2020-10-24 23:57:45 +05:30
|
|
|
import { createLocalVue, mount } from '@vue/test-utils';
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
import { GlDrawer } from '@gitlab/ui';
|
2021-01-03 14:25:43 +05:30
|
|
|
import { mockTracking, unmockTracking, triggerEvent } from 'helpers/tracking_helper';
|
2020-10-24 23:57:45 +05:30
|
|
|
import App from '~/whats_new/components/app.vue';
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
describe('App', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
const propsData = { storageKey: 'storage-key' };
|
2020-10-24 23:57:45 +05:30
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
let actions;
|
|
|
|
let state;
|
2021-01-03 14:25:43 +05:30
|
|
|
let trackingSpy;
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
const buildWrapper = () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
actions = {
|
2020-11-24 15:15:51 +05:30
|
|
|
openDrawer: jest.fn(),
|
2020-10-24 23:57:45 +05:30
|
|
|
closeDrawer: jest.fn(),
|
2021-01-03 14:25:43 +05:30
|
|
|
fetchItems: jest.fn(),
|
2020-10-24 23:57:45 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
open: true,
|
2021-01-03 14:25:43 +05:30
|
|
|
features: null,
|
2020-10-24 23:57:45 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
store = new Vuex.Store({
|
|
|
|
actions,
|
|
|
|
state,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper = mount(App, {
|
|
|
|
localVue,
|
|
|
|
store,
|
2020-11-24 15:15:51 +05:30
|
|
|
propsData,
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
};
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
beforeEach(async () => {
|
|
|
|
document.body.dataset.page = 'test-page';
|
|
|
|
document.body.dataset.namespaceId = 'namespace-840';
|
|
|
|
|
|
|
|
trackingSpy = mockTracking('_category_', null, jest.spyOn);
|
2020-11-24 15:15:51 +05:30
|
|
|
buildWrapper();
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
wrapper.vm.$store.state.features = [{ title: 'Whats New Drawer', url: 'www.url.com' }];
|
|
|
|
await wrapper.vm.$nextTick();
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
2021-01-03 14:25:43 +05:30
|
|
|
unmockTracking();
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
const getDrawer = () => wrapper.find(GlDrawer);
|
|
|
|
|
|
|
|
it('contains a drawer', () => {
|
|
|
|
expect(getDrawer().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it('dispatches openDrawer when mounted', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(actions.openDrawer).toHaveBeenCalledWith(expect.any(Object), 'storage-key');
|
|
|
|
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_whats_new_drawer', {
|
|
|
|
label: 'namespace_id',
|
|
|
|
value: 'namespace-840',
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
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);
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('renders features when provided via ajax', () => {
|
|
|
|
expect(actions.fetchItems).toHaveBeenCalled();
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find('h5').text()).toBe('Whats New Drawer');
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it('send an event when feature item is clicked', () => {
|
|
|
|
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
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',
|
|
|
|
},
|
|
|
|
]);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|