Commit e718970d authored by Mark Florian's avatar Mark Florian

Merge branch '213925-fix-geo-replicables' into 'master'

Geo Replicables - Use debounce prop

See merge request gitlab-org/gitlab!39744
parents 8ad39554 f64968e5
<script> <script>
import { mapActions, mapState, mapGetters } from 'vuex'; import { mapActions, mapState, mapGetters } from 'vuex';
import { debounce } from 'lodash';
import { import {
GlSearchBoxByType, GlSearchBoxByType,
GlDeprecatedDropdown, GlDeprecatedDropdown,
...@@ -25,10 +24,10 @@ export default { ...@@ -25,10 +24,10 @@ export default {
get() { get() {
return this.searchFilter; return this.searchFilter;
}, },
set: debounce(function debounceSearch(newVal) { set(val) {
this.setSearch(newVal); this.setSearch(val);
this.fetchReplicableItems(); this.fetchReplicableItems();
}, DEFAULT_SEARCH_DELAY), },
}, },
resyncText() { resyncText() {
return sprintf(__('Resync all %{replicableType}'), { return sprintf(__('Resync all %{replicableType}'), {
...@@ -45,6 +44,7 @@ export default { ...@@ -45,6 +44,7 @@ export default {
}, },
actionTypes: ACTION_TYPES, actionTypes: ACTION_TYPES,
filterStates: FILTER_STATES, filterStates: FILTER_STATES,
debounce: DEFAULT_SEARCH_DELAY,
}; };
</script> </script>
...@@ -68,6 +68,7 @@ export default { ...@@ -68,6 +68,7 @@ export default {
</gl-deprecated-dropdown> </gl-deprecated-dropdown>
<gl-search-box-by-type <gl-search-box-by-type
v-model="search" v-model="search"
:debounce="$options.debounce"
class="px-1 my-1 my-sm-0 bg-white w-100" class="px-1 my-1 my-sm-0 bg-white w-100"
type="text" type="text"
:placeholder="__('Filter by name')" :placeholder="__('Filter by name')"
......
import Vuex from 'vuex'; import Vuex from 'vuex';
import { createLocalVue, mount } from '@vue/test-utils'; import { createLocalVue, shallowMount } from '@vue/test-utils';
import { import {
GlDeprecatedDropdown, GlDeprecatedDropdown,
GlDeprecatedDropdownItem, GlDeprecatedDropdownItem,
...@@ -25,7 +25,7 @@ describe('GeoReplicableFilterBar', () => { ...@@ -25,7 +25,7 @@ describe('GeoReplicableFilterBar', () => {
}; };
const createComponent = () => { const createComponent = () => {
wrapper = mount(GeoReplicableFilterBar, { wrapper = shallowMount(GeoReplicableFilterBar, {
localVue, localVue,
store: createStore({ replicableType: MOCK_REPLICABLE_TYPE, graphqlFieldName: null }), store: createStore({ replicableType: MOCK_REPLICABLE_TYPE, graphqlFieldName: null }),
methods: { methods: {
...@@ -75,51 +75,44 @@ describe('GeoReplicableFilterBar', () => { ...@@ -75,51 +75,44 @@ describe('GeoReplicableFilterBar', () => {
const index = 1; const index = 1;
findGlDropdownItems() findGlDropdownItems()
.at(index) .at(index)
.find('button') .vm.$emit('click');
.trigger('click');
expect(actionSpies.setFilter).toHaveBeenCalledWith(index); expect(actionSpies.setFilter).toHaveBeenCalledWith(index);
}); });
}); });
it('renders a search box always', () => { describe('Search box', () => {
expect(findGlSearchBox().exists()).toBeTruthy();
});
describe('Re-sync all button', () => {
it('renders always', () => { it('renders always', () => {
expect(findGlButton().exists()).toBeTruthy(); expect(findGlSearchBox().exists()).toBe(true);
}); });
it('calls initiateAllReplicableSyncs when clicked', () => { it('has debounce prop', () => {
findGlButton().trigger('click'); expect(findGlSearchBox().attributes('debounce')).toBe(DEFAULT_SEARCH_DELAY.toString());
expect(actionSpies.initiateAllReplicableSyncs).toHaveBeenCalled();
});
});
}); });
// TODO: These specs should fixed once we have a proper mock for debounce describe('onSearch', () => {
// https://gitlab.com/gitlab-org/gitlab/-/issues/213925 const testSearch = 'test search';
// eslint-disable-next-line jest/no-disabled-tests
describe.skip('when search changes', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); findGlSearchBox().vm.$emit('input', testSearch);
actionSpies.fetchReplicableItems.mockClear(); // Will get called on init
wrapper.vm.search = 'test search';
}); });
it(`should wait ${DEFAULT_SEARCH_DELAY}ms before calling setSearch`, () => { it('calls fetchSyncNamespaces when input event is fired from GlSearchBoxByType', () => {
expect(actionSpies.setSearch).not.toHaveBeenCalledWith('test search'); expect(actionSpies.setSearch).toHaveBeenCalledWith(testSearch);
expect(actionSpies.fetchReplicableItems).toHaveBeenCalled();
jest.runAllTimers(); // Debounce });
expect(actionSpies.setSearch).toHaveBeenCalledWith('test search'); });
}); });
it(`should wait ${DEFAULT_SEARCH_DELAY}ms before calling fetchReplicableItems`, () => { describe('Re-sync all button', () => {
expect(actionSpies.fetchReplicableItems).not.toHaveBeenCalled(); it('renders always', () => {
expect(findGlButton().exists()).toBeTruthy();
});
jest.runAllTimers(); // Debounce it('calls initiateAllReplicableSyncs when clicked', () => {
expect(actionSpies.fetchReplicableItems).toHaveBeenCalled(); findGlButton().vm.$emit('click');
expect(actionSpies.initiateAllReplicableSyncs).toHaveBeenCalled();
});
}); });
}); });
......
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