Commit bee1489a authored by Zack Cuddy's avatar Zack Cuddy Committed by Ezekiel Kigbo

Geo Node Form - Use debounce prop

This replaces the lodash debounce
implementation with the debounce
prop.
parent dfdfb82d
<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,10 +56,16 @@ describe('GeoNodeFormNamespaces', () => { ...@@ -56,10 +56,16 @@ describe('GeoNodeFormNamespaces', () => {
expect(findGlDropdown().exists()).toBe(true); expect(findGlDropdown().exists()).toBe(true);
}); });
it('renders findGlDropdownSearch', () => { describe('findGlDropdownSearch', () => {
it('renders always', () => {
expect(findGlDropdownSearch().exists()).toBe(true); expect(findGlDropdownSearch().exists()).toBe(true);
}); });
it('has debounce prop', () => {
expect(findGlDropdownSearch().attributes('debounce')).toBe('500');
});
});
describe('findDropdownItems', () => { describe('findDropdownItems', () => {
beforeEach(() => { beforeEach(() => {
delete actionSpies.isSelected; delete actionSpies.isSelected;
...@@ -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', () => {
expect(actionSpies.fetchSyncNamespaces).not.toHaveBeenCalledWith(namespaceSearch);
jest.advanceTimersByTime(500); // Debounce it('calls fetchSyncNamespaces when input event is fired from GlSearchBoxByType', () => {
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