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

64 lines
2.1 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', () => {
const lineRanges = ['old', 'new', null].map(type => ({
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);
});
});
2020-07-28 23:09:34 +05:30
describe('getCommentedLines', () => {
const diffLines = [{ line_code: '1' }, { line_code: '2' }, { line_code: '3' }];
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
});