blob: 0e3a2dfdfd4110a66042c2c60b547932fe47edc1 (
plain)
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
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
import initNetworkOutbound from '~/admin/application_settings/network_outbound';
describe('initNetworkOutbound', () => {
const findAllowCheckboxes = () => document.querySelectorAll('.js-allow-local-requests');
const findDenyCheckbox = () => document.querySelector('.js-deny-all-requests');
const findWarningBanner = () => document.querySelector('.js-deny-all-requests-warning');
const clickDenyCheckbox = () => {
findDenyCheckbox().click();
};
const createFixture = (denyAll = false) => {
setHTMLFixture(`
<input class="js-deny-all-requests" type="checkbox" name="application_setting[deny_all_requests]" ${
denyAll ? 'checked="checked"' : ''
}/>
<div class="js-deny-all-requests-warning ${denyAll ? '' : 'gl-display-none'}"></div>
<input class="js-allow-local-requests" type="checkbox" name="application_setting[allow_local_requests_from_web_hooks_and_services]" />
<input class="js-allow-local-requests" type="checkbox" name="application_setting[allow_local_requests_from_system_hooks]" />
`);
};
afterEach(() => {
resetHTMLFixture();
});
describe('when the checkbox is not checked', () => {
beforeEach(() => {
createFixture();
initNetworkOutbound();
});
it('shows banner and disables allow checkboxes on change', () => {
expect(findDenyCheckbox().checked).toBe(false);
expect(findWarningBanner().classList).toContain('gl-display-none');
clickDenyCheckbox();
expect(findDenyCheckbox().checked).toBe(true);
expect(findWarningBanner().classList).not.toContain('gl-display-none');
const allowCheckboxes = findAllowCheckboxes();
allowCheckboxes.forEach((checkbox) => {
expect(checkbox.checked).toBe(false);
expect(checkbox.disabled).toBe(true);
});
});
});
describe('when the checkbox is checked', () => {
beforeEach(() => {
createFixture(true);
initNetworkOutbound();
});
it('hides banner and enables allow checkboxes on change', () => {
expect(findDenyCheckbox().checked).toBe(true);
expect(findWarningBanner().classList).not.toContain('gl-display-none');
clickDenyCheckbox();
expect(findDenyCheckbox().checked).toBe(false);
expect(findWarningBanner().classList).toContain('gl-display-none');
const allowCheckboxes = findAllowCheckboxes();
allowCheckboxes.forEach((checkbox) => {
expect(checkbox.disabled).toBe(false);
});
});
});
});
|