debian-mirror-gitlab/spec/frontend/vue_shared/components/notes/system_note_spec.js

102 lines
2.7 KiB
JavaScript
Raw Normal View History

2021-12-11 22:18:48 +05:30
import MockAdapter from 'axios-mock-adapter';
2020-03-13 15:44:24 +05:30
import { mount } from '@vue/test-utils';
2021-12-11 22:18:48 +05:30
import waitForPromises from 'helpers/wait_for_promises';
2019-07-31 22:56:46 +05:30
import initMRPopovers from '~/mr_popover/index';
2021-03-11 19:13:27 +05:30
import createStore from '~/notes/stores';
import IssueSystemNote from '~/vue_shared/components/notes/system_note.vue';
2021-12-11 22:18:48 +05:30
import axios from '~/lib/utils/axios_utils';
2019-07-31 22:56:46 +05:30
jest.mock('~/mr_popover/index', () => jest.fn());
2018-03-17 18:26:18 +05:30
2018-11-08 19:23:39 +05:30
describe('system note component', () => {
2018-03-17 18:26:18 +05:30
let vm;
let props;
2021-12-11 22:18:48 +05:30
let mock;
function createComponent(propsData = {}) {
const store = createStore();
store.dispatch('setTargetNoteHash', `note_${props.note.id}`);
vm = mount(IssueSystemNote, {
store,
propsData,
});
}
2018-03-17 18:26:18 +05:30
beforeEach(() => {
props = {
note: {
2018-11-20 20:47:30 +05:30
id: '1424',
2018-03-17 18:26:18 +05:30
author: {
id: 1,
name: 'Root',
username: 'root',
state: 'active',
avatar_url: 'path',
path: '/root',
},
note_html: '<p dir="auto">closed</p>',
2018-11-18 11:00:15 +05:30
system_note_icon_name: 'status_closed',
2018-03-17 18:26:18 +05:30
created_at: '2017-08-02T10:51:58.559Z',
},
};
2021-12-11 22:18:48 +05:30
mock = new MockAdapter(axios);
2018-03-17 18:26:18 +05:30
});
afterEach(() => {
2020-01-01 13:55:28 +05:30
vm.destroy();
2021-12-11 22:18:48 +05:30
mock.restore();
2018-03-17 18:26:18 +05:30
});
it('should render a list item with correct id', () => {
2021-12-11 22:18:48 +05:30
createComponent(props);
2020-01-01 13:55:28 +05:30
expect(vm.attributes('id')).toEqual(`note_${props.note.id}`);
2018-03-17 18:26:18 +05:30
});
it('should render target class is note is target note', () => {
2021-12-11 22:18:48 +05:30
createComponent(props);
2020-01-01 13:55:28 +05:30
expect(vm.classes()).toContain('target');
2018-03-17 18:26:18 +05:30
});
it('should render svg icon', () => {
2021-12-11 22:18:48 +05:30
createComponent(props);
2020-01-01 13:55:28 +05:30
expect(vm.find('.timeline-icon svg').exists()).toBe(true);
2018-03-17 18:26:18 +05:30
});
2018-11-08 19:23:39 +05:30
// Redcarpet Markdown renderer wraps text in `<p>` tags
// we need to strip them because they break layout of commit lists in system notes:
2019-12-04 20:38:33 +05:30
// https://gitlab.com/gitlab-org/gitlab-foss/uploads/b07a10670919254f0220d3ff5c1aa110/jqzI.png
2018-11-08 19:23:39 +05:30
it('removes wrapping paragraph from note HTML', () => {
2021-12-11 22:18:48 +05:30
createComponent(props);
2020-01-01 13:55:28 +05:30
expect(vm.find('.system-note-message').html()).toContain('<span>closed</span>');
2018-03-17 18:26:18 +05:30
});
2019-07-07 11:18:12 +05:30
it('should initMRPopovers onMount', () => {
2021-12-11 22:18:48 +05:30
createComponent(props);
2019-07-31 22:56:46 +05:30
expect(initMRPopovers).toHaveBeenCalled();
2019-07-07 11:18:12 +05:30
});
2021-12-11 22:18:48 +05:30
it('renders outdated code lines', async () => {
mock
.onGet('/outdated_line_change_path')
.reply(200, [
{ rich_text: 'console.log', type: 'new', line_code: '123', old_line: null, new_line: 1 },
]);
createComponent({
note: { ...props.note, outdated_line_change_path: '/outdated_line_change_path' },
});
await vm.find("[data-testid='outdated-lines-change-btn']").trigger('click');
await waitForPromises();
expect(vm.find("[data-testid='outdated-lines']").exists()).toBe(true);
});
2018-03-17 18:26:18 +05:30
});