From 85dc423f7090da0a52c73eb66faf22ddb20efff9 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Sat, 19 Sep 2020 01:45:44 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-4-stable-ee --- spec/frontend/alert_handler_spec.js | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 spec/frontend/alert_handler_spec.js (limited to 'spec/frontend/alert_handler_spec.js') diff --git a/spec/frontend/alert_handler_spec.js b/spec/frontend/alert_handler_spec.js new file mode 100644 index 00000000000..ba2f4f24aa5 --- /dev/null +++ b/spec/frontend/alert_handler_spec.js @@ -0,0 +1,46 @@ +import { setHTMLFixture } from 'helpers/fixtures'; +import initAlertHandler from '~/alert_handler'; + +describe('Alert Handler', () => { + const ALERT_SELECTOR = 'gl-alert'; + const CLOSE_SELECTOR = 'gl-alert-dismiss'; + const ALERT_HTML = `
`; + + const findFirstAlert = () => document.querySelector(`.${ALERT_SELECTOR}`); + const findAllAlerts = () => document.querySelectorAll(`.${ALERT_SELECTOR}`); + const findFirstCloseButton = () => document.querySelector(`.${CLOSE_SELECTOR}`); + + describe('initAlertHandler', () => { + describe('with one alert', () => { + beforeEach(() => { + setHTMLFixture(ALERT_HTML); + initAlertHandler(); + }); + + it('should render the alert', () => { + expect(findFirstAlert()).toExist(); + }); + + it('should dismiss the alert on click', () => { + findFirstCloseButton().click(); + expect(findFirstAlert()).not.toExist(); + }); + }); + + describe('with two alerts', () => { + beforeEach(() => { + setHTMLFixture(ALERT_HTML + ALERT_HTML); + initAlertHandler(); + }); + + it('should render two alerts', () => { + expect(findAllAlerts()).toHaveLength(2); + }); + + it('should dismiss only one alert on click', () => { + findFirstCloseButton().click(); + expect(findAllAlerts()).toHaveLength(1); + }); + }); + }); +}); -- cgit v1.2.1