diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-03 21:10:18 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-03 21:10:18 +0300 |
commit | 3413ab248287b19b1d2cd1f78d957096546e8c37 (patch) | |
tree | b59d4bddbee10eceebbe7a085c3d660307d03ca5 /spec/frontend | |
parent | dbe0e5676267eb142dd8d81e4c881c997cb96962 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/admin/application_settings/network_outbound_spec.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/frontend/admin/application_settings/network_outbound_spec.js b/spec/frontend/admin/application_settings/network_outbound_spec.js new file mode 100644 index 00000000000..0e3a2dfdfd4 --- /dev/null +++ b/spec/frontend/admin/application_settings/network_outbound_spec.js @@ -0,0 +1,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); + }); + }); + }); +}); |