2021-04-12 17:11:12 -04:00
|
|
|
import { GlDrawer, GlInfiniteScroll } from '@gitlab/ui';
|
2022-01-21 13:12:45 -05:00
|
|
|
import { mount } from '@vue/test-utils';
|
2022-01-25 07:14:14 -05:00
|
|
|
import Vue, { nextTick } from 'vue';
|
2020-08-13 17:10:04 -04:00
|
|
|
import Vuex from 'vuex';
|
2020-09-30 05:10:11 -04:00
|
|
|
import { mockTracking, unmockTracking, triggerEvent } from 'helpers/tracking_helper';
|
2020-11-02 04:08:35 -05:00
|
|
|
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
|
2020-08-13 17:10:04 -04:00
|
|
|
import App from '~/whats_new/components/app.vue';
|
2020-11-02 04:08:35 -05:00
|
|
|
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-08-13 17:10:04 -04:00
|
|
|
|
2022-01-21 13:12:45 -05:00
|
|
|
Vue.use(Vuex);
|
2020-08-13 17:10:04 -04:00
|
|
|
|
|
|
|
describe('App', () => {
|
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
let actions;
|
|
|
|
let state;
|
2020-09-30 05:10:11 -04:00
|
|
|
let trackingSpy;
|
2020-12-10 10:10:12 -05:00
|
|
|
|
|
|
|
const buildProps = () => ({
|
2021-04-12 17:11:12 -04:00
|
|
|
versionDigest: 'version-digest',
|
2020-12-10 10:10:12 -05:00
|
|
|
});
|
2020-08-13 17:10:04 -04:00
|
|
|
|
2020-08-26 02:10:34 -04:00
|
|
|
const buildWrapper = () => {
|
2020-08-13 17:10:04 -04:00
|
|
|
actions = {
|
2020-09-08 17:08:53 -04:00
|
|
|
openDrawer: jest.fn(),
|
2020-08-13 17:10:04 -04:00
|
|
|
closeDrawer: jest.fn(),
|
2020-10-14 14:08:47 -04:00
|
|
|
fetchItems: jest.fn(),
|
2020-11-02 04:08:35 -05:00
|
|
|
setDrawerBodyHeight: jest.fn(),
|
2020-08-13 17:10:04 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
open: true,
|
2020-11-02 04:08:35 -05:00
|
|
|
features: [],
|
|
|
|
drawerBodyHeight: null,
|
2020-08-13 17:10:04 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
store = new Vuex.Store({
|
|
|
|
actions,
|
|
|
|
state,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper = mount(App, {
|
|
|
|
store,
|
2020-12-10 10:10:12 -05:00
|
|
|
propsData: buildProps(),
|
2020-11-02 04:08:35 -05:00
|
|
|
directives: {
|
|
|
|
GlResizeObserver: createMockDirective(),
|
|
|
|
},
|
2020-08-13 17:10:04 -04:00
|
|
|
});
|
2020-08-26 02:10:34 -04:00
|
|
|
};
|
|
|
|
|
2020-11-02 04:08:35 -05:00
|
|
|
const findInfiniteScroll = () => wrapper.find(GlInfiniteScroll);
|
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
const setup = async () => {
|
2020-09-30 05:10:11 -04:00
|
|
|
document.body.dataset.page = 'test-page';
|
|
|
|
document.body.dataset.namespaceId = 'namespace-840';
|
|
|
|
|
|
|
|
trackingSpy = mockTracking('_category_', null, jest.spyOn);
|
2020-08-26 02:10:34 -04:00
|
|
|
buildWrapper();
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
wrapper.vm.$store.state.features = [
|
|
|
|
{ title: 'Whats New Drawer', url: 'www.url.com', release: 3.11 },
|
|
|
|
];
|
2020-11-02 04:08:35 -05:00
|
|
|
wrapper.vm.$store.state.drawerBodyHeight = MOCK_DRAWER_BODY_HEIGHT;
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
2020-12-10 10:10:12 -05:00
|
|
|
};
|
2020-08-13 17:10:04 -04:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
2020-09-30 05:10:11 -04:00
|
|
|
unmockTracking();
|
2020-08-13 17:10:04 -04:00
|
|
|
});
|
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
describe('gitlab.com', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setup();
|
|
|
|
});
|
2020-09-30 05:10:11 -04:00
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
const getDrawer = () => wrapper.find(GlDrawer);
|
2021-05-17 17:10:42 -04:00
|
|
|
const getBackdrop = () => wrapper.find('.whats-new-modal-backdrop');
|
2020-12-04 04:09:36 -05:00
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
it('contains a drawer', () => {
|
|
|
|
expect(getDrawer().exists()).toBe(true);
|
2020-12-04 04:09:36 -05:00
|
|
|
});
|
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
it('dispatches openDrawer and tracking calls when mounted', () => {
|
2021-04-12 17:11:12 -04:00
|
|
|
expect(actions.openDrawer).toHaveBeenCalledWith(expect.any(Object), 'version-digest');
|
2020-12-10 10:10:12 -05:00
|
|
|
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_whats_new_drawer', {
|
|
|
|
label: 'namespace_id',
|
|
|
|
value: 'namespace-840',
|
|
|
|
});
|
|
|
|
});
|
2020-12-04 04:09:36 -05:00
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
it('dispatches closeDrawer when clicking close', () => {
|
|
|
|
getDrawer().vm.$emit('close');
|
|
|
|
expect(actions.closeDrawer).toHaveBeenCalled();
|
|
|
|
});
|
2020-11-02 04:08:35 -05:00
|
|
|
|
2021-05-17 17:10:42 -04:00
|
|
|
it('dispatches closeDrawer when clicking the backdrop', () => {
|
|
|
|
getBackdrop().trigger('click');
|
|
|
|
expect(actions.closeDrawer).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it.each([true, false])('passes open property', async (openState) => {
|
2020-12-10 10:10:12 -05:00
|
|
|
wrapper.vm.$store.state.open = openState;
|
2020-11-02 04:08:35 -05:00
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
2020-12-04 04:09:36 -05:00
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
expect(getDrawer().props('open')).toBe(openState);
|
|
|
|
});
|
2020-12-04 04:09:36 -05:00
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
it('renders features when provided via ajax', () => {
|
|
|
|
expect(actions.fetchItems).toHaveBeenCalled();
|
|
|
|
expect(wrapper.find('[data-test-id="feature-title"]').text()).toBe('Whats New Drawer');
|
|
|
|
});
|
2020-12-04 04:09:36 -05:00
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
it('send an event when feature item is clicked', () => {
|
|
|
|
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
|
2020-12-04 04:09:36 -05:00
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
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');
|
2020-12-04 04:09:36 -05:00
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
actions.fetchItems.mockClear();
|
|
|
|
});
|
2020-12-04 04:09:36 -05:00
|
|
|
|
2020-12-10 10:10:12 -05:00
|
|
|
it('when nextPage exists it calls fetchItems', () => {
|
|
|
|
wrapper.vm.$store.state.pageInfo = { nextPage: 840 };
|
|
|
|
emitBottomReached();
|
|
|
|
|
2021-05-08 02:10:29 -04:00
|
|
|
expect(actions.fetchItems).toHaveBeenCalledWith(expect.anything(), {
|
|
|
|
page: 840,
|
|
|
|
versionDigest: 'version-digest',
|
|
|
|
});
|
2020-12-10 10:10:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
|
|
|
);
|
2020-11-02 04:08:35 -05:00
|
|
|
});
|
|
|
|
});
|
2020-08-13 17:10:04 -04:00
|
|
|
});
|