Commit 3f50321e authored by pburdette's avatar pburdette

Apply reviewer feedback

Use named arguments on
create component and clean
up use of vm on wrapper.
parent 48c380a1
...@@ -117,7 +117,12 @@ export default { ...@@ -117,7 +117,12 @@ export default {
<div class="table-section section-50" role="rowheader">{{ s__('CiVariables|Value') }}</div> <div class="table-section section-50" role="rowheader">{{ s__('CiVariables|Value') }}</div>
</div> </div>
<div v-for="variable in variables" :key="variable.id" class="gl-responsive-table-row"> <div
v-for="variable in variables"
:key="variable.id"
class="gl-responsive-table-row"
data-testid="ci-variable-row"
>
<div class="table-section section-50"> <div class="table-section section-50">
<div class="table-mobile-header" role="rowheader">{{ s__('Pipeline|Key') }}</div> <div class="table-mobile-header" role="rowheader">{{ s__('Pipeline|Key') }}</div>
<div class="table-mobile-content gl-mr-3"> <div class="table-mobile-content gl-mr-3">
...@@ -126,6 +131,7 @@ export default { ...@@ -126,6 +131,7 @@ export default {
v-model="variable.key" v-model="variable.key"
:placeholder="$options.i18n.keyPlaceholder" :placeholder="$options.i18n.keyPlaceholder"
class="ci-variable-body-item form-control" class="ci-variable-body-item form-control"
data-testid="ci-variable-key"
/> />
</div> </div>
</div> </div>
...@@ -138,6 +144,7 @@ export default { ...@@ -138,6 +144,7 @@ export default {
v-model="variable.secret_value" v-model="variable.secret_value"
:placeholder="$options.i18n.valuePlaceholder" :placeholder="$options.i18n.valuePlaceholder"
class="ci-variable-body-item form-control" class="ci-variable-body-item form-control"
data-testid="ci-variable-value"
/> />
</div> </div>
</div> </div>
......
...@@ -21,7 +21,7 @@ describe('Manual Variables Form', () => { ...@@ -21,7 +21,7 @@ describe('Manual Variables Form', () => {
variablesSettingsUrl: '/settings', variablesSettingsUrl: '/settings',
}; };
const createComponent = (props = {}, mountFn = shallowMount) => { const createComponent = ({ props = {}, mountFn = shallowMount } = {}) => {
store = new Vuex.Store({ store = new Vuex.Store({
actions: { actions: {
triggerManualJob: jest.fn(), triggerManualJob: jest.fn(),
...@@ -30,7 +30,7 @@ describe('Manual Variables Form', () => { ...@@ -30,7 +30,7 @@ describe('Manual Variables Form', () => {
wrapper = extendedWrapper( wrapper = extendedWrapper(
mountFn(localVue.extend(Form), { mountFn(localVue.extend(Form), {
propsData: props, propsData: { ...requiredProps, ...props },
localVue, localVue,
store, store,
}), }),
...@@ -43,6 +43,9 @@ describe('Manual Variables Form', () => { ...@@ -43,6 +43,9 @@ describe('Manual Variables Form', () => {
const findTriggerBtn = () => wrapper.findByTestId('trigger-manual-job-btn'); const findTriggerBtn = () => wrapper.findByTestId('trigger-manual-job-btn');
const findHelpText = () => wrapper.findByTestId('form-help-text'); const findHelpText = () => wrapper.findByTestId('form-help-text');
const findDeleteVarBtn = () => wrapper.findByTestId('delete-variable-btn'); const findDeleteVarBtn = () => wrapper.findByTestId('delete-variable-btn');
const findCiVariableKey = () => wrapper.findByTestId('ci-variable-key');
const findCiVariableValue = () => wrapper.findByTestId('ci-variable-value');
const findAllVariables = () => wrapper.findAllByTestId('ci-variable-row');
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -50,7 +53,7 @@ describe('Manual Variables Form', () => { ...@@ -50,7 +53,7 @@ describe('Manual Variables Form', () => {
describe('shallowMount', () => { describe('shallowMount', () => {
beforeEach(() => { beforeEach(() => {
createComponent(requiredProps); createComponent();
}); });
it('renders empty form with correct placeholders', () => { it('renders empty form with correct placeholders', () => {
...@@ -70,19 +73,25 @@ describe('Manual Variables Form', () => { ...@@ -70,19 +73,25 @@ describe('Manual Variables Form', () => {
it('creates a new variable when user types a new key and resets the form', async () => { it('creates a new variable when user types a new key and resets the form', async () => {
await findInputKey().setValue('new key'); await findInputKey().setValue('new key');
expect(wrapper.vm.variables).toHaveLength(1); expect(findAllVariables()).toHaveLength(1);
expect(wrapper.vm.variables[0].key).toBe('new key'); expect(findCiVariableKey().element.value).toBe('new key');
expect(findInputKey().attributes('value')).toBe(undefined); expect(findInputKey().attributes('value')).toBe(undefined);
}); });
it('creates a new variable when user types a new value and resets the form', async () => { it('creates a new variable when user types a new value and resets the form', async () => {
await findInputValue().setValue('new value'); await findInputValue().setValue('new value');
expect(wrapper.vm.variables).toHaveLength(1); expect(findAllVariables()).toHaveLength(1);
expect(wrapper.vm.variables[0].secret_value).toBe('new value'); expect(findCiVariableValue().element.value).toBe('new value');
expect(findInputValue().attributes('value')).toBe(undefined); expect(findInputValue().attributes('value')).toBe(undefined);
}); });
}); });
});
describe('mount', () => {
beforeEach(() => {
createComponent({ mountFn: mount });
});
describe('when deleting a variable', () => { describe('when deleting a variable', () => {
it('removes the variable row', async () => { it('removes the variable row', async () => {
...@@ -96,17 +105,15 @@ describe('Manual Variables Form', () => { ...@@ -96,17 +105,15 @@ describe('Manual Variables Form', () => {
], ],
}); });
findDeleteVarBtn().vm.$emit('click'); findDeleteVarBtn().trigger('click');
expect(wrapper.vm.variables).toHaveLength(0); await wrapper.vm.$nextTick();
});
expect(findAllVariables()).toHaveLength(0);
}); });
}); });
describe('mount', () => {
it('trigger button is disabled after trigger action', async () => { it('trigger button is disabled after trigger action', async () => {
createComponent(requiredProps, mount);
expect(findTriggerBtn().props('disabled')).toBe(false); expect(findTriggerBtn().props('disabled')).toBe(false);
await findTriggerBtn().trigger('click'); await findTriggerBtn().trigger('click');
......
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