Skip to content
代码片段 群组 项目
提交 c2a242bc 编辑于 作者: Thomas Randolph's avatar Thomas Randolph 提交者: Kushal Pandya
浏览文件

Migrate approvers_select GLDropdown to <select>

上级 d2eac44e
No related branches found
No related tags found
无相关合并请求
<script> <script>
import { GlCollapsibleListbox, GlDropdown, GlDropdownItem, GlAvatarLabeled } from '@gitlab/ui'; import { GlIcon, GlCollapsibleListbox, GlAvatarLabeled } from '@gitlab/ui';
import Api from 'ee/api'; import Api from 'ee/api';
import { NAMESPACE_TYPES } from 'ee/security_orchestration/constants'; import { NAMESPACE_TYPES } from 'ee/security_orchestration/constants';
import { import {
...@@ -17,10 +17,9 @@ function addType(type) { ...@@ -17,10 +17,9 @@ function addType(type) {
export default { export default {
components: { components: {
GlIcon,
GlCollapsibleListbox, GlCollapsibleListbox,
GlAvatarLabeled, GlAvatarLabeled,
GlDropdown,
GlDropdownItem,
}, },
i18n: { i18n: {
toggleText: SEARCH_PLACEHOLDER, toggleText: SEARCH_PLACEHOLDER,
...@@ -147,7 +146,9 @@ export default { ...@@ -147,7 +146,9 @@ export default {
this.listboxItems = this.listboxItems.filter((item) => item.value !== selected); this.listboxItems = this.listboxItems.filter((item) => item.value !== selected);
}, },
selectGroupOption(option) { selectGroupOption(inputEvent) {
const option = inputEvent.target.value;
if (option === this.selectedGroupOption) { if (option === this.selectedGroupOption) {
return; return;
} }
...@@ -159,7 +160,7 @@ export default { ...@@ -159,7 +160,7 @@ export default {
</script> </script>
<template> <template>
<div> <div class="gl-display-flex">
<gl-collapsible-listbox <gl-collapsible-listbox
:items="listboxItems" :items="listboxItems"
:toggle-text="$options.i18n.toggleText" :toggle-text="$options.i18n.toggleText"
...@@ -184,14 +185,17 @@ export default { ...@@ -184,14 +185,17 @@ export default {
/> />
</template> </template>
</gl-collapsible-listbox> </gl-collapsible-listbox>
<gl-dropdown :text="selectedGroupOption" class="gl-w-30p gl-ml-4"> <div class="gl-relative gl-ml-4 gl-flex-grow-1">
<gl-dropdown-item <select class="gl-pr-6 form-control select-control" @input="selectGroupOption">
v-for="groupOption in $options.groupOptions" <option v-for="opt in $options.groupOptions" :key="opt" :value="opt">
:key="groupOption" {{ $options.i18n.dropdownItemLabel }} {{ opt }}
@click="selectGroupOption(groupOption)" </option>
> </select>
{{ $options.i18n.dropdownItemLabel }} {{ groupOption }} <gl-icon
</gl-dropdown-item> name="chevron-down"
</gl-dropdown> data-hidden="true"
class="gl-absolute gl-top-3 gl-right-3 gl-text-gray-500"
/>
</div>
</div> </div>
</template> </template>
import { import { GlCollapsibleListbox, GlListboxItem, GlAvatarLabeled } from '@gitlab/ui';
GlCollapsibleListbox,
GlListboxItem,
GlAvatarLabeled,
GlDropdown,
GlDropdownItem,
} from '@gitlab/ui';
import { nextTick } from 'vue'; import { nextTick } from 'vue';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
...@@ -13,7 +7,7 @@ import waitForPromises from 'helpers/wait_for_promises'; ...@@ -13,7 +7,7 @@ import waitForPromises from 'helpers/wait_for_promises';
import Api from 'ee/api'; import Api from 'ee/api';
import ApproversSelect from 'ee/approvals/components/approvers_select.vue'; import ApproversSelect from 'ee/approvals/components/approvers_select.vue';
import { NAMESPACE_TYPES } from 'ee/security_orchestration/constants'; import { NAMESPACE_TYPES } from 'ee/security_orchestration/constants';
import { TYPE_USER, GROUP_OPTIONS, DROPDOWN_OPTION_ALL_GROUPS } from 'ee/approvals/constants'; import { TYPE_USER, GROUP_OPTIONS } from 'ee/approvals/constants';
const TEST_PROJECT_ID = '17'; const TEST_PROJECT_ID = '17';
const TEST_GROUP_AVATAR = `${TEST_HOST}/group-avatar.png`; const TEST_GROUP_AVATAR = `${TEST_HOST}/group-avatar.png`;
...@@ -40,8 +34,8 @@ describe('Approvers Selector', () => { ...@@ -40,8 +34,8 @@ describe('Approvers Selector', () => {
const findListbox = () => wrapper.findComponent(GlCollapsibleListbox); const findListbox = () => wrapper.findComponent(GlCollapsibleListbox);
const findAllListboxItems = () => wrapper.findAllComponents(GlListboxItem); const findAllListboxItems = () => wrapper.findAllComponents(GlListboxItem);
const findAvatar = (index) => findAllListboxItems().at(index).findComponent(GlAvatarLabeled); const findAvatar = (index) => findAllListboxItems().at(index).findComponent(GlAvatarLabeled);
const findGroupOptionsDropdown = () => wrapper.findComponent(GlDropdown); const findGroupOptionsDropdown = () => wrapper.find('select');
const findGroupOtions = () => wrapper.findAllComponents(GlDropdownItem); const findGroupOptions = () => wrapper.findAll('option');
const search = (searchString) => findListbox().vm.$emit('search', searchString); const search = (searchString) => findListbox().vm.$emit('search', searchString);
const createComponent = (props = {}) => { const createComponent = (props = {}) => {
...@@ -138,15 +132,9 @@ describe('Approvers Selector', () => { ...@@ -138,15 +132,9 @@ describe('Approvers Selector', () => {
expect(findGroupOptionsDropdown().exists()).toBe(true); expect(findGroupOptionsDropdown().exists()).toBe(true);
}); });
it('renders all groups option selected by default', () => {
createComponent();
expect(findGroupOptionsDropdown().props('text')).toBe(DROPDOWN_OPTION_ALL_GROUPS);
});
it('renders expected amount of group options', () => { it('renders expected amount of group options', () => {
createComponent(); createComponent();
expect(findGroupOtions()).toHaveLength(GROUP_OPTIONS.length); expect(findGroupOptions()).toHaveLength(GROUP_OPTIONS.length);
}); });
}); });
...@@ -241,7 +229,11 @@ describe('Approvers Selector', () => { ...@@ -241,7 +229,11 @@ describe('Approvers Selector', () => {
describe('on project groups option selection', () => { describe('on project groups option selection', () => {
it('fetches project groups when the project group option is selected', async () => { it('fetches project groups when the project group option is selected', async () => {
createComponent(); createComponent();
findGroupOtions().at(1).vm.$emit('click');
const groupOptions = findGroupOptionsDropdown();
groupOptions.element.value = 'project groups';
groupOptions.trigger('input');
await waitForPromises(); await waitForPromises();
expect(Api.projectGroups).toHaveBeenCalledWith('17', { expect(Api.projectGroups).toHaveBeenCalledWith('17', {
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册