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

82 lines
2.3 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import Vue, { nextTick } from 'vue';
2020-05-24 23:13:21 +05:30
import { trimText } from 'helpers/text_helper';
import { mountComponentWithStore } from 'helpers/vue_mount_component_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';
2018-11-18 11:00:15 +05:30
describe('NavDropdown', () => {
const TEST_BRANCH_ID = 'lorem-ipsum-dolar';
const TEST_MR_ID = '12345';
2020-03-13 15:44:24 +05:30
let store;
2018-11-18 11:00:15 +05:30
let vm;
beforeEach(() => {
2020-03-13 15:44:24 +05:30
store = createStore();
2018-11-18 11:00:15 +05:30
});
afterEach(() => {
vm.$destroy();
});
2020-03-13 15:44:24 +05:30
const createComponent = (props = {}) => {
vm = mountComponentWithStore(Vue.extend(NavDropdownButton), { props, store });
vm.$mount();
};
2018-11-18 11:00:15 +05:30
2021-03-08 18:12:59 +05:30
const findIcon = (name) => vm.$el.querySelector(`[data-testid="${name}-icon"]`);
2020-03-13 15:44:24 +05:30
const findMRIcon = () => findIcon('merge-request');
const findBranchIcon = () => findIcon('branch');
2018-11-18 11:00:15 +05:30
2020-03-13 15:44:24 +05:30
describe('normal', () => {
beforeEach(() => {
createComponent();
});
it('renders empty placeholders, if state is falsey', () => {
expect(trimText(vm.$el.textContent)).toEqual('- -');
});
2018-11-18 11:00:15 +05:30
2022-04-04 11:22:00 +05:30
it('renders branch name, if state has currentBranchId', async () => {
2020-03-13 15:44:24 +05:30
vm.$store.state.currentBranchId = TEST_BRANCH_ID;
2018-11-18 11:00:15 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
expect(trimText(vm.$el.textContent)).toEqual(`${TEST_BRANCH_ID} -`);
2020-03-13 15:44:24 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders mr id, if state has currentMergeRequestId', async () => {
2020-03-13 15:44:24 +05:30
vm.$store.state.currentMergeRequestId = TEST_MR_ID;
2022-04-04 11:22:00 +05:30
await nextTick();
expect(trimText(vm.$el.textContent)).toEqual(`- !${TEST_MR_ID}`);
2020-03-13 15:44:24 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders branch and mr, if state has both', async () => {
2020-03-13 15:44:24 +05:30
vm.$store.state.currentBranchId = TEST_BRANCH_ID;
vm.$store.state.currentMergeRequestId = TEST_MR_ID;
2022-04-04 11:22:00 +05:30
await nextTick();
expect(trimText(vm.$el.textContent)).toEqual(`${TEST_BRANCH_ID} !${TEST_MR_ID}`);
2020-03-13 15:44:24 +05:30
});
it('shows icons', () => {
expect(findBranchIcon()).toBeTruthy();
expect(findMRIcon()).toBeTruthy();
});
2018-11-18 11:00:15 +05:30
});
2020-03-13 15:44:24 +05:30
describe('with showMergeRequests false', () => {
beforeEach(() => {
createComponent({ showMergeRequests: false });
});
it('shows single empty placeholder, if state is falsey', () => {
expect(trimText(vm.$el.textContent)).toEqual('-');
});
2018-11-18 11:00:15 +05:30
2020-03-13 15:44:24 +05:30
it('shows only branch icon', () => {
expect(findBranchIcon()).toBeTruthy();
expect(findMRIcon()).toBe(null);
});
2018-11-18 11:00:15 +05:30
});
});