diff options
Diffstat (limited to 'spec/javascripts/ci_variable_list')
3 files changed, 62 insertions, 34 deletions
diff --git a/spec/javascripts/ci_variable_list/ajax_variable_list_spec.js b/spec/javascripts/ci_variable_list/ajax_variable_list_spec.js index ee457a9c48c..4f8701bae01 100644 --- a/spec/javascripts/ci_variable_list/ajax_variable_list_spec.js +++ b/spec/javascripts/ci_variable_list/ajax_variable_list_spec.js @@ -43,7 +43,7 @@ describe('AjaxFormVariableList', () => { }); describe('onSaveClicked', () => { - it('shows loading spinner while waiting for the request', (done) => { + it('shows loading spinner while waiting for the request', done => { const loadingIcon = saveButton.querySelector('.js-secret-variables-save-loading-icon'); mock.onPatch(VARIABLE_PATCH_ENDPOINT).reply(() => { @@ -54,7 +54,8 @@ describe('AjaxFormVariableList', () => { expect(loadingIcon.classList.contains(HIDE_CLASS)).toEqual(true); - ajaxVariableList.onSaveClicked() + ajaxVariableList + .onSaveClicked() .then(() => { expect(loadingIcon.classList.contains(HIDE_CLASS)).toEqual(true); }) @@ -62,27 +63,30 @@ describe('AjaxFormVariableList', () => { .catch(done.fail); }); - it('calls `updateRowsWithPersistedVariables` with the persisted variables', (done) => { + it('calls `updateRowsWithPersistedVariables` with the persisted variables', done => { const variablesResponse = [{ id: 1, key: 'foo', value: 'bar' }]; mock.onPatch(VARIABLE_PATCH_ENDPOINT).reply(200, { variables: variablesResponse, }); - ajaxVariableList.onSaveClicked() + ajaxVariableList + .onSaveClicked() .then(() => { - expect(ajaxVariableList.updateRowsWithPersistedVariables) - .toHaveBeenCalledWith(variablesResponse); + expect(ajaxVariableList.updateRowsWithPersistedVariables).toHaveBeenCalledWith( + variablesResponse, + ); }) .then(done) .catch(done.fail); }); - it('hides any previous error box', (done) => { + it('hides any previous error box', done => { mock.onPatch(VARIABLE_PATCH_ENDPOINT).reply(200); expect(errorBox.classList.contains(HIDE_CLASS)).toEqual(true); - ajaxVariableList.onSaveClicked() + ajaxVariableList + .onSaveClicked() .then(() => { expect(errorBox.classList.contains(HIDE_CLASS)).toEqual(true); }) @@ -90,14 +94,15 @@ describe('AjaxFormVariableList', () => { .catch(done.fail); }); - it('disables remove buttons while waiting for the request', (done) => { + it('disables remove buttons while waiting for the request', done => { mock.onPatch(VARIABLE_PATCH_ENDPOINT).reply(() => { expect(ajaxVariableList.variableList.toggleEnableRow).toHaveBeenCalledWith(false); return [200, {}]; }); - ajaxVariableList.onSaveClicked() + ajaxVariableList + .onSaveClicked() .then(() => { expect(ajaxVariableList.variableList.toggleEnableRow).toHaveBeenCalledWith(true); }) @@ -105,7 +110,7 @@ describe('AjaxFormVariableList', () => { .catch(done.fail); }); - it('hides secret values', (done) => { + it('hides secret values', done => { mock.onPatch(VARIABLE_PATCH_ENDPOINT).reply(200, {}); const row = container.querySelector('.js-row:first-child'); @@ -118,7 +123,8 @@ describe('AjaxFormVariableList', () => { expect(valuePlaceholder.classList.contains(HIDE_CLASS)).toBe(true); expect(valueInput.classList.contains(HIDE_CLASS)).toBe(false); - ajaxVariableList.onSaveClicked() + ajaxVariableList + .onSaveClicked() .then(() => { expect(valuePlaceholder.classList.contains(HIDE_CLASS)).toBe(false); expect(valueInput.classList.contains(HIDE_CLASS)).toBe(true); @@ -127,29 +133,31 @@ describe('AjaxFormVariableList', () => { .catch(done.fail); }); - it('shows error box with validation errors', (done) => { + it('shows error box with validation errors', done => { const validationError = 'some validation error'; - mock.onPatch(VARIABLE_PATCH_ENDPOINT).reply(400, [ - validationError, - ]); + mock.onPatch(VARIABLE_PATCH_ENDPOINT).reply(400, [validationError]); expect(errorBox.classList.contains(HIDE_CLASS)).toEqual(true); - ajaxVariableList.onSaveClicked() + ajaxVariableList + .onSaveClicked() .then(() => { expect(errorBox.classList.contains(HIDE_CLASS)).toEqual(false); - expect(errorBox.textContent.trim().replace(/\n+\s+/m, ' ')).toEqual(`Validation failed ${validationError}`); + expect(errorBox.textContent.trim().replace(/\n+\s+/m, ' ')).toEqual( + `Validation failed ${validationError}`, + ); }) .then(done) .catch(done.fail); }); - it('shows flash message when request fails', (done) => { + it('shows flash message when request fails', done => { mock.onPatch(VARIABLE_PATCH_ENDPOINT).reply(500); expect(errorBox.classList.contains(HIDE_CLASS)).toEqual(true); - ajaxVariableList.onSaveClicked() + ajaxVariableList + .onSaveClicked() .then(() => { expect(errorBox.classList.contains(HIDE_CLASS)).toEqual(true); }) @@ -200,11 +208,13 @@ describe('AjaxFormVariableList', () => { expect(idInput.value).toEqual(''); - ajaxVariableList.updateRowsWithPersistedVariables([{ - id: 3, - key: 'foo', - value: 'bar', - }]); + ajaxVariableList.updateRowsWithPersistedVariables([ + { + id: 3, + key: 'foo', + value: 'bar', + }, + ]); expect(idInput.value).toEqual('3'); expect(row.dataset.isPersisted).toEqual('true'); diff --git a/spec/javascripts/ci_variable_list/ci_variable_list_spec.js b/spec/javascripts/ci_variable_list/ci_variable_list_spec.js index 2fa50975f0f..30b15011def 100644 --- a/spec/javascripts/ci_variable_list/ci_variable_list_spec.js +++ b/spec/javascripts/ci_variable_list/ci_variable_list_spec.js @@ -33,7 +33,8 @@ describe('VariableList', () => { it('should add another row when editing the last rows key input', () => { const $row = $wrapper.find('.js-row'); - $row.find('.js-ci-variable-input-key') + $row + .find('.js-ci-variable-input-key') .val('foo') .trigger('input'); @@ -41,12 +42,14 @@ describe('VariableList', () => { // Check for the correct default in the new row const $keyInput = $wrapper.find('.js-row:last-child').find('.js-ci-variable-input-key'); + expect($keyInput.val()).toBe(''); }); it('should add another row when editing the last rows value textarea', () => { const $row = $wrapper.find('.js-row'); - $row.find('.js-ci-variable-input-value') + $row + .find('.js-ci-variable-input-value') .val('foo') .trigger('input'); @@ -54,18 +57,21 @@ describe('VariableList', () => { // Check for the correct default in the new row const $valueInput = $wrapper.find('.js-row:last-child').find('.js-ci-variable-input-key'); + expect($valueInput.val()).toBe(''); }); it('should remove empty row after blurring', () => { const $row = $wrapper.find('.js-row'); - $row.find('.js-ci-variable-input-key') + $row + .find('.js-ci-variable-input-key') .val('foo') .trigger('input'); expect($wrapper.find('.js-row').length).toBe(2); - $row.find('.js-ci-variable-input-key') + $row + .find('.js-ci-variable-input-key') .val('') .trigger('input') .trigger('blur'); @@ -119,7 +125,7 @@ describe('VariableList', () => { variableList.init(); }); - it('should add another row when editing the last rows protected checkbox', (done) => { + it('should add another row when editing the last rows protected checkbox', done => { const $row = $wrapper.find('.js-row:last-child'); $row.find('.ci-variable-protected-item .js-project-feature-toggle').click(); @@ -128,7 +134,10 @@ describe('VariableList', () => { expect($wrapper.find('.js-row').length).toBe(2); // Check for the correct default in the new row - const $protectedInput = $wrapper.find('.js-row:last-child').find('.js-ci-variable-input-protected'); + const $protectedInput = $wrapper + .find('.js-row:last-child') + .find('.js-ci-variable-input-protected'); + expect($protectedInput.val()).toBe('false'); }) .then(done) @@ -166,6 +175,7 @@ describe('VariableList', () => { it('should enable all remove buttons', () => { variableList.toggleEnableRow(false); + expect($wrapper.find('.js-row-remove-button[disabled]').length).toBe(3); variableList.toggleEnableRow(true); @@ -175,6 +185,7 @@ describe('VariableList', () => { it('should enable all key inputs', () => { variableList.toggleEnableRow(false); + expect($wrapper.find('.js-ci-variable-input-key[disabled]').length).toBe(3); variableList.toggleEnableRow(true); @@ -200,7 +211,8 @@ describe('VariableList', () => { const $inputValue = $row.find('.js-ci-variable-input-value'); const $placeholder = $row.find('.js-secret-value-placeholder'); - $row.find('.js-ci-variable-input-value') + $row + .find('.js-ci-variable-input-value') .val('foo') .trigger('input'); diff --git a/spec/javascripts/ci_variable_list/native_form_variable_list_spec.js b/spec/javascripts/ci_variable_list/native_form_variable_list_spec.js index 94a0c999d66..997d0d54d79 100644 --- a/spec/javascripts/ci_variable_list/native_form_variable_list_spec.js +++ b/spec/javascripts/ci_variable_list/native_form_variable_list_spec.js @@ -19,8 +19,14 @@ describe('NativeFormVariableList', () => { describe('onFormSubmit', () => { it('should clear out the `name` attribute on the inputs for the last empty row on form submission (avoid BE validation)', () => { const $row = $wrapper.find('.js-row'); - expect($row.find('.js-ci-variable-input-key').attr('name')).toBe('schedule[variables_attributes][][key]'); - expect($row.find('.js-ci-variable-input-value').attr('name')).toBe('schedule[variables_attributes][][secret_value]'); + + expect($row.find('.js-ci-variable-input-key').attr('name')).toBe( + 'schedule[variables_attributes][][key]', + ); + + expect($row.find('.js-ci-variable-input-value').attr('name')).toBe( + 'schedule[variables_attributes][][secret_value]', + ); $wrapper.closest('form').trigger('trigger-submit'); |