1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import { formatListBoxItems, formatErrors } from '~/ref/format_refs';
import { DEFAULT_I18N } from '~/ref/constants';
import {
MOCK_BRANCHES,
MOCK_COMMITS,
MOCK_ERROR,
MOCK_TAGS,
FORMATTED_BRANCHES,
FORMATTED_TAGS,
FORMATTED_COMMITS,
} from './mock_data';
describe('formatListBoxItems', () => {
it.each`
branches | tags | commits | expectedResult
${MOCK_BRANCHES} | ${MOCK_TAGS} | ${MOCK_COMMITS} | ${[FORMATTED_BRANCHES, FORMATTED_TAGS, FORMATTED_COMMITS]}
${MOCK_BRANCHES} | ${[]} | ${MOCK_COMMITS} | ${[FORMATTED_BRANCHES, FORMATTED_COMMITS]}
${[]} | ${[]} | ${MOCK_COMMITS} | ${[FORMATTED_COMMITS]}
${undefined} | ${undefined} | ${MOCK_COMMITS} | ${[FORMATTED_COMMITS]}
${MOCK_BRANCHES} | ${undefined} | ${null} | ${[FORMATTED_BRANCHES]}
`('should correctly format listbox items', ({ branches, tags, commits, expectedResult }) => {
expect(formatListBoxItems(branches, tags, commits)).toEqual(expectedResult);
});
});
describe('formatErrors', () => {
const { branchesErrorMessage, tagsErrorMessage, commitsErrorMessage } = DEFAULT_I18N;
it.each`
branches | tags | commits | expectedResult
${MOCK_ERROR} | ${MOCK_ERROR} | ${MOCK_ERROR} | ${[branchesErrorMessage, tagsErrorMessage, commitsErrorMessage]}
${MOCK_ERROR} | ${[]} | ${MOCK_ERROR} | ${[branchesErrorMessage, commitsErrorMessage]}
${[]} | ${[]} | ${MOCK_ERROR} | ${[commitsErrorMessage]}
${undefined} | ${undefined} | ${MOCK_ERROR} | ${[commitsErrorMessage]}
${MOCK_ERROR} | ${undefined} | ${null} | ${[branchesErrorMessage]}
`('should correctly format listbox errors', ({ branches, tags, commits, expectedResult }) => {
expect(formatErrors(branches, tags, commits)).toEqual(expectedResult);
});
});
|