debian-mirror-gitlab/spec/frontend/notes/components/multiline_comment_utils_spec.js

73 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-06-23 00:09:42 +05:30
import {
getSymbol,
getStartLineNumber,
getEndLineNumber,
2020-07-28 23:09:34 +05:30
getCommentedLines,
2020-06-23 00:09:42 +05:30
} from '~/notes/components/multiline_comment_utils';
describe('Multiline comment utilities', () => {
2020-07-28 23:09:34 +05:30
describe('get start & end line numbers', () => {
2021-03-08 18:12:59 +05:30
const lineRanges = ['old', 'new', null].map((type) => ({
2020-07-28 23:09:34 +05:30
start: { new_line: 1, old_line: 1, type },
end: { new_line: 2, old_line: 2, type },
}));
2020-06-23 00:09:42 +05:30
it.each`
2020-07-28 23:09:34 +05:30
lineRange | start | end
${lineRanges[0]} | ${'-1'} | ${'-2'}
${lineRanges[1]} | ${'+1'} | ${'+2'}
${lineRanges[2]} | ${'1'} | ${'2'}
`('returns line numbers `$start` & `$end`', ({ lineRange, start, end }) => {
expect(getStartLineNumber(lineRange)).toEqual(start);
expect(getEndLineNumber(lineRange)).toEqual(end);
2020-06-23 00:09:42 +05:30
});
});
describe('getSymbol', () => {
it.each`
type | result
${'new'} | ${'+'}
${'old'} | ${'-'}
${'unused'} | ${''}
${''} | ${''}
${null} | ${''}
${undefined} | ${''}
`('`$type` returns `$result`', ({ type, result }) => {
expect(getSymbol(type)).toEqual(result);
});
});
2021-02-22 17:27:13 +05:30
const inlineDiffLines = [{ line_code: '1' }, { line_code: '2' }, { line_code: '3' }];
2021-03-08 18:12:59 +05:30
const parallelDiffLines = inlineDiffLines.map((line) => ({
2021-02-22 17:27:13 +05:30
left: { ...line },
right: { ...line },
}));
describe.each`
view | diffLines
${'inline'} | ${inlineDiffLines}
${'parallel'} | ${parallelDiffLines}
`('getCommentedLines $view view', ({ diffLines }) => {
2020-07-28 23:09:34 +05:30
it('returns a default object when `selectedCommentPosition` is not provided', () => {
expect(getCommentedLines(undefined, diffLines)).toEqual({ startLine: 4, endLine: 4 });
});
it('returns an object with startLine and endLine equal to 0', () => {
const selectedCommentPosition = {
start: { line_code: '1' },
end: { line_code: '1' },
};
expect(getCommentedLines(selectedCommentPosition, diffLines)).toEqual({
startLine: 0,
endLine: 0,
});
});
it('returns an object with startLine and endLine equal to 0 and 1', () => {
const selectedCommentPosition = {
start: { line_code: '1' },
end: { line_code: '2' },
};
expect(getCommentedLines(selectedCommentPosition, diffLines)).toEqual({
startLine: 0,
endLine: 1,
});
});
});
2020-06-23 00:09:42 +05:30
});