Skip to content
代码片段 群组 项目
提交 30dcf8bd 编辑于 作者: Lukas 'Eipi' Eipert's avatar Lukas 'Eipi' Eipert
浏览文件

Merge branch 'eduardosanz/entity_select_additional_event' into 'master'

Enrich `input` event with both value and text -- EntitySelect

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/125610



Merged-by: default avatarLukas 'Eipi' Eipert <leipert@gitlab.com>
Approved-by: default avatarTan Le <tle@gitlab.com>
Approved-by: default avatarLukas 'Eipi' Eipert <leipert@gitlab.com>
Co-authored-by: default avatarEduardo Sanz García <esanz-garcia@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -75,10 +75,13 @@ export default { ...@@ -75,10 +75,13 @@ export default {
computed: { computed: {
selected: { selected: {
set(value) { set(value) {
this.$emit('input', value);
this.selectedValue = value; this.selectedValue = value;
this.selectedText = this.selectedText =
value === null ? null : this.items.find((item) => item.value === value).text; value === null ? null : this.items.find((item) => item.value === value).text;
this.$emit('input', {
value: this.selectedValue,
text: this.selectedText,
});
}, },
get() { get() {
return this.selectedValue; return this.selectedValue;
...@@ -161,7 +164,7 @@ export default { ...@@ -161,7 +164,7 @@ export default {
}, },
onReset() { onReset() {
this.selected = null; this.selected = null;
this.$emit('input', null); this.$emit('input', {});
}, },
onBottomReached() { onBottomReached() {
this.fetchEntities(this.page + 1); this.fetchEntities(this.page + 1);
......
...@@ -99,8 +99,8 @@ export default { ...@@ -99,8 +99,8 @@ export default {
} }
return { items: groups, totalPages }; return { items: groups, totalPages };
}, },
handleEntitySelectInput(input) { handleEntitySelectInput({ value }) {
this.excludedId = input; this.excludedId = value;
}, },
}, },
}; };
......
...@@ -37,7 +37,7 @@ describe('ExcludedNamespacesForm', () => { ...@@ -37,7 +37,7 @@ describe('ExcludedNamespacesForm', () => {
const submitForm = () => wrapper.find('form').trigger('submit'); const submitForm = () => wrapper.find('form').trigger('submit');
const fillAndSubmitForm = () => { const fillAndSubmitForm = () => {
findReasonInput().vm.$emit('input', mockReason); findReasonInput().vm.$emit('input', mockReason);
findEntitySelect().vm.$emit('input', mockNamespaceId); findEntitySelect().vm.$emit('input', { value: mockNamespaceId });
submitForm(); submitForm();
......
...@@ -125,7 +125,8 @@ describe('EntitySelect', () => { ...@@ -125,7 +125,8 @@ describe('EntitySelect', () => {
it('emits `input` event with the select value', async () => { it('emits `input` event with the select value', async () => {
createComponent(); createComponent();
await selectGroup(); await selectGroup();
expect(wrapper.emitted('input')[0]).toEqual(['1']);
expect(wrapper.emitted('input')[0][0]).toMatchObject(itemMock);
}); });
it(`uses the selected group's name as the toggle text`, async () => { it(`uses the selected group's name as the toggle text`, async () => {
...@@ -153,14 +154,14 @@ describe('EntitySelect', () => { ...@@ -153,14 +154,14 @@ describe('EntitySelect', () => {
expect(findListbox().props('toggleText')).toBe(defaultToggleText); expect(findListbox().props('toggleText')).toBe(defaultToggleText);
}); });
it('emits `input` event with `null` on reset', async () => { it('emits `input` event with an empty object on reset', async () => {
createComponent(); createComponent();
await selectGroup(); await selectGroup();
findListbox().vm.$emit('reset'); findListbox().vm.$emit('reset');
await nextTick(); await nextTick();
expect(wrapper.emitted('input')[2]).toEqual([null]); expect(Object.keys(wrapper.emitted('input')[2][0]).length).toBe(0);
}); });
}); });
}); });
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册