Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-08 12:08:31 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-08 12:08:31 +0300
commit49a897eff9081b39665a4827b4f685e142569b99 (patch)
tree302e8c9fad985adb1302feda35cca079302cd542 /spec/frontend/alert_handler_spec.js
parenta69bb17d1e46f2816c3406d24c4dcdcb6d479935 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/alert_handler_spec.js')
-rw-r--r--spec/frontend/alert_handler_spec.js46
1 files changed, 46 insertions, 0 deletions
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 = `<div class="${ALERT_SELECTOR}"><button class="${CLOSE_SELECTOR}">Dismiss</button></div>`;
+
+ 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);
+ });
+ });
+ });
+});