debian-mirror-gitlab/spec/frontend/confidential_merge_request/components/dropdown_spec.js

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

80 lines
1.8 KiB
JavaScript
Raw Normal View History

2023-04-23 21:23:45 +05:30
import { GlCollapsibleListbox } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
2019-09-30 21:07:59 +05:30
import Dropdown from '~/confidential_merge_request/components/dropdown.vue';
2023-04-23 21:23:45 +05:30
const TEST_PROJECTS = [
{
id: 7,
name: 'test',
},
{
id: 9,
name: 'lorem ipsum',
},
{
id: 11,
name: 'dolar sit',
},
];
2019-09-30 21:07:59 +05:30
2023-04-23 21:23:45 +05:30
describe('~/confidential_merge_request/components/dropdown.vue', () => {
let wrapper;
2019-09-30 21:07:59 +05:30
2023-04-23 21:23:45 +05:30
function factory(props = {}) {
wrapper = shallowMount(Dropdown, {
propsData: {
projects: TEST_PROJECTS,
...props,
2019-09-30 21:07:59 +05:30
},
2023-04-23 21:23:45 +05:30
});
}
2019-09-30 21:07:59 +05:30
2023-04-23 21:23:45 +05:30
const findListbox = () => wrapper.findComponent(GlCollapsibleListbox);
describe('default', () => {
beforeEach(() => {
factory();
});
it('renders collapsible listbox', () => {
expect(findListbox().props()).toMatchObject({
icon: 'lock',
selected: [],
toggleText: 'Select private project',
block: true,
items: TEST_PROJECTS.map(({ id, name }) => ({
value: String(id),
text: name,
})),
});
});
it('does not emit anything', () => {
expect(wrapper.emitted()).toEqual({});
});
2019-09-30 21:07:59 +05:30
2023-04-23 21:23:45 +05:30
describe('when listbox emits selected', () => {
beforeEach(() => {
findListbox().vm.$emit('select', String(TEST_PROJECTS[1].id));
});
2021-01-03 14:25:43 +05:30
2023-04-23 21:23:45 +05:30
it('emits selected project', () => {
expect(wrapper.emitted('select')).toEqual([[TEST_PROJECTS[1]]]);
});
});
2021-01-03 14:25:43 +05:30
});
2023-04-23 21:23:45 +05:30
describe('with selected', () => {
beforeEach(() => {
factory({ selectedProject: TEST_PROJECTS[1] });
});
2019-09-30 21:07:59 +05:30
2023-04-23 21:23:45 +05:30
it('shows selected project', () => {
expect(findListbox().props()).toMatchObject({
selected: String(TEST_PROJECTS[1].id),
toggleText: TEST_PROJECTS[1].name,
});
});
2019-09-30 21:07:59 +05:30
});
});