Commit f7648c58 authored by Scott Hampton's avatar Scott Hampton

Merge branch 'pb-disable-trigger-manual-action' into 'master'

Disable trigger manual job button after click

See merge request gitlab-org/gitlab!57885
parents 0425ff3d 7e7751bf
......@@ -43,6 +43,7 @@ export default {
variables: [],
key: '',
secretValue: '',
triggerBtnDisabled: false,
};
},
computed: {
......@@ -98,6 +99,11 @@ export default {
1,
);
},
trigger() {
this.triggerBtnDisabled = true;
this.triggerManualJob(this.variables);
},
},
};
</script>
......@@ -182,7 +188,9 @@ export default {
variant="info"
category="primary"
:aria-label="__('Trigger manual job')"
@click="triggerManualJob(variables)"
:disabled="triggerBtnDisabled"
data-testid="trigger-manual-job-btn"
@click="trigger"
>
{{ action.button_title }}
</gl-button>
......
---
title: Disable trigger manual job button after click
merge_request: 57885
author:
type: fixed
import { GlButton } from '@gitlab/ui';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import { createLocalVue, mount, shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex';
import Form from '~/jobs/components/manual_variables_form.vue';
const localVue = createLocalVue();
Vue.use(Vuex);
describe('Manual Variables Form', () => {
let wrapper;
let store;
const requiredProps = {
action: {
......@@ -16,16 +21,21 @@ describe('Manual Variables Form', () => {
variablesSettingsUrl: '/settings',
};
const factory = (props = {}) => {
wrapper = shallowMount(localVue.extend(Form), {
const createComponent = (props = {}, mountFn = shallowMount) => {
store = new Vuex.Store({
actions: {
triggerManualJob: jest.fn(),
},
});
wrapper = mountFn(localVue.extend(Form), {
propsData: props,
localVue,
store,
});
};
beforeEach(() => {
factory(requiredProps);
});
const findTriggerBtn = () => wrapper.find('[data-testid="trigger-manual-job-btn"]');
afterEach((done) => {
// The component has a `nextTick` callback after some events so we need
......@@ -38,66 +48,88 @@ describe('Manual Variables Form', () => {
});
});
it('renders empty form with correct placeholders', () => {
expect(wrapper.find({ ref: 'inputKey' }).attributes('placeholder')).toBe('Input variable key');
expect(wrapper.find({ ref: 'inputSecretValue' }).attributes('placeholder')).toBe(
'Input variable value',
);
});
describe('shallowMount', () => {
beforeEach(() => {
createComponent(requiredProps);
});
it('renders empty form with correct placeholders', () => {
expect(wrapper.find({ ref: 'inputKey' }).attributes('placeholder')).toBe(
'Input variable key',
);
expect(wrapper.find({ ref: 'inputSecretValue' }).attributes('placeholder')).toBe(
'Input variable value',
);
});
it('renders help text with provided link', () => {
expect(wrapper.find('p').text()).toBe(
'Specify variable values to be used in this run. The values specified in CI/CD settings will be used as default',
);
it('renders help text with provided link', () => {
expect(wrapper.find('p').text()).toBe(
'Specify variable values to be used in this run. The values specified in CI/CD settings will be used as default',
);
expect(wrapper.find('a').attributes('href')).toBe(requiredProps.variablesSettingsUrl);
});
expect(wrapper.find('a').attributes('href')).toBe(requiredProps.variablesSettingsUrl);
});
describe('when adding a new variable', () => {
it('creates a new variable when user types a new key and resets the form', (done) => {
wrapper.vm
.$nextTick()
.then(() => wrapper.find({ ref: 'inputKey' }).setValue('new key'))
.then(() => {
expect(wrapper.vm.variables.length).toBe(1);
expect(wrapper.vm.variables[0].key).toBe('new key');
expect(wrapper.find({ ref: 'inputKey' }).attributes('value')).toBe(undefined);
})
.then(done)
.catch(done.fail);
describe('when adding a new variable', () => {
it('creates a new variable when user types a new key and resets the form', (done) => {
wrapper.vm
.$nextTick()
.then(() => wrapper.find({ ref: 'inputKey' }).setValue('new key'))
.then(() => {
expect(wrapper.vm.variables.length).toBe(1);
expect(wrapper.vm.variables[0].key).toBe('new key');
expect(wrapper.find({ ref: 'inputKey' }).attributes('value')).toBe(undefined);
})
.then(done)
.catch(done.fail);
});
it('creates a new variable when user types a new value and resets the form', (done) => {
wrapper.vm
.$nextTick()
.then(() => wrapper.find({ ref: 'inputSecretValue' }).setValue('new value'))
.then(() => {
expect(wrapper.vm.variables.length).toBe(1);
expect(wrapper.vm.variables[0].secret_value).toBe('new value');
expect(wrapper.find({ ref: 'inputSecretValue' }).attributes('value')).toBe(undefined);
})
.then(done)
.catch(done.fail);
});
});
it('creates a new variable when user types a new value and resets the form', (done) => {
wrapper.vm
.$nextTick()
.then(() => wrapper.find({ ref: 'inputSecretValue' }).setValue('new value'))
.then(() => {
expect(wrapper.vm.variables.length).toBe(1);
expect(wrapper.vm.variables[0].secret_value).toBe('new value');
expect(wrapper.find({ ref: 'inputSecretValue' }).attributes('value')).toBe(undefined);
})
.then(done)
.catch(done.fail);
describe('when deleting a variable', () => {
beforeEach((done) => {
wrapper.vm.variables = [
{
key: 'new key',
secret_value: 'value',
id: '1',
},
];
wrapper.vm.$nextTick(done);
});
it('removes the variable row', () => {
wrapper.find(GlButton).vm.$emit('click');
expect(wrapper.vm.variables.length).toBe(0);
});
});
});
describe('when deleting a variable', () => {
beforeEach((done) => {
wrapper.vm.variables = [
{
key: 'new key',
secret_value: 'value',
id: '1',
},
];
wrapper.vm.$nextTick(done);
describe('mount', () => {
beforeEach(() => {
createComponent(requiredProps, mount);
});
it('removes the variable row', () => {
wrapper.find(GlButton).vm.$emit('click');
it('trigger button is disabled after trigger action', async () => {
expect(findTriggerBtn().props('disabled')).toBe(false);
await findTriggerBtn().trigger('click');
expect(wrapper.vm.variables.length).toBe(0);
expect(findTriggerBtn().props('disabled')).toBe(true);
});
});
});
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