debian-mirror-gitlab/spec/frontend/batch_comments/components/preview_item_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

125 lines
3.3 KiB
JavaScript
Raw Normal View History

2022-11-25 23:54:43 +05:30
import { mount } from '@vue/test-utils';
2020-10-24 23:57:45 +05:30
import PreviewItem from '~/batch_comments/components/preview_item.vue';
2020-06-23 00:09:42 +05:30
import { createStore } from '~/batch_comments/stores';
import diffsModule from '~/diffs/store/modules';
import notesModule from '~/notes/stores/modules';
import { createDraft } from '../mock_data';
2023-03-04 22:38:38 +05:30
jest.mock('~/behaviors/markdown/render_gfm');
2020-06-23 00:09:42 +05:30
describe('Batch comments draft preview item component', () => {
2022-11-25 23:54:43 +05:30
let wrapper;
2020-06-23 00:09:42 +05:30
let draft;
function createComponent(isLast = false, extra = {}, extendStore = () => {}) {
const store = createStore();
store.registerModule('diffs', diffsModule());
store.registerModule('notes', notesModule());
extendStore(store);
draft = {
...createDraft(),
...extra,
};
2022-11-25 23:54:43 +05:30
wrapper = mount(PreviewItem, { store, propsData: { draft, isLast } });
2020-06-23 00:09:42 +05:30
}
it('renders text content', () => {
createComponent(false, { note_html: '<img src="" /><p>Hello world</p>' });
2022-11-25 23:54:43 +05:30
expect(wrapper.find('.review-preview-item-content').element.innerHTML).toBe(
2020-06-23 00:09:42 +05:30
'<p>Hello world</p>',
);
});
describe('for file', () => {
it('renders file path', () => {
createComponent(false, { file_path: 'index.js', file_hash: 'abc', position: {} });
2022-11-25 23:54:43 +05:30
expect(wrapper.find('.review-preview-item-header-text').text()).toContain('index.js');
2020-06-23 00:09:42 +05:30
});
it('renders new line position', () => {
createComponent(false, {
file_path: 'index.js',
file_hash: 'abc',
2021-03-11 19:13:27 +05:30
position: {
line_range: {
start: {
new_line: 1,
type: 'new',
},
},
},
2020-06-23 00:09:42 +05:30
});
2022-11-25 23:54:43 +05:30
expect(wrapper.find('.bold').text()).toContain(':+1');
2020-06-23 00:09:42 +05:30
});
it('renders old line position', () => {
createComponent(false, {
file_path: 'index.js',
file_hash: 'abc',
2021-03-11 19:13:27 +05:30
position: {
line_range: {
start: {
old_line: 2,
},
},
},
2020-06-23 00:09:42 +05:30
});
2022-11-25 23:54:43 +05:30
expect(wrapper.find('.bold').text()).toContain(':2');
2020-06-23 00:09:42 +05:30
});
it('renders image position', () => {
createComponent(false, {
file_path: 'index.js',
file_hash: 'abc',
position: { position_type: 'image', x: 10, y: 20 },
});
2022-11-25 23:54:43 +05:30
expect(wrapper.find('.bold').text()).toContain('10x 20y');
2020-06-23 00:09:42 +05:30
});
});
describe('for thread', () => {
beforeEach(() => {
2021-03-08 18:12:59 +05:30
createComponent(false, { discussion_id: '1', resolve_discussion: true }, (store) => {
2020-06-23 00:09:42 +05:30
store.state.notes.discussions.push({
id: '1',
notes: [
{
author: {
2021-09-04 01:27:46 +05:30
name: "Author 'Nick' Name",
2020-06-23 00:09:42 +05:30
},
},
],
});
});
});
it('renders title', () => {
2022-11-25 23:54:43 +05:30
expect(wrapper.find('.review-preview-item-header-text').text()).toContain(
2021-09-04 01:27:46 +05:30
"Author 'Nick' Name's thread",
2020-06-23 00:09:42 +05:30
);
});
2022-10-11 01:57:18 +05:30
it('renders thread resolved text', () => {
2022-11-25 23:54:43 +05:30
expect(wrapper.find('.draft-note-resolution').text()).toContain('Thread will be resolved');
2020-06-23 00:09:42 +05:30
});
});
2021-04-29 21:17:54 +05:30
describe('for new comment', () => {
it('renders title', () => {
createComponent(false, {}, (store) => {
store.state.notes.discussions.push({});
});
2022-11-25 23:54:43 +05:30
expect(wrapper.find('.review-preview-item-header-text').text()).toContain('Your new comment');
2021-04-29 21:17:54 +05:30
});
});
2020-06-23 00:09:42 +05:30
});