Commit 845cb647 authored by Savas Vedova's avatar Savas Vedova Committed by Andrew Fontaine

Fix submit button not being clickable

The vulnerability status bulk update form is updating the submit
button's disabled state on form submission. After the submission
is complete the button remains disabled. This commit fixes that
behaviour.

Changelog: fixed
EE: true
parent 14f00cbb
...@@ -27,6 +27,7 @@ export default { ...@@ -27,6 +27,7 @@ export default {
}, },
data() { data() {
return { return {
isSubmitting: false,
updateErrorText: null, updateErrorText: null,
selectedStatus: null, selectedStatus: null,
selectedStatusPayload: undefined, selectedStatusPayload: undefined,
...@@ -51,6 +52,7 @@ export default { ...@@ -51,6 +52,7 @@ export default {
}, },
handleSubmit() { handleSubmit() {
this.isSubmitting = true;
this.updateErrorText = null; this.updateErrorText = null;
let fulfilledCount = 0; let fulfilledCount = 0;
const rejected = []; const rejected = [];
...@@ -77,6 +79,8 @@ export default { ...@@ -77,6 +79,8 @@ export default {
}); });
return Promise.all(promises).then(() => { return Promise.all(promises).then(() => {
this.isSubmitting = false;
if (fulfilledCount > 0) { if (fulfilledCount > 0) {
toast(this.$options.i18n.vulnerabilitiesUpdated(fulfilledCount)); toast(this.$options.i18n.vulnerabilitiesUpdated(fulfilledCount));
eventHub.$emit('vulnerabilities-updated', this); eventHub.$emit('vulnerabilities-updated', this);
...@@ -128,7 +132,7 @@ export default { ...@@ -128,7 +132,7 @@ export default {
<gl-button type="button" class="gl-mr-4" @click="resetSelected"> <gl-button type="button" class="gl-mr-4" @click="resetSelected">
{{ $options.i18n.cancel }} {{ $options.i18n.cancel }}
</gl-button> </gl-button>
<gl-button type="submit" category="primary" variant="confirm"> <gl-button type="submit" category="primary" variant="confirm" :disabled="isSubmitting">
{{ $options.i18n.changeStatus }} {{ $options.i18n.changeStatus }}
</gl-button> </gl-button>
</template> </template>
......
...@@ -17,10 +17,6 @@ localVue.use(VueApollo); ...@@ -17,10 +17,6 @@ localVue.use(VueApollo);
describe('Selection Summary component', () => { describe('Selection Summary component', () => {
let wrapper; let wrapper;
const defaultData = {
dismissalReason: null,
};
const createApolloProvider = (...queries) => { const createApolloProvider = (...queries) => {
return createMockApollo([...queries]); return createMockApollo([...queries]);
}; };
...@@ -29,8 +25,9 @@ describe('Selection Summary component', () => { ...@@ -29,8 +25,9 @@ describe('Selection Summary component', () => {
const findGlAlert = () => wrapper.findComponent(GlAlert); const findGlAlert = () => wrapper.findComponent(GlAlert);
const findCancelButton = () => wrapper.find('[type="button"]'); const findCancelButton = () => wrapper.find('[type="button"]');
const findSubmitButton = () => wrapper.find('[type="submit"]'); const findSubmitButton = () => wrapper.find('[type="submit"]');
const isSubmitButtonDisabled = () => findSubmitButton().props('disabled');
const createComponent = ({ props = {}, data = defaultData, apolloProvider } = {}) => { const createComponent = ({ props = {}, apolloProvider } = {}) => {
wrapper = shallowMount(SelectionSummary, { wrapper = shallowMount(SelectionSummary, {
localVue, localVue,
apolloProvider, apolloProvider,
...@@ -41,13 +38,11 @@ describe('Selection Summary component', () => { ...@@ -41,13 +38,11 @@ describe('Selection Summary component', () => {
selectedVulnerabilities: [], selectedVulnerabilities: [],
...props, ...props,
}, },
data: () => data,
}); });
}; };
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
describe('with 1 vulnerability selected', () => { describe('with 1 vulnerability selected', () => {
...@@ -116,7 +111,6 @@ describe('Selection Summary component', () => { ...@@ -116,7 +111,6 @@ describe('Selection Summary component', () => {
const submitForm = async () => { const submitForm = async () => {
wrapper.find(StatusDropdown).vm.$emit('change', { action, payload }); wrapper.find(StatusDropdown).vm.$emit('change', { action, payload });
findForm().trigger('submit'); findForm().trigger('submit');
await waitForPromises(); await waitForPromises();
}; };
...@@ -171,7 +165,10 @@ describe('Selection Summary component', () => { ...@@ -171,7 +165,10 @@ describe('Selection Summary component', () => {
}), }),
]); ]);
createComponent({ apolloProvider, props: { selectedVulnerabilities } }); createComponent({
apolloProvider,
props: { selectedVulnerabilities },
});
}); });
it(`emits an update for each vulnerability - ${action}`, async () => { it(`emits an update for each vulnerability - ${action}`, async () => {
...@@ -186,6 +183,15 @@ describe('Selection Summary component', () => { ...@@ -186,6 +183,15 @@ describe('Selection Summary component', () => {
expect(toast).toHaveBeenLastCalledWith('3 vulnerabilities updated'); expect(toast).toHaveBeenLastCalledWith('3 vulnerabilities updated');
}); });
it(`the submit button is unclickable during form submission - ${action}`, async () => {
expect(findSubmitButton().exists()).toBe(false);
submitForm();
await wrapper.vm.$nextTick();
expect(isSubmitButtonDisabled()).toBe(true);
await waitForPromises();
expect(isSubmitButtonDisabled()).toBe(false);
});
it(`emits an event for the event hub - ${action}`, async () => { it(`emits an event for the event hub - ${action}`, async () => {
const spy = jest.fn(); const spy = jest.fn();
eventHub.$on('vulnerabilities-updated', spy); eventHub.$on('vulnerabilities-updated', spy);
......
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