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

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

94 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import { mount } from '@vue/test-utils';
2021-03-11 19:13:27 +05:30
import $ from 'jquery';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2020-05-24 23:13:21 +05:30
import NavDropdown from '~/ide/components/nav_dropdown.vue';
import { PERMISSION_READ_MR } from '~/ide/constants';
2021-03-11 19:13:27 +05:30
import { createStore } from '~/ide/stores';
2020-05-24 23:13:21 +05:30
const TEST_PROJECT_ID = 'lorem-ipsum';
describe('IDE NavDropdown', () => {
let store;
let wrapper;
beforeEach(() => {
store = createStore();
Object.assign(store.state, {
currentProjectId: TEST_PROJECT_ID,
2021-09-04 01:27:46 +05:30
currentBranchId: 'main',
2020-05-24 23:13:21 +05:30
projects: {
[TEST_PROJECT_ID]: {
userPermissions: {
[PERMISSION_READ_MR]: true,
},
branches: {
2021-09-04 01:27:46 +05:30
main: { id: 'main' },
2020-05-24 23:13:21 +05:30
},
},
},
});
jest.spyOn(store, 'dispatch').mockImplementation(() => {});
});
afterEach(() => {
wrapper.destroy();
});
const createComponent = () => {
wrapper = mount(NavDropdown, {
store,
});
};
2021-03-08 18:12:59 +05:30
const findIcon = (name) => wrapper.find(`[data-testid="${name}-icon"]`);
2020-05-24 23:13:21 +05:30
const findMRIcon = () => findIcon('merge-request');
const findNavForm = () => wrapper.find('.ide-nav-form');
const showDropdown = () => {
$(wrapper.vm.$el).trigger('show.bs.dropdown');
};
const hideDropdown = () => {
$(wrapper.vm.$el).trigger('hide.bs.dropdown');
};
describe('default', () => {
beforeEach(() => {
createComponent();
});
it('renders nothing initially', () => {
expect(findNavForm().exists()).toBe(false);
});
2022-04-04 11:22:00 +05:30
it('renders nav form when show.bs.dropdown', async () => {
2020-05-24 23:13:21 +05:30
showDropdown();
2022-04-04 11:22:00 +05:30
await nextTick();
expect(findNavForm().exists()).toBe(true);
2020-05-24 23:13:21 +05:30
});
2022-04-04 11:22:00 +05:30
it('destroys nav form when closed', async () => {
2020-05-24 23:13:21 +05:30
showDropdown();
hideDropdown();
2022-04-04 11:22:00 +05:30
await nextTick();
expect(findNavForm().exists()).toBe(false);
2020-05-24 23:13:21 +05:30
});
it('renders merge request icon', () => {
expect(findMRIcon().exists()).toBe(true);
});
});
describe('when user cannot read merge requests', () => {
beforeEach(() => {
store.state.projects[TEST_PROJECT_ID].userPermissions = {};
createComponent();
});
it('does not render merge requests', () => {
expect(findMRIcon().exists()).toBe(false);
});
});
});