2024-07-17 14:53:43 +00:00
|
|
|
import {mount, flushPromises} from '@vue/test-utils';
|
2024-03-29 19:41:13 +00:00
|
|
|
import ContextPopup from './ContextPopup.vue';
|
|
|
|
|
2024-07-17 14:53:43 +00:00
|
|
|
test('renders a issue info popup', async () => {
|
|
|
|
const owner = 'user2';
|
|
|
|
const repo = 'repo1';
|
|
|
|
const index = 1;
|
2024-03-29 19:41:13 +00:00
|
|
|
vi.spyOn(global, 'fetch').mockResolvedValue({
|
|
|
|
json: vi.fn().mockResolvedValue({
|
|
|
|
ok: true,
|
2024-07-17 14:53:43 +00:00
|
|
|
created_at: '2023-09-30T19:00:00Z',
|
|
|
|
repository: {full_name: owner},
|
2024-03-29 19:41:13 +00:00
|
|
|
pull_request: null,
|
|
|
|
state: 'open',
|
2024-07-17 14:53:43 +00:00
|
|
|
title: 'Normal issue',
|
|
|
|
body: 'Lorem ipsum...',
|
|
|
|
number: index,
|
|
|
|
labels: [{color: 'ee0701', name: "Bug :+1: <script class='evil'>alert('Oh no!');</script>"}],
|
2024-03-29 19:41:13 +00:00
|
|
|
}),
|
|
|
|
ok: true,
|
|
|
|
});
|
|
|
|
|
2024-07-17 14:53:43 +00:00
|
|
|
const wrapper = mount(ContextPopup);
|
|
|
|
wrapper.vm.$el.dispatchEvent(new CustomEvent('ce-load-context-popup', {detail: {owner, repo, index}}));
|
2024-03-29 19:41:13 +00:00
|
|
|
await flushPromises();
|
|
|
|
|
2024-07-17 14:53:43 +00:00
|
|
|
// Header
|
|
|
|
expect(wrapper.get('p:nth-of-type(1)').text()).toEqual('user2 on Sep 30, 2023');
|
|
|
|
// Title
|
|
|
|
expect(wrapper.get('p:nth-of-type(2)').text()).toEqual('Normal issue #1');
|
|
|
|
// Body
|
|
|
|
expect(wrapper.get('p:nth-of-type(3)').text()).toEqual('Lorem ipsum...');
|
|
|
|
// Check that the state is correct.
|
|
|
|
expect(wrapper.get('svg').classes()).toContain('octicon-issue-opened');
|
|
|
|
// Ensure that script is not an element.
|
|
|
|
expect(() => wrapper.get('.evil')).toThrowError();
|
|
|
|
// Check content of label
|
|
|
|
expect(wrapper.get('.ui.label').text()).toContain("Bug 👍 <script class='evil'>alert('Oh no!');</script>");
|
2024-03-29 19:41:13 +00:00
|
|
|
});
|