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:
Diffstat (limited to 'spec/frontend/behaviors/toasts_spec.js')
-rw-r--r--spec/frontend/behaviors/toasts_spec.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/frontend/behaviors/toasts_spec.js b/spec/frontend/behaviors/toasts_spec.js
new file mode 100644
index 00000000000..bad04758ea1
--- /dev/null
+++ b/spec/frontend/behaviors/toasts_spec.js
@@ -0,0 +1,59 @@
+import { initToastMessages } from '~/behaviors/toasts';
+import { setHTMLFixture } from 'helpers/fixtures';
+import showToast from '~/vue_shared/plugins/global_toast';
+
+jest.mock('~/vue_shared/plugins/global_toast');
+
+describe('initToastMessages', () => {
+ describe('when there are no messages', () => {
+ beforeEach(() => {
+ setHTMLFixture('<div></div>');
+
+ initToastMessages();
+ });
+
+ it('does not display any toasts', () => {
+ expect(showToast).not.toHaveBeenCalled();
+ });
+ });
+
+ describe('when there is a message', () => {
+ const expectedMessage = 'toast with jam is great';
+
+ beforeEach(() => {
+ setHTMLFixture(
+ `<div>
+ <div class="js-toast-message" data-message="${expectedMessage}"></div>
+ </div>`,
+ );
+
+ initToastMessages();
+ });
+
+ it('displays the message', () => {
+ expect(showToast).toHaveBeenCalledTimes(1);
+ expect(showToast).toHaveBeenCalledWith(expectedMessage);
+ });
+ });
+
+ describe('when there are multiple messages', () => {
+ beforeEach(() => {
+ setHTMLFixture(
+ `<div>
+ <div class="js-toast-message" data-message="foo"></div>
+ <div class="js-toast-message" data-message="bar"></div>
+ <div class="js-toast-message" data-message="baz"></div>
+ </div>`,
+ );
+
+ initToastMessages();
+ });
+
+ it('displays the messages', () => {
+ expect(showToast).toHaveBeenCalledTimes(3);
+ expect(showToast).toHaveBeenCalledWith('foo');
+ expect(showToast).toHaveBeenCalledWith('bar');
+ expect(showToast).toHaveBeenCalledWith('baz');
+ });
+ });
+});