1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
import expect from 'expect';
import fetchMock from 'fetch-mock';
import browser from 'helpers/browser';
import Util from 'src/common/util';
describe('Utils', () => {
describe('.hasQueryParameter', () => {
global.window = {
location: {
search: '?auth-error&lng=pt-BR'
}
};
it('checks if param included in query parameters', () => {
expect(Util.hasQueryParameter('auth-error')).toBe(true);
});
it('checks if param not included in query parameters', () => {
expect(Util.hasQueryParameter('error')).toBe(false);
});
});
describe('submitForm', () => {
const event = {};
beforeEach(() => {
event.preventDefault = expect.createSpy();
expect.spyOn(browser, 'getCookie').andReturn('abc123');
fetchMock.post('/some-url', 200);
Util.submitForm(event, '/some-url', { userCode: '123' });
});
it('sends csrftoken as content', () => {
expect(fetchMock.lastOptions('/some-url').body).toContain('"csrftoken":["abc123"]');
});
it('sends body as content', () => {
expect(fetchMock.lastOptions('/some-url').body).toContain('"userCode":"123"');
});
it('sends content-type header', () => {
expect(fetchMock.lastOptions('/some-url').headers['Content-Type']).toEqual('application/json');
});
it('sends same origin headers', () => {
expect(fetchMock.lastOptions('/some-url').credentials).toEqual('same-origin');
});
it('prevents default call to refresh page', () => {
expect(event.preventDefault).toHaveBeenCalled();
});
});
});
|