From 48aff82709769b098321c738f3444b9bdaa694c6 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 21 Oct 2020 07:08:36 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-5-stable-ee --- spec/frontend/whats_new/components/app_spec.js | 42 ++++++++++++++++++++----- spec/frontend/whats_new/store/actions_spec.js | 33 ++++++++++++++++++- spec/frontend/whats_new/store/mutations_spec.js | 7 +++++ 3 files changed, 73 insertions(+), 9 deletions(-) (limited to 'spec/frontend/whats_new') diff --git a/spec/frontend/whats_new/components/app_spec.js b/spec/frontend/whats_new/components/app_spec.js index 59d05f68fdd..77c2ae19d1f 100644 --- a/spec/frontend/whats_new/components/app_spec.js +++ b/spec/frontend/whats_new/components/app_spec.js @@ -1,26 +1,30 @@ import { createLocalVue, mount } from '@vue/test-utils'; import Vuex from 'vuex'; import { GlDrawer } from '@gitlab/ui'; +import { mockTracking, unmockTracking, triggerEvent } from 'helpers/tracking_helper'; import App from '~/whats_new/components/app.vue'; const localVue = createLocalVue(); localVue.use(Vuex); describe('App', () => { + const propsData = { storageKey: 'storage-key' }; let wrapper; let store; let actions; let state; - let propsData = { features: '[ {"title":"Whats New Drawer"} ]' }; + let trackingSpy; const buildWrapper = () => { actions = { openDrawer: jest.fn(), closeDrawer: jest.fn(), + fetchItems: jest.fn(), }; state = { open: true, + features: null, }; store = new Vuex.Store({ @@ -35,12 +39,20 @@ describe('App', () => { }); }; - beforeEach(() => { + beforeEach(async () => { + document.body.dataset.page = 'test-page'; + document.body.dataset.namespaceId = 'namespace-840'; + + trackingSpy = mockTracking('_category_', null, jest.spyOn); buildWrapper(); + + wrapper.vm.$store.state.features = [{ title: 'Whats New Drawer', url: 'www.url.com' }]; + await wrapper.vm.$nextTick(); }); afterEach(() => { wrapper.destroy(); + unmockTracking(); }); const getDrawer = () => wrapper.find(GlDrawer); @@ -50,7 +62,11 @@ describe('App', () => { }); it('dispatches openDrawer when mounted', () => { - expect(actions.openDrawer).toHaveBeenCalled(); + expect(actions.openDrawer).toHaveBeenCalledWith(expect.any(Object), 'storage-key'); + expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_whats_new_drawer', { + label: 'namespace_id', + value: 'namespace-840', + }); }); it('dispatches closeDrawer when clicking close', () => { @@ -66,14 +82,24 @@ describe('App', () => { expect(getDrawer().props('open')).toBe(openState); }); - it('renders features when provided as props', () => { + it('renders features when provided via ajax', () => { + expect(actions.fetchItems).toHaveBeenCalled(); expect(wrapper.find('h5').text()).toBe('Whats New Drawer'); }); - it('handles bad json argument gracefully', () => { - propsData = { features: 'this is not json' }; - buildWrapper(); + it('send an event when feature item is clicked', () => { + trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn); - expect(getDrawer().exists()).toBe(true); + const link = wrapper.find('[data-testid="whats-new-title-link"]'); + triggerEvent(link.element); + + expect(trackingSpy.mock.calls[1]).toMatchObject([ + '_category_', + 'click_whats_new_item', + { + label: 'Whats New Drawer', + property: 'www.url.com', + }, + ]); }); }); diff --git a/spec/frontend/whats_new/store/actions_spec.js b/spec/frontend/whats_new/store/actions_spec.js index d95453c9175..95ab667d611 100644 --- a/spec/frontend/whats_new/store/actions_spec.js +++ b/spec/frontend/whats_new/store/actions_spec.js @@ -1,11 +1,19 @@ import testAction from 'helpers/vuex_action_helper'; +import { useLocalStorageSpy } from 'helpers/local_storage_helper'; +import MockAdapter from 'axios-mock-adapter'; +import waitForPromises from 'helpers/wait_for_promises'; import actions from '~/whats_new/store/actions'; import * as types from '~/whats_new/store/mutation_types'; +import axios from '~/lib/utils/axios_utils'; describe('whats new actions', () => { describe('openDrawer', () => { + useLocalStorageSpy(); + it('should commit openDrawer', () => { - testAction(actions.openDrawer, {}, {}, [{ type: types.OPEN_DRAWER }]); + testAction(actions.openDrawer, 'storage-key', {}, [{ type: types.OPEN_DRAWER }]); + + expect(window.localStorage.setItem).toHaveBeenCalledWith('storage-key', 'false'); }); }); @@ -14,4 +22,27 @@ describe('whats new actions', () => { testAction(actions.closeDrawer, {}, {}, [{ type: types.CLOSE_DRAWER }]); }); }); + + describe('fetchItems', () => { + let axiosMock; + + beforeEach(async () => { + axiosMock = new MockAdapter(axios); + axiosMock + .onGet('/-/whats_new') + .replyOnce(200, [{ title: 'Whats New Drawer', url: 'www.url.com' }]); + + await waitForPromises(); + }); + + afterEach(() => { + axiosMock.restore(); + }); + + it('should commit setFeatures', () => { + testAction(actions.fetchItems, {}, {}, [ + { type: types.SET_FEATURES, payload: [{ title: 'Whats New Drawer', url: 'www.url.com' }] }, + ]); + }); + }); }); diff --git a/spec/frontend/whats_new/store/mutations_spec.js b/spec/frontend/whats_new/store/mutations_spec.js index 3c33364fed3..feaa1dd2a3b 100644 --- a/spec/frontend/whats_new/store/mutations_spec.js +++ b/spec/frontend/whats_new/store/mutations_spec.js @@ -22,4 +22,11 @@ describe('whats new mutations', () => { expect(state.open).toBe(false); }); }); + + describe('setFeatures', () => { + it('sets features to data', () => { + mutations[types.SET_FEATURES](state, 'bells and whistles'); + expect(state.features).toBe('bells and whistles'); + }); + }); }); -- cgit v1.2.3