debian-mirror-gitlab/spec/frontend/ide/components/nav_dropdown_button_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import { trimText } from 'helpers/text_helper';
2022-08-13 15:12:31 +05:30
import { mountExtended } from 'helpers/vue_test_utils_helper';
2020-01-01 13:55:28 +05:30
import NavDropdownButton from '~/ide/components/nav_dropdown_button.vue';
2020-03-13 15:44:24 +05:30
import { createStore } from '~/ide/stores';
2022-08-13 15:12:31 +05:30
import { __ } from '~/locale';
2018-11-18 11:00:15 +05:30
2022-08-13 15:12:31 +05:30
describe('NavDropdownButton component', () => {
2018-11-18 11:00:15 +05:30
const TEST_BRANCH_ID = 'lorem-ipsum-dolar';
const TEST_MR_ID = '12345';
2022-08-13 15:12:31 +05:30
let wrapper;
2018-11-18 11:00:15 +05:30
2022-08-13 15:12:31 +05:30
const createComponent = ({ props = {}, state = {} } = {}) => {
const store = createStore();
store.replaceState(state);
wrapper = mountExtended(NavDropdownButton, { propsData: props, store });
2020-03-13 15:44:24 +05:30
};
2018-11-18 11:00:15 +05:30
2022-08-13 15:12:31 +05:30
const findMRIcon = () => wrapper.findByLabelText(__('Merge request'));
const findBranchIcon = () => wrapper.findByLabelText(__('Current Branch'));
2018-11-18 11:00:15 +05:30
2020-03-13 15:44:24 +05:30
describe('normal', () => {
2022-08-13 15:12:31 +05:30
it('renders empty placeholders, if state is falsey', () => {
2020-03-13 15:44:24 +05:30
createComponent();
2022-08-13 15:12:31 +05:30
expect(trimText(wrapper.text())).toBe('- -');
2020-03-13 15:44:24 +05:30
});
2018-11-18 11:00:15 +05:30
2022-08-13 15:12:31 +05:30
it('renders branch name, if state has currentBranchId', () => {
createComponent({ state: { currentBranchId: TEST_BRANCH_ID } });
2018-11-18 11:00:15 +05:30
2022-08-13 15:12:31 +05:30
expect(trimText(wrapper.text())).toBe(`${TEST_BRANCH_ID} -`);
2020-03-13 15:44:24 +05:30
});
2022-08-13 15:12:31 +05:30
it('renders mr id, if state has currentMergeRequestId', () => {
createComponent({ state: { currentMergeRequestId: TEST_MR_ID } });
2020-03-13 15:44:24 +05:30
2022-08-13 15:12:31 +05:30
expect(trimText(wrapper.text())).toBe(`- !${TEST_MR_ID}`);
2020-03-13 15:44:24 +05:30
});
2022-08-13 15:12:31 +05:30
it('renders branch and mr, if state has both', () => {
createComponent({
state: { currentBranchId: TEST_BRANCH_ID, currentMergeRequestId: TEST_MR_ID },
});
2020-03-13 15:44:24 +05:30
2022-08-13 15:12:31 +05:30
expect(trimText(wrapper.text())).toBe(`${TEST_BRANCH_ID} !${TEST_MR_ID}`);
2020-03-13 15:44:24 +05:30
});
it('shows icons', () => {
2022-08-13 15:12:31 +05:30
createComponent();
expect(findBranchIcon().exists()).toBe(true);
expect(findMRIcon().exists()).toBe(true);
2020-03-13 15:44:24 +05:30
});
2018-11-18 11:00:15 +05:30
});
2022-08-13 15:12:31 +05:30
describe('when showMergeRequests=false', () => {
2020-03-13 15:44:24 +05:30
beforeEach(() => {
2022-08-13 15:12:31 +05:30
createComponent({ props: { showMergeRequests: false } });
2020-03-13 15:44:24 +05:30
});
it('shows single empty placeholder, if state is falsey', () => {
2022-08-13 15:12:31 +05:30
expect(trimText(wrapper.text())).toBe('-');
2020-03-13 15:44:24 +05:30
});
2018-11-18 11:00:15 +05:30
2020-03-13 15:44:24 +05:30
it('shows only branch icon', () => {
2022-08-13 15:12:31 +05:30
expect(findBranchIcon().exists()).toBe(true);
expect(findMRIcon().exists()).toBe(false);
2020-03-13 15:44:24 +05:30
});
2018-11-18 11:00:15 +05:30
});
});