2020-09-02 14:10:40 -04:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2020-11-03 10:09:05 -05:00
|
|
|
import { initIssuableApp } from '~/issue_show/issue';
|
2020-09-02 14:10:40 -04:00
|
|
|
import * as parseData from '~/issue_show/utils/parse_data';
|
2021-02-14 13:09:20 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-10-27 05:08:48 -04:00
|
|
|
import createStore from '~/notes/stores';
|
2021-05-19 17:12:42 -04:00
|
|
|
import { appProps } from './mock_data/mock_data';
|
2020-09-02 14:10:40 -04:00
|
|
|
|
|
|
|
const mock = new MockAdapter(axios);
|
|
|
|
mock.onGet().reply(200);
|
|
|
|
|
|
|
|
jest.mock('~/lib/utils/poll');
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
const setupHTML = (initialData) => {
|
2020-09-25 02:09:42 -04:00
|
|
|
document.body.innerHTML = `<div id="js-issuable-app"></div>`;
|
|
|
|
document.getElementById('js-issuable-app').dataset.initial = JSON.stringify(initialData);
|
2020-09-02 14:10:40 -04:00
|
|
|
};
|
2020-09-02 05:10:23 -04:00
|
|
|
|
|
|
|
describe('Issue show index', () => {
|
|
|
|
describe('initIssueableApp', () => {
|
2020-09-02 14:10:40 -04:00
|
|
|
it('should initialize app with no potential XSS attack', async () => {
|
|
|
|
const alertSpy = jest.spyOn(window, 'alert').mockImplementation(() => {});
|
|
|
|
const parseDataSpy = jest.spyOn(parseData, 'parseIssuableData');
|
2020-09-02 05:10:23 -04:00
|
|
|
|
2020-09-02 14:10:40 -04:00
|
|
|
setupHTML({
|
|
|
|
...appProps,
|
|
|
|
initialDescriptionHtml: '<svg onload=window.alert(1)>',
|
|
|
|
});
|
2020-09-02 05:10:23 -04:00
|
|
|
|
2020-12-08 16:10:06 -05:00
|
|
|
const initialDataEl = document.getElementById('js-issuable-app');
|
|
|
|
const issuableData = parseData.parseIssuableData(initialDataEl);
|
2020-10-27 05:08:48 -04:00
|
|
|
initIssuableApp(issuableData, createStore());
|
2020-09-02 05:10:23 -04:00
|
|
|
|
2020-09-02 14:10:40 -04:00
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(parseDataSpy).toHaveBeenCalled();
|
2020-09-02 05:10:23 -04:00
|
|
|
expect(alertSpy).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|