diff options
Diffstat (limited to 'spec/frontend/whats_new')
-rw-r--r-- | spec/frontend/whats_new/components/app_spec.js | 57 | ||||
-rw-r--r-- | spec/frontend/whats_new/components/trigger_spec.js | 43 | ||||
-rw-r--r-- | spec/frontend/whats_new/store/actions_spec.js | 17 | ||||
-rw-r--r-- | spec/frontend/whats_new/store/mutations_spec.js | 25 |
4 files changed, 142 insertions, 0 deletions
diff --git a/spec/frontend/whats_new/components/app_spec.js b/spec/frontend/whats_new/components/app_spec.js new file mode 100644 index 00000000000..a349aad9f1c --- /dev/null +++ b/spec/frontend/whats_new/components/app_spec.js @@ -0,0 +1,57 @@ +import { createLocalVue, mount } from '@vue/test-utils'; +import Vuex from 'vuex'; +import { GlDrawer } from '@gitlab/ui'; +import App from '~/whats_new/components/app.vue'; + +const localVue = createLocalVue(); +localVue.use(Vuex); + +describe('App', () => { + let wrapper; + let store; + let actions; + let state; + + beforeEach(() => { + actions = { + closeDrawer: jest.fn(), + }; + + state = { + open: true, + }; + + store = new Vuex.Store({ + actions, + state, + }); + + wrapper = mount(App, { + localVue, + store, + }); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + const getDrawer = () => wrapper.find(GlDrawer); + + it('contains a drawer', () => { + expect(getDrawer().exists()).toBe(true); + }); + + it('dispatches closeDrawer when clicking close', () => { + getDrawer().vm.$emit('close'); + expect(actions.closeDrawer).toHaveBeenCalled(); + }); + + it.each([true, false])('passes open property', async openState => { + wrapper.vm.$store.state.open = openState; + + await wrapper.vm.$nextTick(); + + expect(getDrawer().props('open')).toBe(openState); + }); +}); diff --git a/spec/frontend/whats_new/components/trigger_spec.js b/spec/frontend/whats_new/components/trigger_spec.js new file mode 100644 index 00000000000..7961957e077 --- /dev/null +++ b/spec/frontend/whats_new/components/trigger_spec.js @@ -0,0 +1,43 @@ +import { createLocalVue, mount } from '@vue/test-utils'; +import Vuex from 'vuex'; +import { GlButton } from '@gitlab/ui'; +import Trigger from '~/whats_new/components/trigger.vue'; + +const localVue = createLocalVue(); +localVue.use(Vuex); + +describe('Trigger', () => { + let wrapper; + let store; + let actions; + let state; + + beforeEach(() => { + actions = { + openDrawer: jest.fn(), + }; + + state = { + open: true, + }; + + store = new Vuex.Store({ + actions, + state, + }); + + wrapper = mount(Trigger, { + localVue, + store, + }); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + it('dispatches openDrawer when clicking close', () => { + wrapper.find(GlButton).vm.$emit('click'); + expect(actions.openDrawer).toHaveBeenCalled(); + }); +}); diff --git a/spec/frontend/whats_new/store/actions_spec.js b/spec/frontend/whats_new/store/actions_spec.js new file mode 100644 index 00000000000..d95453c9175 --- /dev/null +++ b/spec/frontend/whats_new/store/actions_spec.js @@ -0,0 +1,17 @@ +import testAction from 'helpers/vuex_action_helper'; +import actions from '~/whats_new/store/actions'; +import * as types from '~/whats_new/store/mutation_types'; + +describe('whats new actions', () => { + describe('openDrawer', () => { + it('should commit openDrawer', () => { + testAction(actions.openDrawer, {}, {}, [{ type: types.OPEN_DRAWER }]); + }); + }); + + describe('closeDrawer', () => { + it('should commit closeDrawer', () => { + testAction(actions.closeDrawer, {}, {}, [{ type: types.CLOSE_DRAWER }]); + }); + }); +}); diff --git a/spec/frontend/whats_new/store/mutations_spec.js b/spec/frontend/whats_new/store/mutations_spec.js new file mode 100644 index 00000000000..3c33364fed3 --- /dev/null +++ b/spec/frontend/whats_new/store/mutations_spec.js @@ -0,0 +1,25 @@ +import mutations from '~/whats_new/store/mutations'; +import createState from '~/whats_new/store/state'; +import * as types from '~/whats_new/store/mutation_types'; + +describe('whats new mutations', () => { + let state; + + beforeEach(() => { + state = createState; + }); + + describe('openDrawer', () => { + it('sets open to true', () => { + mutations[types.OPEN_DRAWER](state); + expect(state.open).toBe(true); + }); + }); + + describe('closeDrawer', () => { + it('sets open to false', () => { + mutations[types.CLOSE_DRAWER](state); + expect(state.open).toBe(false); + }); + }); +}); |