Commit 9e9fd07f authored by Phil Hughes's avatar Phil Hughes

Merge branch '37951-project-settings-required-approval-input-not-sequential-order' into 'master'

Fix project setting approval input in non-sequential order

See merge request gitlab-org/gitlab!25391
parents d7373a1b 17962dde
---
title: Fix project setting approval input in non-sequential order
merge_request: 25391
author:
type: fixed
<script> <script>
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { RULE_TYPE_ANY_APPROVER } from '../../constants'; import { RULE_TYPE_ANY_APPROVER } from '../../constants';
import { debounce } from 'lodash';
const ANY_RULE_NAME = 'All Members'; const ANY_RULE_NAME = 'All Members';
...@@ -21,17 +22,20 @@ export default { ...@@ -21,17 +22,20 @@ export default {
}, },
methods: { methods: {
...mapActions(['putRule', 'postRule']), ...mapActions(['putRule', 'postRule']),
onInputChange(event) { onInputChange: debounce(function debounceSearch(event) {
const { value } = event.target;
const approvalsRequired = parseInt(value, 10);
if (this.rule.id) { if (this.rule.id) {
this.putRule({ id: this.rule.id, approvalsRequired: Number(event.target.value) }); this.putRule({ id: this.rule.id, approvalsRequired });
} else { } else {
this.postRule({ this.postRule({
name: ANY_RULE_NAME, name: ANY_RULE_NAME,
ruleType: RULE_TYPE_ANY_APPROVER, ruleType: RULE_TYPE_ANY_APPROVER,
approvalsRequired: Number(event.target.value), approvalsRequired,
}); });
} }
}, }, 1000),
}, },
}; };
</script> </script>
......
...@@ -4,6 +4,8 @@ import RuleInput from 'ee/approvals/components/mr_edit/rule_input.vue'; ...@@ -4,6 +4,8 @@ import RuleInput from 'ee/approvals/components/mr_edit/rule_input.vue';
import MREditModule from 'ee/approvals/stores/modules/mr_edit'; import MREditModule from 'ee/approvals/stores/modules/mr_edit';
import { createStoreOptions } from 'ee/approvals/stores'; import { createStoreOptions } from 'ee/approvals/stores';
jest.mock('lodash/debounce', () => jest.fn(fn => fn));
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
...@@ -80,10 +82,14 @@ describe('Rule Input', () => { ...@@ -80,10 +82,14 @@ describe('Rule Input', () => {
wrapper.element.value = wrapper.props().rule.approvalsRequired + 1; wrapper.element.value = wrapper.props().rule.approvalsRequired + 1;
wrapper.trigger('input'); wrapper.trigger('input');
expect(action).toHaveBeenCalledWith( jest.runAllTimers();
expect.anything(),
{ approvalsRequired: 10, id: 5 }, return wrapper.vm.$nextTick().then(() => {
undefined, expect(action).toHaveBeenCalledWith(
); expect.anything(),
{ approvalsRequired: 10, id: 5 },
undefined,
);
});
}); });
}); });
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