2020-03-13 15:44:24 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import SuggestionDiffComponent from '~/vue_shared/components/markdown/suggestion_diff.vue';
|
|
|
|
import SuggestionDiffHeader from '~/vue_shared/components/markdown/suggestion_diff_header.vue';
|
|
|
|
import SuggestionDiffRow from '~/vue_shared/components/markdown/suggestion_diff_row.vue';
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
const suggestionId = 1;
|
2020-03-13 15:44:24 +05:30
|
|
|
const MOCK_DATA = {
|
|
|
|
suggestion: {
|
2020-06-23 00:09:42 +05:30
|
|
|
id: suggestionId,
|
2020-03-13 15:44:24 +05:30
|
|
|
diff_lines: [
|
|
|
|
{
|
|
|
|
can_receive_suggestion: false,
|
|
|
|
line_code: null,
|
|
|
|
meta_data: null,
|
|
|
|
new_line: null,
|
|
|
|
old_line: 5,
|
|
|
|
rich_text: '-test',
|
|
|
|
text: '-test',
|
|
|
|
type: 'old',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
can_receive_suggestion: true,
|
|
|
|
line_code: null,
|
|
|
|
meta_data: null,
|
|
|
|
new_line: 5,
|
|
|
|
old_line: null,
|
|
|
|
rich_text: '+new test',
|
|
|
|
text: '+new test',
|
|
|
|
type: 'new',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
can_receive_suggestion: true,
|
|
|
|
line_code: null,
|
|
|
|
meta_data: null,
|
|
|
|
new_line: 5,
|
|
|
|
old_line: null,
|
|
|
|
rich_text: '+new test2',
|
|
|
|
text: '+new test2',
|
|
|
|
type: 'new',
|
|
|
|
},
|
|
|
|
],
|
2020-06-23 00:09:42 +05:30
|
|
|
is_applying_batch: true,
|
2020-03-13 15:44:24 +05:30
|
|
|
},
|
|
|
|
helpPagePath: 'path_to_docs',
|
2020-06-23 00:09:42 +05:30
|
|
|
batchSuggestionsInfo: [{ suggestionId }],
|
2020-03-13 15:44:24 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
describe('Suggestion Diff component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const createComponent = () => {
|
|
|
|
wrapper = shallowMount(SuggestionDiffComponent, {
|
|
|
|
propsData: {
|
|
|
|
...MOCK_DATA,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('matches snapshot', () => {
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a correct amount of suggestion diff rows', () => {
|
|
|
|
expect(wrapper.findAll(SuggestionDiffRow)).toHaveLength(3);
|
|
|
|
});
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it.each`
|
|
|
|
event | childArgs | args
|
|
|
|
${'apply'} | ${['test-event']} | ${[{ callback: 'test-event', suggestionId }]}
|
|
|
|
${'applyBatch'} | ${[]} | ${[]}
|
|
|
|
${'addToBatch'} | ${[]} | ${[suggestionId]}
|
|
|
|
${'removeFromBatch'} | ${[]} | ${[suggestionId]}
|
|
|
|
`('emits $event event on sugestion diff header $event', ({ event, childArgs, args }) => {
|
|
|
|
wrapper.find(SuggestionDiffHeader).vm.$emit(event, ...childArgs);
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(wrapper.emitted(event)).toBeDefined();
|
|
|
|
expect(wrapper.emitted(event)).toEqual([args]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes suggestion batch props to suggestion diff header', () => {
|
|
|
|
expect(wrapper.find(SuggestionDiffHeader).props()).toMatchObject({
|
|
|
|
batchSuggestionsCount: 1,
|
|
|
|
isBatched: true,
|
|
|
|
isApplyingBatch: MOCK_DATA.suggestion.is_applying_batch,
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
});
|