Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-25 15:25:58 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-25 15:25:58 +0300
commit21fb7a5e5b6be5c58845460e3a2f9de0c1cfab8c (patch)
tree0a83af79fb27c52ecfd168ddc24648d45943d952 /spec/frontend
parentc052f86b6b4d2428b62a2baac77aee4cc91fc2b1 (diff)
Add latest changes from gitlab-org/gitlab@15-8-stable-ee
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/projects/commit/components/branches_dropdown_spec.js115
-rw-r--r--spec/frontend/projects/commit/components/projects_dropdown_spec.js64
2 files changed, 170 insertions, 9 deletions
diff --git a/spec/frontend/projects/commit/components/branches_dropdown_spec.js b/spec/frontend/projects/commit/components/branches_dropdown_spec.js
index 7334e007e18..a84dd246f5d 100644
--- a/spec/frontend/projects/commit/components/branches_dropdown_spec.js
+++ b/spec/frontend/projects/commit/components/branches_dropdown_spec.js
@@ -1,8 +1,9 @@
-import { GlCollapsibleListbox } from '@gitlab/ui';
+import { GlDropdownItem, GlSearchBoxByType } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import Vuex from 'vuex';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
+import { DEFAULT_DEBOUNCE_AND_THROTTLE_MS } from '~/lib/utils/constants';
import BranchesDropdown from '~/projects/commit/components/branches_dropdown.vue';
Vue.use(Vuex);
@@ -33,7 +34,12 @@ describe('BranchesDropdown', () => {
}),
);
};
- const findDropdown = () => wrapper.findComponent(GlCollapsibleListbox);
+
+ const findAllDropdownItems = () => wrapper.findAllComponents(GlDropdownItem);
+ const findSearchBoxByType = () => wrapper.findComponent(GlSearchBoxByType);
+ const findDropdownItemByIndex = (index) => wrapper.findAllComponents(GlDropdownItem).at(index);
+ const findNoResults = () => wrapper.findByTestId('empty-result-message');
+ const findLoading = () => wrapper.findByTestId('dropdown-text-loading-icon');
afterEach(() => {
wrapper.destroy();
@@ -49,6 +55,72 @@ describe('BranchesDropdown', () => {
it('invokes fetchBranches', () => {
expect(spyFetchBranches).toHaveBeenCalled();
});
+
+ describe('with a value but visually blanked', () => {
+ beforeEach(() => {
+ createComponent({ value: '_main_', blanked: true }, { branch: '_main_' });
+ });
+
+ it('renders all branches', () => {
+ expect(findAllDropdownItems()).toHaveLength(3);
+ expect(findDropdownItemByIndex(0).text()).toBe('_main_');
+ expect(findDropdownItemByIndex(1).text()).toBe('_branch_1_');
+ expect(findDropdownItemByIndex(2).text()).toBe('_branch_2_');
+ });
+
+ it('selects the active branch', () => {
+ expect(wrapper.vm.isSelected('_main_')).toBe(true);
+ });
+ });
+ });
+
+ describe('Loading states', () => {
+ it('shows loading icon while fetching', () => {
+ createComponent({ value: '' }, { isFetching: true });
+
+ expect(findLoading().isVisible()).toBe(true);
+ });
+
+ it('does not show loading icon', () => {
+ createComponent({ value: '' });
+
+ expect(findLoading().isVisible()).toBe(false);
+ });
+ });
+
+ describe('No branches found', () => {
+ beforeEach(() => {
+ createComponent({ value: '_non_existent_branch_' });
+ });
+
+ it('renders empty results message', () => {
+ expect(findNoResults().text()).toBe('No matching results');
+ });
+
+ it('shows GlSearchBoxByType with default attributes', () => {
+ expect(findSearchBoxByType().exists()).toBe(true);
+ expect(findSearchBoxByType().vm.$attrs).toMatchObject({
+ placeholder: 'Search branches',
+ debounce: DEFAULT_DEBOUNCE_AND_THROTTLE_MS,
+ });
+ });
+ });
+
+ describe('Search term is empty', () => {
+ beforeEach(() => {
+ createComponent({ value: '' });
+ });
+
+ it('renders all branches when search term is empty', () => {
+ expect(findAllDropdownItems()).toHaveLength(3);
+ expect(findDropdownItemByIndex(0).text()).toBe('_main_');
+ expect(findDropdownItemByIndex(1).text()).toBe('_branch_1_');
+ expect(findDropdownItemByIndex(2).text()).toBe('_branch_2_');
+ });
+
+ it('should not be selected on the inactive branch', () => {
+ expect(wrapper.vm.isSelected('_main_')).toBe(false);
+ });
});
describe('When searching', () => {
@@ -59,7 +131,7 @@ describe('BranchesDropdown', () => {
it('invokes fetchBranches', async () => {
const spy = jest.spyOn(wrapper.vm, 'fetchBranches');
- findDropdown().vm.$emit('search', '_anything_');
+ findSearchBoxByType().vm.$emit('input', '_anything_');
await nextTick();
@@ -68,13 +140,46 @@ describe('BranchesDropdown', () => {
});
});
+ describe('Branches found', () => {
+ beforeEach(() => {
+ createComponent({ value: '_branch_1_' }, { branch: '_branch_1_' });
+ });
+
+ it('renders only the branch searched for', () => {
+ expect(findAllDropdownItems()).toHaveLength(1);
+ expect(findDropdownItemByIndex(0).text()).toBe('_branch_1_');
+ });
+
+ it('should not display empty results message', () => {
+ expect(findNoResults().exists()).toBe(false);
+ });
+
+ it('should signify this branch is selected', () => {
+ expect(wrapper.vm.isSelected('_branch_1_')).toBe(true);
+ });
+
+ it('should signify the branch is not selected', () => {
+ expect(wrapper.vm.isSelected('_not_selected_branch_')).toBe(false);
+ });
+
+ describe('Custom events', () => {
+ it('should emit selectBranch if an branch is clicked', () => {
+ findDropdownItemByIndex(0).vm.$emit('click');
+
+ expect(wrapper.emitted('selectBranch')).toEqual([['_branch_1_']]);
+ expect(wrapper.vm.searchTerm).toBe('_branch_1_');
+ });
+ });
+ });
+
describe('Case insensitive for search term', () => {
beforeEach(() => {
createComponent({ value: '_BrAnCh_1_' });
});
- it('returns only the branch searched for', () => {
- expect(findDropdown().props('items')).toEqual([{ text: '_branch_1_', value: '_branch_1_' }]);
+ it('renders only the branch searched for', () => {
+ expect(findAllDropdownItems()).toHaveLength(1);
+ expect(findDropdownItemByIndex(0).text()).toBe('_branch_1_');
});
});
});
diff --git a/spec/frontend/projects/commit/components/projects_dropdown_spec.js b/spec/frontend/projects/commit/components/projects_dropdown_spec.js
index 0e213ff388a..bb20918e0cd 100644
--- a/spec/frontend/projects/commit/components/projects_dropdown_spec.js
+++ b/spec/frontend/projects/commit/components/projects_dropdown_spec.js
@@ -1,4 +1,4 @@
-import { GlCollapsibleListbox } from '@gitlab/ui';
+import { GlDropdownItem, GlSearchBoxByType } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex';
@@ -35,23 +35,78 @@ describe('ProjectsDropdown', () => {
);
};
- const findDropdown = () => wrapper.findComponent(GlCollapsibleListbox);
+ const findAllDropdownItems = () => wrapper.findAllComponents(GlDropdownItem);
+ const findSearchBoxByType = () => wrapper.findComponent(GlSearchBoxByType);
+ const findDropdownItemByIndex = (index) => wrapper.findAllComponents(GlDropdownItem).at(index);
+ const findNoResults = () => wrapper.findByTestId('empty-result-message');
afterEach(() => {
wrapper.destroy();
spyFetchProjects.mockReset();
});
+ describe('No projects found', () => {
+ beforeEach(() => {
+ createComponent('_non_existent_project_');
+ });
+
+ it('renders empty results message', () => {
+ expect(findNoResults().text()).toBe('No matching results');
+ });
+
+ it('shows GlSearchBoxByType with default attributes', () => {
+ expect(findSearchBoxByType().exists()).toBe(true);
+ expect(findSearchBoxByType().vm.$attrs).toMatchObject({
+ placeholder: 'Search projects',
+ });
+ });
+ });
+
+ describe('Search term is empty', () => {
+ beforeEach(() => {
+ createComponent('');
+ });
+
+ it('renders all projects when search term is empty', () => {
+ expect(findAllDropdownItems()).toHaveLength(3);
+ expect(findDropdownItemByIndex(0).text()).toBe('_project_1_');
+ expect(findDropdownItemByIndex(1).text()).toBe('_project_2_');
+ expect(findDropdownItemByIndex(2).text()).toBe('_project_3_');
+ });
+
+ it('should not be selected on the inactive project', () => {
+ expect(wrapper.vm.isSelected('_project_1_')).toBe(false);
+ });
+ });
+
describe('Projects found', () => {
beforeEach(() => {
createComponent('_project_1_', { targetProjectId: '1' });
});
+ it('renders only the project searched for', () => {
+ expect(findAllDropdownItems()).toHaveLength(1);
+ expect(findDropdownItemByIndex(0).text()).toBe('_project_1_');
+ });
+
+ it('should not display empty results message', () => {
+ expect(findNoResults().exists()).toBe(false);
+ });
+
+ it('should signify this project is selected', () => {
+ expect(findDropdownItemByIndex(0).props('isChecked')).toBe(true);
+ });
+
+ it('should signify the project is not selected', () => {
+ expect(wrapper.vm.isSelected('_not_selected_project_')).toBe(false);
+ });
+
describe('Custom events', () => {
it('should emit selectProject if a project is clicked', () => {
- findDropdown().vm.$emit('select', '1');
+ findDropdownItemByIndex(0).vm.$emit('click');
expect(wrapper.emitted('selectProject')).toEqual([['1']]);
+ expect(wrapper.vm.filterTerm).toBe('_project_1_');
});
});
});
@@ -62,7 +117,8 @@ describe('ProjectsDropdown', () => {
});
it('renders only the project searched for', () => {
- expect(findDropdown().props('items')).toEqual([{ text: '_project_1_', value: '1' }]);
+ expect(findAllDropdownItems()).toHaveLength(1);
+ expect(findDropdownItemByIndex(0).text()).toBe('_project_1_');
});
});
});