diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-09 18:08:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-09 18:08:59 +0300 |
commit | fd8183c340684448fd976af9c0b4217fa58d7211 (patch) | |
tree | 45797af0b5dc7c8cc7d466ce7b816e45ceaf83b2 /spec/frontend/merge_requests | |
parent | 5b98c2c50664b78cbf50094de6b40abcff818831 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/merge_requests')
-rw-r--r-- | spec/frontend/merge_requests/components/target_project_dropdown_spec.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/spec/frontend/merge_requests/components/target_project_dropdown_spec.js b/spec/frontend/merge_requests/components/target_project_dropdown_spec.js new file mode 100644 index 00000000000..795fae2f8d8 --- /dev/null +++ b/spec/frontend/merge_requests/components/target_project_dropdown_spec.js @@ -0,0 +1,77 @@ +import { mount } from '@vue/test-utils'; +import MockAdapter from 'axios-mock-adapter'; +import waitForPromises from 'helpers/wait_for_promises'; +import axios from '~/lib/utils/axios_utils'; +import TargetProjectDropdown from '~/merge_requests/components/target_project_dropdown.vue'; + +let wrapper; +let mock; + +function factory() { + wrapper = mount(TargetProjectDropdown, { + provide: { + targetProjectsPath: '/gitlab-org/gitlab/target_projects', + currentProject: { value: 1, text: 'gitlab-org/gitlab' }, + }, + }); +} + +describe('Merge requests target project dropdown component', () => { + beforeEach(() => { + mock = new MockAdapter(axios); + mock.onGet('/gitlab-org/gitlab/target_projects').reply(200, [ + { + 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(() => { + wrapper.destroy(); + 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(); + + wrapper.find('[data-testid="listbox-search-input"]').setValue('test'); + + jest.advanceTimersByTime(500); + await waitForPromises(); + + expect(mock.history.get[1].params).toEqual({ search: 'test' }); + }); +}); |