Commit cb5cc942 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch '213925-use-debounce-prop' into 'master'

Geo Node Form - Use debounce prop

Closes #213925

See merge request gitlab-org/gitlab!39630
parents 8b62d092 bee1489a
<script> <script>
import { GlIcon, GlSearchBoxByType, GlDeprecatedDropdown, GlDeprecatedButton } from '@gitlab/ui'; import { GlIcon, GlSearchBoxByType, GlDeprecatedDropdown, GlDeprecatedButton } from '@gitlab/ui';
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import { debounce } from 'lodash';
import { __, n__ } from '~/locale'; import { __, n__ } from '~/locale';
import { SELECTIVE_SYNC_NAMESPACES } from '../constants'; import { SELECTIVE_SYNC_NAMESPACES } from '../constants';
...@@ -37,9 +36,9 @@ export default { ...@@ -37,9 +36,9 @@ export default {
}, },
}, },
watch: { watch: {
namespaceSearch: debounce(function debounceSearch() { namespaceSearch() {
this.fetchSyncNamespaces(this.namespaceSearch); this.fetchSyncNamespaces(this.namespaceSearch);
}, 500), },
}, },
methods: { methods: {
...mapActions(['fetchSyncNamespaces']), ...mapActions(['fetchSyncNamespaces']),
...@@ -60,7 +59,7 @@ export default { ...@@ -60,7 +59,7 @@ export default {
<template> <template>
<gl-deprecated-dropdown :text="dropdownTitle" @show="fetchSyncNamespaces(namespaceSearch)"> <gl-deprecated-dropdown :text="dropdownTitle" @show="fetchSyncNamespaces(namespaceSearch)">
<gl-search-box-by-type v-model="namespaceSearch" class="m-2" /> <gl-search-box-by-type v-model="namespaceSearch" class="m-2" :debounce="500" />
<li v-for="namespace in synchronizationNamespaces" :key="namespace.id"> <li v-for="namespace in synchronizationNamespaces" :key="namespace.id">
<gl-deprecated-button class="d-flex align-items-center" @click="toggleNamespace(namespace)"> <gl-deprecated-button class="d-flex align-items-center" @click="toggleNamespace(namespace)">
<gl-icon :class="[{ invisible: !isSelected(namespace) }]" name="mobile-issue-close" /> <gl-icon :class="[{ invisible: !isSelected(namespace) }]" name="mobile-issue-close" />
......
...@@ -56,8 +56,14 @@ describe('GeoNodeFormNamespaces', () => { ...@@ -56,8 +56,14 @@ describe('GeoNodeFormNamespaces', () => {
expect(findGlDropdown().exists()).toBe(true); expect(findGlDropdown().exists()).toBe(true);
}); });
it('renders findGlDropdownSearch', () => { describe('findGlDropdownSearch', () => {
expect(findGlDropdownSearch().exists()).toBe(true); it('renders always', () => {
expect(findGlDropdownSearch().exists()).toBe(true);
});
it('has debounce prop', () => {
expect(findGlDropdownSearch().attributes('debounce')).toBe('500');
});
}); });
describe('findDropdownItems', () => { describe('findDropdownItems', () => {
...@@ -79,37 +85,17 @@ describe('GeoNodeFormNamespaces', () => { ...@@ -79,37 +85,17 @@ describe('GeoNodeFormNamespaces', () => {
}); });
}); });
// TODO: These specs should fixed once we have a proper mock for debounce describe('watchers', () => {
// https://gitlab.com/gitlab-org/gitlab/-/issues/213925
// eslint-disable-next-line jest/no-disabled-tests
describe.skip('watchers', () => {
describe('namespaceSearch', () => { describe('namespaceSearch', () => {
const namespaceSearch = 'test search'; const namespaceSearch = 'test search';
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
wrapper.setData({ findGlDropdownSearch().vm.$emit('input', namespaceSearch);
namespaceSearch,
});
}); });
it('should wait 500ms before calling fetchSyncNamespaces', () => { it('calls fetchSyncNamespaces when input event is fired from GlSearchBoxByType', () => {
expect(actionSpies.fetchSyncNamespaces).not.toHaveBeenCalledWith(namespaceSearch);
jest.advanceTimersByTime(500); // Debounce
expect(actionSpies.fetchSyncNamespaces).toHaveBeenCalledWith(namespaceSearch); expect(actionSpies.fetchSyncNamespaces).toHaveBeenCalledWith(namespaceSearch);
expect(actionSpies.fetchSyncNamespaces).toHaveBeenCalledTimes(1);
});
it('should call fetchSyncNamespaces once with the latest search term', () => {
expect(actionSpies.fetchSyncNamespaces).not.toHaveBeenCalledWith(namespaceSearch);
wrapper.setData({
namespaceSearch: 'test search2',
});
jest.advanceTimersByTime(500); // Debounce
expect(actionSpies.fetchSyncNamespaces).toHaveBeenCalledWith('test search2');
expect(actionSpies.fetchSyncNamespaces).toHaveBeenCalledTimes(1);
}); });
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment