From 250660ca2d88556c5305bc855744c6e22cb329f2 Mon Sep 17 00:00:00 2001 From: Fernando Arias Date: Tue, 10 Sep 2019 21:20:20 +0000 Subject: Add global toast module **Why?** https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/15015#note_210891978 --- .../javascripts/vue_shared/plugins/global_toast.js | 8 ++++++++ .../vue_shared/plugins/global_toast_spec.js | 24 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 app/assets/javascripts/vue_shared/plugins/global_toast.js create mode 100644 spec/frontend/vue_shared/plugins/global_toast_spec.js diff --git a/app/assets/javascripts/vue_shared/plugins/global_toast.js b/app/assets/javascripts/vue_shared/plugins/global_toast.js new file mode 100644 index 00000000000..c0de1cdc615 --- /dev/null +++ b/app/assets/javascripts/vue_shared/plugins/global_toast.js @@ -0,0 +1,8 @@ +import Vue from 'vue'; +import { GlToast } from '@gitlab/ui'; + +Vue.use(GlToast); + +export default function showGlobalToast(...args) { + return Vue.toasted.show(...args); +} diff --git a/spec/frontend/vue_shared/plugins/global_toast_spec.js b/spec/frontend/vue_shared/plugins/global_toast_spec.js new file mode 100644 index 00000000000..551abe3cb41 --- /dev/null +++ b/spec/frontend/vue_shared/plugins/global_toast_spec.js @@ -0,0 +1,24 @@ +import toast from '~/vue_shared/plugins/global_toast'; +import Vue from 'vue'; + +describe('Global toast', () => { + let spyFunc; + + beforeEach(() => { + spyFunc = jest.spyOn(Vue.toasted, 'show').mockImplementation(() => {}); + }); + + afterEach(() => { + spyFunc.mockRestore(); + }); + + it('should pass all args to Vue toasted', () => { + const arg1 = 'TestMessage'; + const arg2 = { className: 'foo' }; + + toast(arg1, arg2); + + expect(Vue.toasted.show).toHaveBeenCalledTimes(1); + expect(Vue.toasted.show).toHaveBeenCalledWith(arg1, arg2); + }); +}); -- cgit v1.2.1