diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-30 18:08:57 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-30 18:08:57 +0000 |
commit | d8121cb00b8bbd281d7362902590b110639bdeba (patch) | |
tree | 0a0f71b247b232773a46732d9f74aa3cfed0ef1a /spec/frontend/vue_alerts_spec.js | |
parent | 536aa3a1f4b96abc4ca34489bf2cbe503afcded7 (diff) | |
download | gitlab-ce-d8121cb00b8bbd281d7362902590b110639bdeba.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_alerts_spec.js')
-rw-r--r-- | spec/frontend/vue_alerts_spec.js | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/spec/frontend/vue_alerts_spec.js b/spec/frontend/vue_alerts_spec.js new file mode 100644 index 00000000000..b2ee6f895a8 --- /dev/null +++ b/spec/frontend/vue_alerts_spec.js @@ -0,0 +1,87 @@ +import Vue from 'vue'; +import initVueAlerts from '~/vue_alerts'; +import { setHTMLFixture } from 'helpers/fixtures'; +import { TEST_HOST } from 'helpers/test_constants'; + +describe('VueAlerts', () => { + const alerts = [ + { + title: 'Lorem', + html: 'Lorem <strong>Ipsum</strong>', + dismissible: true, + primaryButtonText: 'Okay!', + primaryButtonLink: `${TEST_HOST}/okay`, + variant: 'tip', + }, + { + title: 'Hello', + html: 'Hello <strong>World</strong>', + dismissible: false, + primaryButtonText: 'No!', + primaryButtonLink: `${TEST_HOST}/no`, + variant: 'info', + }, + ]; + + beforeEach(() => { + setHTMLFixture( + alerts + .map( + x => ` + <div class="js-vue-alert" + data-dismissible="${x.dismissible}" + data-title="${x.title}" + data-primary-button-text="${x.primaryButtonText}" + data-primary-button-link="${x.primaryButtonLink}" + data-variant="${x.variant}">${x.html}</div> + `, + ) + .join('\n'), + ); + }); + + const findJsHooks = () => document.querySelectorAll('.js-vue-alert'); + const findAlerts = () => document.querySelectorAll('.gl-alert'); + const findAlertDismiss = alert => alert.querySelector('.gl-alert-dismiss'); + + const serializeAlert = alert => ({ + title: alert.querySelector('.gl-alert-title').textContent.trim(), + html: alert.querySelector('.gl-alert-body div').innerHTML, + dismissible: Boolean(alert.querySelector('.gl-alert-dismiss')), + primaryButtonText: alert.querySelector('.gl-alert-action').textContent.trim(), + primaryButtonLink: alert.querySelector('.gl-alert-action').href, + variant: [...alert.classList].find(x => x.match('gl-alert-')).replace('gl-alert-', ''), + }); + + it('starts with only JsHooks', () => { + expect(findJsHooks().length).toEqual(alerts.length); + expect(findAlerts().length).toEqual(0); + }); + + describe('when mounted', () => { + beforeEach(() => { + initVueAlerts(); + }); + + it('replaces JsHook with GlAlert', () => { + expect(findJsHooks().length).toEqual(0); + expect(findAlerts().length).toEqual(alerts.length); + }); + + it('passes along props to gl-alert', () => { + expect([...findAlerts()].map(serializeAlert)).toEqual(alerts); + }); + + describe('when dismissed', () => { + beforeEach(() => { + findAlertDismiss(findAlerts()[0]).click(); + + return Vue.nextTick(); + }); + + it('hides the alert', () => { + expect(findAlerts().length).toEqual(alerts.length - 1); + }); + }); + }); +}); |