debian-mirror-gitlab/spec/frontend/merge_requests/components/compare_dropdown_spec.js

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

104 lines
2.7 KiB
JavaScript
Raw Normal View History

2023-03-04 22:38:38 +05:30
import { mount } from '@vue/test-utils';
import { GlCollapsibleListbox } from '@gitlab/ui';
import MockAdapter from 'axios-mock-adapter';
import waitForPromises from 'helpers/wait_for_promises';
import axios from '~/lib/utils/axios_utils';
2023-04-23 21:23:45 +05:30
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
import CompareDropdown from '~/merge_requests/components/compare_dropdown.vue';
2023-03-04 22:38:38 +05:30
let wrapper;
let mock;
2023-04-23 21:23:45 +05:30
function factory(propsData = {}) {
wrapper = mount(CompareDropdown, {
propsData: {
endpoint: '/gitlab-org/gitlab/target_projects',
default: { value: 1, text: 'gitlab-org/gitlab' },
dropdownHeader: 'Select',
inputId: 'input_id',
inputName: 'input_name',
isProject: true,
...propsData,
2023-03-04 22:38:38 +05:30
},
});
}
const findDropdown = () => wrapper.findComponent(GlCollapsibleListbox);
2023-04-23 21:23:45 +05:30
describe('Merge requests compare dropdown component', () => {
2023-03-04 22:38:38 +05:30
beforeEach(() => {
mock = new MockAdapter(axios);
2023-04-23 21:23:45 +05:30
mock.onGet('/gitlab-org/gitlab/target_projects').reply(HTTP_STATUS_OK, [
2023-03-04 22:38:38 +05:30
{
id: 10,
name: 'Gitlab Test',
full_path: '/root/gitlab-test',
full_name: 'Administrator / Gitlab Test',
refs_url: '/root/gitlab-test/refs',
},
{
id: 1,
name: 'Gitlab Test',
full_path: '/gitlab-org/gitlab-test',
full_name: 'Gitlab Org / Gitlab Test',
refs_url: '/gitlab-org/gitlab-test/refs',
},
]);
});
afterEach(() => {
mock.restore();
});
it('creates hidden input with currentProject ID', () => {
factory();
expect(wrapper.find('[data-testid="target-project-input"]').attributes('value')).toBe('1');
});
it('renders list of projects', async () => {
factory();
wrapper.find('[data-testid="base-dropdown-toggle"]').trigger('click');
await waitForPromises();
expect(wrapper.findAll('li').length).toBe(2);
expect(wrapper.findAll('li').at(0).text()).toBe('root/gitlab-test');
expect(wrapper.findAll('li').at(1).text()).toBe('gitlab-org/gitlab-test');
});
it('searches projects', async () => {
factory();
wrapper.find('[data-testid="base-dropdown-toggle"]').trigger('click');
await waitForPromises();
findDropdown().vm.$emit('search', 'test');
jest.advanceTimersByTime(500);
await waitForPromises();
expect(mock.history.get[1].params).toEqual({ search: 'test' });
});
2023-04-23 21:23:45 +05:30
it('renders static data', async () => {
factory({
endpoint: undefined,
staticData: [
{
value: '10',
text: 'GitLab Org',
},
],
});
wrapper.find('[data-testid="base-dropdown-toggle"]').trigger('click');
await waitForPromises();
expect(wrapper.findAll('li').length).toBe(1);
});
2023-03-04 22:38:38 +05:30
});