Repository navigation
Expand file tree
/
Copy pathindexSpec.js
More file actions
86 lines (69 loc) · 2.6 KB
/
Copy pathindexSpec.js
File metadata and controls
86 lines (69 loc) · 2.6 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import {hideLoader, handleClickButton, findSiteFromInput} from './index.js'
import {createTestContainer, tearDownTestContainer} from "./specHelper.js";
describe('index.js', () => {
let testContainer;
beforeEach(() => {
testContainer = createTestContainer();
});
afterEach(() => {
tearDownTestContainer();
});
describe('#hideLoader()', () => {
it('finds the loader adds the hide class', () => {
const loader = document.createElement('div');
loader.setAttribute('id', 'loading');
testContainer.appendChild(loader);
hideLoader();
const actual = document.getElementById('loading');
expect(actual.className).toEqual('hide');
});
});
describe('#handleClickButton()', () => {
describe('when site is not found', () => {
it('adds visible class to alert', () => {
const data = [];
const container = document.createElement('div');
container.innerHTML = '<div id="alert"></div>' +
'<input id="site-code-input" type="tel" value="1"/>' +
'<input type="submit" name="submit" id="submit-button"/>';
testContainer.appendChild(container);
jasmine.clock().install();
handleClickButton(new Event('click'), data);
jasmine.clock().tick(50);
const actual = document.getElementById('alert');
expect(actual.className).toEqual('visible');
});
});
describe('when site is found', () => {
it('redirects to the site url', () => {
const data = [
{code: '1', url: 'something'}
];
const container = document.createElement('div');
container.innerHTML = '<div id="alert"></div>' +
'<input id="site-code-input" type="tel" value="1"/>' +
'<input type="submit" name="submit" id="submit-button"/>';
testContainer.appendChild(container);
const redirectSpy = jasmine.createSpy();
handleClickButton(new Event('click'), data, redirectSpy);
expect(redirectSpy).toHaveBeenCalled();
});
});
});
describe('#findSiteFromInput()', () => {
it('returns site when site code from input exists in lookup data', () => {
const data = [
{code: '1234', url: 'something.com'}
];
const input = {value: '1234'};
expect(findSiteFromInput(data, input)).toEqual(data[0]);
});
it('returns undefined when site code from input does not exist in lookup data', () => {
const data = [
{code: '1234', url: 'something.com'}
];
const input = {value: '1111'};
expect(findSiteFromInput(data, input)).toEqual(undefined);
});
});
});