debian-mirror-gitlab/spec/javascripts/ide/components/nav_dropdown_spec.js

81 lines
2 KiB
JavaScript
Raw Normal View History

2018-11-18 11:00:15 +05:30
import $ from 'jquery';
import Vue from 'vue';
2020-01-01 13:55:28 +05:30
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
2018-11-18 11:00:15 +05:30
import store from '~/ide/stores';
import NavDropdown from '~/ide/components/nav_dropdown.vue';
2020-03-09 13:42:32 +05:30
import { PERMISSION_READ_MR } from '~/ide/constants';
const TEST_PROJECT_ID = 'lorem-ipsum';
2018-11-18 11:00:15 +05:30
describe('IDE NavDropdown', () => {
const Component = Vue.extend(NavDropdown);
let vm;
let $dropdown;
beforeEach(() => {
2020-03-09 13:42:32 +05:30
store.state.currentProjectId = TEST_PROJECT_ID;
Vue.set(store.state.projects, TEST_PROJECT_ID, {
userPermissions: {
[PERMISSION_READ_MR]: true,
},
});
2018-11-18 11:00:15 +05:30
vm = mountComponentWithStore(Component, { store });
$dropdown = $(vm.$el);
// block dispatch from doing anything
spyOn(vm.$store, 'dispatch');
});
afterEach(() => {
vm.$destroy();
});
2020-03-09 13:42:32 +05:30
const findIcon = name => vm.$el.querySelector(`.ic-${name}`);
const findMRIcon = () => findIcon('merge-request');
2018-11-18 11:00:15 +05:30
it('renders nothing initially', () => {
expect(vm.$el).not.toContainElement('.ide-nav-form');
});
it('renders nav form when show.bs.dropdown', done => {
$dropdown.trigger('show.bs.dropdown');
vm.$nextTick()
.then(() => {
expect(vm.$el).toContainElement('.ide-nav-form');
})
.then(done)
.catch(done.fail);
});
it('destroys nav form when closed', done => {
$dropdown.trigger('show.bs.dropdown');
$dropdown.trigger('hide.bs.dropdown');
vm.$nextTick()
.then(() => {
expect(vm.$el).not.toContainElement('.ide-nav-form');
})
.then(done)
.catch(done.fail);
});
2020-03-09 13:42:32 +05:30
it('renders merge request icon', () => {
expect(findMRIcon()).not.toBeNull();
});
describe('when user cannot read merge requests', () => {
beforeEach(done => {
store.state.projects[TEST_PROJECT_ID].userPermissions = {};
vm.$nextTick()
.then(done)
.catch(done.fail);
});
it('does not render merge requests', () => {
expect(findMRIcon()).toBeNull();
});
});
2018-11-18 11:00:15 +05:30
});