2020-07-28 23:09:34 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2019-10-12 21:52:04 +05:30
|
|
|
import { createStore } from '~/mr_notes/stores';
|
2019-02-15 15:39:39 +05:30
|
|
|
import InlineDiffTableRow from '~/diffs/components/inline_diff_table_row.vue';
|
|
|
|
import diffFileMockData from '../mock_data/diff_file';
|
|
|
|
|
|
|
|
describe('InlineDiffTableRow', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
let wrapper;
|
2019-02-15 15:39:39 +05:30
|
|
|
let vm;
|
|
|
|
const thisLine = diffFileMockData.highlighted_diff_lines[0];
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-07-28 23:09:34 +05:30
|
|
|
wrapper = shallowMount(InlineDiffTableRow, {
|
|
|
|
store: createStore(),
|
|
|
|
propsData: {
|
|
|
|
line: thisLine,
|
|
|
|
fileHash: diffFileMockData.file_hash,
|
|
|
|
filePath: diffFileMockData.file_path,
|
|
|
|
contextLinesPath: 'contextLinesPath',
|
|
|
|
isHighlighted: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
vm = wrapper.vm;
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not add hll class to line content when line does not match highlighted row', done => {
|
|
|
|
vm.$nextTick()
|
|
|
|
.then(() => {
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(wrapper.find('.line_content').classes('hll')).toBe(false);
|
2019-02-15 15:39:39 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds hll class to lineContent when line is the highlighted row', done => {
|
|
|
|
vm.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
vm.$store.state.diffs.highlightedRow = thisLine.line_code;
|
|
|
|
|
|
|
|
return vm.$nextTick();
|
|
|
|
})
|
|
|
|
.then(() => {
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(wrapper.find('.line_content').classes('hll')).toBe(true);
|
2019-02-15 15:39:39 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('adds hll class to lineContent when line is part of a multiline comment', () => {
|
|
|
|
wrapper.setProps({ isCommented: true });
|
|
|
|
return vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.find('.line_content').classes('hll')).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
describe('sets coverage title and class', () => {
|
|
|
|
it('for lines with coverage', done => {
|
|
|
|
vm.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
const name = diffFileMockData.file_path;
|
|
|
|
const line = thisLine.new_line;
|
|
|
|
|
|
|
|
vm.$store.state.diffs.coverageFiles = { files: { [name]: { [line]: 5 } } };
|
|
|
|
|
|
|
|
return vm.$nextTick();
|
|
|
|
})
|
|
|
|
.then(() => {
|
2020-07-28 23:09:34 +05:30
|
|
|
const coverage = wrapper.find('.line-coverage');
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(coverage.attributes('title')).toContain('Test coverage: 5 hits');
|
|
|
|
expect(coverage.classes('coverage')).toBe(true);
|
2020-04-08 14:13:33 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('for lines without coverage', done => {
|
|
|
|
vm.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
const name = diffFileMockData.file_path;
|
|
|
|
const line = thisLine.new_line;
|
|
|
|
|
|
|
|
vm.$store.state.diffs.coverageFiles = { files: { [name]: { [line]: 0 } } };
|
|
|
|
|
|
|
|
return vm.$nextTick();
|
|
|
|
})
|
|
|
|
.then(() => {
|
2020-07-28 23:09:34 +05:30
|
|
|
const coverage = wrapper.find('.line-coverage');
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(coverage.attributes('title')).toContain('No test coverage');
|
|
|
|
expect(coverage.classes('no-coverage')).toBe(true);
|
2020-04-08 14:13:33 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('for unknown lines', done => {
|
|
|
|
vm.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
vm.$store.state.diffs.coverageFiles = {};
|
|
|
|
|
|
|
|
return vm.$nextTick();
|
|
|
|
})
|
|
|
|
.then(() => {
|
2020-07-28 23:09:34 +05:30
|
|
|
const coverage = wrapper.find('.line-coverage');
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(coverage.attributes('title')).toBeUndefined();
|
|
|
|
expect(coverage.classes('coverage')).toBe(false);
|
|
|
|
expect(coverage.classes('no-coverage')).toBe(false);
|
2020-04-08 14:13:33 +05:30
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|