2020-07-09 20:09:13 -04:00
|
|
|
import { escape } from 'lodash';
|
2022-05-13 08:08:49 -04:00
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2020-06-11 11:08:36 -04:00
|
|
|
import Wikis from '~/pages/shared/wikis/wikis';
|
2020-07-09 20:09:13 -04:00
|
|
|
import Tracking from '~/tracking';
|
2019-08-01 01:54:52 -04:00
|
|
|
|
|
|
|
describe('Wikis', () => {
|
2020-07-09 20:09:13 -04:00
|
|
|
describe('trackPageView', () => {
|
|
|
|
const trackingPage = 'projects:wikis:show';
|
|
|
|
const trackingContext = { foo: 'bar' };
|
|
|
|
const showPageHtmlFixture = `
|
|
|
|
<div class="js-wiki-page-content" data-tracking-context="${escape(
|
|
|
|
JSON.stringify(trackingContext),
|
|
|
|
)}"></div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setHTMLFixture(showPageHtmlFixture);
|
|
|
|
document.body.dataset.page = trackingPage;
|
|
|
|
jest.spyOn(Tracking, 'event').mockImplementation();
|
|
|
|
|
|
|
|
Wikis.trackPageView();
|
|
|
|
});
|
|
|
|
|
2022-05-13 08:08:49 -04:00
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
2020-07-09 20:09:13 -04:00
|
|
|
it('sends the tracking event and context', () => {
|
|
|
|
expect(Tracking.event).toHaveBeenCalledWith(trackingPage, 'view_wiki_page', {
|
|
|
|
label: 'view_wiki_page',
|
|
|
|
context: {
|
2020-10-06 08:08:38 -04:00
|
|
|
schema: 'iglu:com.gitlab/wiki_page_context/jsonschema/1-0-1',
|
2020-07-09 20:09:13 -04:00
|
|
|
data: trackingContext,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-08-01 01:54:52 -04:00
|
|
|
});
|