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

94 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-11-18 11:00:15 +05:30
import Vue 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-09 13:42:32 +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-09 13:42:32 +05:30
let store;
2018-11-18 11:00:15 +05:30
let vm;
beforeEach(() => {
2020-03-09 13:42:32 +05:30
store = createStore();
2018-11-18 11:00:15 +05:30
});
afterEach(() => {
vm.$destroy();
});
2020-03-09 13:42:32 +05:30
const createComponent = (props = {}) => {
vm = mountComponentWithStore(Vue.extend(NavDropdownButton), { props, store });
vm.$mount();
};
2018-11-18 11:00:15 +05:30
2020-03-09 13:42:32 +05:30
const findIcon = name => vm.$el.querySelector(`.ic-${name}`);
const findMRIcon = () => findIcon('merge-request');
const findBranchIcon = () => findIcon('branch');
2018-11-18 11:00:15 +05:30
2020-03-09 13:42:32 +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
2020-03-09 13:42:32 +05:30
it('renders branch name, if state has currentBranchId', done => {
vm.$store.state.currentBranchId = TEST_BRANCH_ID;
2018-11-18 11:00:15 +05:30
2020-03-09 13:42:32 +05:30
vm.$nextTick()
.then(() => {
expect(trimText(vm.$el.textContent)).toEqual(`${TEST_BRANCH_ID} -`);
})
.then(done)
.catch(done.fail);
});
it('renders mr id, if state has currentMergeRequestId', done => {
vm.$store.state.currentMergeRequestId = TEST_MR_ID;
vm.$nextTick()
.then(() => {
expect(trimText(vm.$el.textContent)).toEqual(`- !${TEST_MR_ID}`);
})
.then(done)
.catch(done.fail);
});
it('renders branch and mr, if state has both', done => {
vm.$store.state.currentBranchId = TEST_BRANCH_ID;
vm.$store.state.currentMergeRequestId = TEST_MR_ID;
vm.$nextTick()
.then(() => {
expect(trimText(vm.$el.textContent)).toEqual(`${TEST_BRANCH_ID} !${TEST_MR_ID}`);
})
.then(done)
.catch(done.fail);
});
it('shows icons', () => {
expect(findBranchIcon()).toBeTruthy();
expect(findMRIcon()).toBeTruthy();
});
2018-11-18 11:00:15 +05:30
});
2020-03-09 13:42:32 +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-09 13:42:32 +05:30
it('shows only branch icon', () => {
expect(findBranchIcon()).toBeTruthy();
expect(findMRIcon()).toBe(null);
});
2018-11-18 11:00:15 +05:30
});
});