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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
import { trimText } from 'helpers/text_helper';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import NavDropdownButton from '~/ide/components/nav_dropdown_button.vue';
import { createStore } from '~/ide/stores';
import { __ } from '~/locale';
describe('NavDropdownButton component', () => {
const TEST_BRANCH_ID = 'lorem-ipsum-dolar';
const TEST_MR_ID = '12345';
let wrapper;
const createComponent = ({ props = {}, state = {} } = {}) => {
const store = createStore();
store.replaceState(state);
wrapper = mountExtended(NavDropdownButton, { propsData: props, store });
};
const findMRIcon = () => wrapper.findByLabelText(__('Merge request'));
const findBranchIcon = () => wrapper.findByLabelText(__('Current Branch'));
describe('normal', () => {
it('renders empty placeholders, if state is falsey', () => {
createComponent();
expect(trimText(wrapper.text())).toBe('- -');
});
it('renders branch name, if state has currentBranchId', () => {
createComponent({ state: { currentBranchId: TEST_BRANCH_ID } });
expect(trimText(wrapper.text())).toBe(`${TEST_BRANCH_ID} -`);
});
it('renders mr id, if state has currentMergeRequestId', () => {
createComponent({ state: { currentMergeRequestId: TEST_MR_ID } });
expect(trimText(wrapper.text())).toBe(`- !${TEST_MR_ID}`);
});
it('renders branch and mr, if state has both', () => {
createComponent({
state: { currentBranchId: TEST_BRANCH_ID, currentMergeRequestId: TEST_MR_ID },
});
expect(trimText(wrapper.text())).toBe(`${TEST_BRANCH_ID} !${TEST_MR_ID}`);
});
it('shows icons', () => {
createComponent();
expect(findBranchIcon().exists()).toBe(true);
expect(findMRIcon().exists()).toBe(true);
});
});
describe('when showMergeRequests=false', () => {
beforeEach(() => {
createComponent({ props: { showMergeRequests: false } });
});
it('shows single empty placeholder, if state is falsey', () => {
expect(trimText(wrapper.text())).toBe('-');
});
it('shows only branch icon', () => {
expect(findBranchIcon().exists()).toBe(true);
expect(findMRIcon().exists()).toBe(false);
});
});
});
|