diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-13 03:11:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-13 03:11:29 +0300 |
commit | 248057a54a1d5fb7db018ef77cda3fee2b0c8ded (patch) | |
tree | b1098b6b2839fff1d3b7b4ad1e6969f16be5d2df /spec/frontend/tags | |
parent | beab869416d5720126a8cbe76f6c842a9b9d9300 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/tags')
-rw-r--r-- | spec/frontend/tags/components/sort_dropdown_spec.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/spec/frontend/tags/components/sort_dropdown_spec.js b/spec/frontend/tags/components/sort_dropdown_spec.js new file mode 100644 index 00000000000..b0fd98ec68e --- /dev/null +++ b/spec/frontend/tags/components/sort_dropdown_spec.js @@ -0,0 +1,81 @@ +import { GlDropdownItem, GlSearchBoxByClick } from '@gitlab/ui'; +import { mount } from '@vue/test-utils'; +import { extendedWrapper } from 'helpers/vue_test_utils_helper'; +import * as urlUtils from '~/lib/utils/url_utility'; +import SortDropdown from '~/tags/components/sort_dropdown.vue'; + +describe('Tags sort dropdown', () => { + let wrapper; + + const createWrapper = (props = {}) => { + return extendedWrapper( + mount(SortDropdown, { + provide: { + filterTagsPath: '/root/ci-cd-project-demo/-/tags', + sortOptions: { + name_asc: 'Name', + updated_asc: 'Oldest updated', + updated_desc: 'Last updated', + }, + ...props, + }, + }), + ); + }; + + const findSearchBox = () => wrapper.findComponent(GlSearchBoxByClick); + const findTagsDropdown = () => wrapper.findByTestId('tags-dropdown'); + + afterEach(() => { + if (wrapper) { + wrapper.destroy(); + } + }); + + describe('default state', () => { + beforeEach(() => { + wrapper = createWrapper(); + }); + + it('should have a search box with a placeholder', () => { + const searchBox = findSearchBox(); + + expect(searchBox.exists()).toBe(true); + expect(searchBox.find('input').attributes('placeholder')).toBe('Filter by tag name'); + }); + + it('should have a sort order dropdown', () => { + const branchesDropdown = findTagsDropdown(); + + expect(branchesDropdown.exists()).toBe(true); + }); + }); + + describe('when submitting a search term', () => { + beforeEach(() => { + urlUtils.visitUrl = jest.fn(); + + wrapper = createWrapper(); + }); + + it('should call visitUrl', () => { + const searchBox = findSearchBox(); + + searchBox.vm.$emit('submit'); + + expect(urlUtils.visitUrl).toHaveBeenCalledWith( + '/root/ci-cd-project-demo/-/tags?sort=updated_desc', + ); + }); + + it('should send a sort parameter', () => { + const sortDropdownItems = findTagsDropdown().findAllComponents(GlDropdownItem).at(0); + + sortDropdownItems.vm.$emit('click'); + + expect(urlUtils.visitUrl).toHaveBeenCalledWith( + '/root/ci-cd-project-demo/-/tags?sort=name_asc', + ); + }); + }); +}); |