2020-09-02 14:10:40 -04:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import { useMockIntersectionObserver } from 'helpers/mock_dom_observer';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-09-02 05:10:23 -04:00
|
|
|
import initIssuableApp from '~/issue_show/issue';
|
2020-09-02 14:10:40 -04:00
|
|
|
import * as parseData from '~/issue_show/utils/parse_data';
|
|
|
|
import { appProps } from './mock_data';
|
|
|
|
|
|
|
|
const mock = new MockAdapter(axios);
|
|
|
|
mock.onGet().reply(200);
|
|
|
|
|
|
|
|
useMockIntersectionObserver();
|
|
|
|
|
|
|
|
jest.mock('~/lib/utils/poll');
|
|
|
|
|
|
|
|
const setupHTML = initialData => {
|
|
|
|
document.body.innerHTML = `
|
|
|
|
<div id="js-issuable-app"></div>
|
|
|
|
<script id="js-issuable-app-initial-data" type="application/json">
|
|
|
|
${JSON.stringify(initialData)}
|
|
|
|
</script>
|
|
|
|
`;
|
|
|
|
};
|
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-09-02 14:10:40 -04:00
|
|
|
const issuableData = parseData.parseIssuableData();
|
2020-09-02 05:10:23 -04:00
|
|
|
initIssuableApp(issuableData);
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|