2021-04-29 21:17:54 +05:30
|
|
|
import { GlDrawer, GlInfiniteScroll } from '@gitlab/ui';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import Vue, { nextTick } from 'vue';
|
2020-10-24 23:57:45 +05:30
|
|
|
import Vuex from 'vuex';
|
2021-01-03 14:25:43 +05:30
|
|
|
import { mockTracking, unmockTracking, triggerEvent } from 'helpers/tracking_helper';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
|
2020-10-24 23:57:45 +05:30
|
|
|
import App from '~/whats_new/components/app.vue';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { getDrawerBodyHeight } from '~/whats_new/utils/get_drawer_body_height';
|
|
|
|
|
|
|
|
const MOCK_DRAWER_BODY_HEIGHT = 42;
|
|
|
|
|
|
|
|
jest.mock('~/whats_new/utils/get_drawer_body_height', () => ({
|
|
|
|
getDrawerBodyHeight: jest.fn().mockImplementation(() => MOCK_DRAWER_BODY_HEIGHT),
|
|
|
|
}));
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
Vue.use(Vuex);
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
describe('App', () => {
|
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
let actions;
|
|
|
|
let state;
|
2021-01-03 14:25:43 +05:30
|
|
|
let trackingSpy;
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
const buildProps = () => ({
|
2021-04-29 21:17:54 +05:30
|
|
|
versionDigest: 'version-digest',
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
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(),
|
2021-01-29 00:20:46 +05:30
|
|
|
setDrawerBodyHeight: jest.fn(),
|
2020-10-24 23:57:45 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
open: true,
|
2021-01-29 00:20:46 +05:30
|
|
|
features: [],
|
|
|
|
drawerBodyHeight: null,
|
2020-10-24 23:57:45 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
store = new Vuex.Store({
|
|
|
|
actions,
|
|
|
|
state,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper = mount(App, {
|
|
|
|
store,
|
2021-02-22 17:27:13 +05:30
|
|
|
propsData: buildProps(),
|
2021-01-29 00:20:46 +05:30
|
|
|
directives: {
|
|
|
|
GlResizeObserver: createMockDirective(),
|
|
|
|
},
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
};
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
const findInfiniteScroll = () => wrapper.find(GlInfiniteScroll);
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
const setup = async () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
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
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
wrapper.vm.$store.state.features = [
|
2022-08-27 11:52:29 +05:30
|
|
|
{ name: 'Whats New Drawer', documentation_link: 'www.url.com', release: 3.11 },
|
2021-02-22 17:27:13 +05:30
|
|
|
];
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper.vm.$store.state.drawerBodyHeight = MOCK_DRAWER_BODY_HEIGHT;
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2021-02-22 17:27:13 +05:30
|
|
|
};
|
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
|
|
|
});
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
describe('gitlab.com', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setup();
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
const getDrawer = () => wrapper.find(GlDrawer);
|
2021-06-08 01:23:25 +05:30
|
|
|
const getBackdrop = () => wrapper.find('.whats-new-modal-backdrop');
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('contains a drawer', () => {
|
|
|
|
expect(getDrawer().exists()).toBe(true);
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('dispatches openDrawer and tracking calls when mounted', () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(actions.openDrawer).toHaveBeenCalledWith(expect.any(Object), 'version-digest');
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_whats_new_drawer', {
|
|
|
|
label: 'namespace_id',
|
|
|
|
value: 'namespace-840',
|
|
|
|
});
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('dispatches closeDrawer when clicking close', () => {
|
|
|
|
getDrawer().vm.$emit('close');
|
|
|
|
expect(actions.closeDrawer).toHaveBeenCalled();
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it('dispatches closeDrawer when clicking the backdrop', () => {
|
|
|
|
getBackdrop().trigger('click');
|
|
|
|
expect(actions.closeDrawer).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it.each([true, false])('passes open property', async (openState) => {
|
2021-02-22 17:27:13 +05:30
|
|
|
wrapper.vm.$store.state.open = openState;
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(getDrawer().props('open')).toBe(openState);
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('renders features when provided via ajax', () => {
|
|
|
|
expect(actions.fetchItems).toHaveBeenCalled();
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.find('[data-test-id="feature-name"]').text()).toBe('Whats New Drawer');
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('send an event when feature item is clicked', () => {
|
|
|
|
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
const link = wrapper.find('.whats-new-item-title-link');
|
|
|
|
triggerEvent(link.element);
|
|
|
|
|
|
|
|
expect(trackingSpy.mock.calls[1]).toMatchObject([
|
|
|
|
'_category_',
|
|
|
|
'click_whats_new_item',
|
|
|
|
{
|
|
|
|
label: 'Whats New Drawer',
|
|
|
|
property: 'www.url.com',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders infinite scroll', () => {
|
|
|
|
const scroll = findInfiniteScroll();
|
|
|
|
|
|
|
|
expect(scroll.props()).toMatchObject({
|
|
|
|
fetchedItems: wrapper.vm.$store.state.features.length,
|
|
|
|
maxListHeight: MOCK_DRAWER_BODY_HEIGHT,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('bottomReached', () => {
|
|
|
|
const emitBottomReached = () => findInfiniteScroll().vm.$emit('bottomReached');
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
actions.fetchItems.mockClear();
|
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
it('when nextPage exists it calls fetchItems', () => {
|
|
|
|
wrapper.vm.$store.state.pageInfo = { nextPage: 840 };
|
|
|
|
emitBottomReached();
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(actions.fetchItems).toHaveBeenCalledWith(expect.anything(), {
|
|
|
|
page: 840,
|
|
|
|
versionDigest: 'version-digest',
|
|
|
|
});
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('when nextPage does not exist it does not call fetchItems', () => {
|
|
|
|
wrapper.vm.$store.state.pageInfo = { nextPage: null };
|
|
|
|
emitBottomReached();
|
|
|
|
|
|
|
|
expect(actions.fetchItems).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls getDrawerBodyHeight and setDrawerBodyHeight when resize directive is triggered', () => {
|
|
|
|
const { value } = getBinding(getDrawer().element, 'gl-resize-observer');
|
|
|
|
|
|
|
|
value();
|
|
|
|
|
|
|
|
expect(getDrawerBodyHeight).toHaveBeenCalledWith(wrapper.find(GlDrawer).element);
|
|
|
|
|
|
|
|
expect(actions.setDrawerBodyHeight).toHaveBeenCalledWith(
|
|
|
|
expect.any(Object),
|
|
|
|
MOCK_DRAWER_BODY_HEIGHT,
|
|
|
|
);
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|