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

140 lines
3.6 KiB
JavaScript
Raw Normal View History

2020-06-23 00:09:42 +05:30
import Vue from 'vue';
import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
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 '~/behaviors/markdown/render_gfm';
import { createDraft } from '../mock_data';
describe('Batch comments draft preview item component', () => {
let vm;
let Component;
let draft;
function createComponent(isLast = false, extra = {}, extendStore = () => {}) {
const store = createStore();
store.registerModule('diffs', diffsModule());
store.registerModule('notes', notesModule());
extendStore(store);
draft = {
...createDraft(),
...extra,
};
vm = mountComponentWithStore(Component, { store, props: { draft, isLast } });
}
beforeAll(() => {
Component = Vue.extend(PreviewItem);
});
afterEach(() => {
vm.$destroy();
});
it('renders text content', () => {
createComponent(false, { note_html: '<img src="" /><p>Hello world</p>' });
expect(vm.$el.querySelector('.review-preview-item-content').innerHTML).toEqual(
'<p>Hello world</p>',
);
});
describe('for file', () => {
it('renders file path', () => {
createComponent(false, { file_path: 'index.js', file_hash: 'abc', position: {} });
expect(vm.$el.querySelector('.review-preview-item-header-text').textContent).toContain(
'index.js',
);
});
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
});
2021-03-11 19:13:27 +05:30
expect(vm.$el.querySelector('.bold').textContent).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
});
expect(vm.$el.querySelector('.bold').textContent).toContain(':2');
});
it('renders image position', () => {
createComponent(false, {
file_path: 'index.js',
file_hash: 'abc',
position: { position_type: 'image', x: 10, y: 20 },
});
expect(vm.$el.querySelector('.bold').textContent).toContain('10x 20y');
});
});
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', () => {
expect(vm.$el.querySelector('.review-preview-item-header-text').textContent).toContain(
2021-09-04 01:27:46 +05:30
"Author 'Nick' Name's thread",
2020-06-23 00:09:42 +05:30
);
});
it('it renders thread resolved text', () => {
expect(vm.$el.querySelector('.draft-note-resolution').textContent).toContain(
'Thread will be resolved',
);
});
});
2021-04-29 21:17:54 +05:30
describe('for new comment', () => {
it('renders title', () => {
createComponent(false, {}, (store) => {
store.state.notes.discussions.push({});
});
expect(vm.$el.querySelector('.review-preview-item-header-text').textContent).toContain(
'Your new comment',
);
});
});
2020-06-23 00:09:42 +05:30
});