diff options
author | mfluharty <mfluharty@gitlab.com> | 2019-06-05 14:29:29 +0100 |
---|---|---|
committer | mfluharty <mfluharty@gitlab.com> | 2019-06-06 15:46:46 +0100 |
commit | 964b1f65d09ef3dd9d7d9a2be33d846c7fbda21c (patch) | |
tree | 1f988aa6a7b0718204003500185c92d90a498f37 /spec | |
parent | c3130068e89c1a02f0b9cd4c3e25a33bc91b59df (diff) | |
download | gitlab-ce-964b1f65d09ef3dd9d7d9a2be33d846c7fbda21c.tar.gz |
Add frontend specs
Test that a regex is provided
Test that it is the expected regex
Test length of variable
Test special character set
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/ci_variable_list/ajax_variable_list_spec.js | 8 | ||||
-rw-r--r-- | spec/javascripts/ci_variable_list/ci_variable_list_spec.js | 59 |
2 files changed, 67 insertions, 0 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 2839922fbd3..e6a969bd855 100644 --- a/spec/javascripts/ci_variable_list/ajax_variable_list_spec.js +++ b/spec/javascripts/ci_variable_list/ajax_variable_list_spec.js @@ -32,6 +32,7 @@ describe('AjaxFormVariableList', () => { saveButton, errorBox, saveEndpoint: container.dataset.saveEndpoint, + maskableRegex: container.dataset.maskableRegex, }); spyOn(ajaxVariableList, 'updateRowsWithPersistedVariables').and.callThrough(); @@ -220,4 +221,11 @@ describe('AjaxFormVariableList', () => { expect(row.dataset.isPersisted).toEqual('true'); }); }); + + describe('maskableRegex', () => { + it('takes in the regex provided by the data attribute', () => { + expect(container.dataset.maskableRegex).toBe('^[a-zA-Z0-9_+=/-]{8,}$'); + expect(ajaxVariableList.maskableRegex).toBe(container.dataset.maskableRegex); + }); + }); }); 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 394e60fc22c..1b2b186234e 100644 --- a/spec/javascripts/ci_variable_list/ci_variable_list_spec.js +++ b/spec/javascripts/ci_variable_list/ci_variable_list_spec.js @@ -150,6 +150,65 @@ describe('VariableList', () => { .then(done) .catch(done.fail); }); + + describe('validateMaskability', () => { + let $row; + + const maskingErrorElement = '.js-row:nth-child(2) .masking-validation-error'; + + beforeEach(() => { + $row = $wrapper.find('.js-row:last-child'); + $row.find('.js-ci-variable-input-key').val('variable-key'); + }); + + it('has a regex provided via a data attribute', () => { + expect($wrapper.attr('data-maskable-regex')).toBe('^[a-zA-Z0-9_+=/-]{8,}$'); + }); + + it('allows values that are 8 characters long', done => { + $row.find('.js-ci-variable-input-value').val('looooong'); + + getSetTimeoutPromise() + .then(() => { + expect($wrapper.find(maskingErrorElement)).toHaveClass('hide'); + }) + .then(done) + .catch(done.fail); + }); + + it('rejects values that are shorter than 8 characters', done => { + $row.find('.js-ci-variable-input-value').val('short'); + + getSetTimeoutPromise() + .then(() => { + expect($wrapper.find(maskingErrorElement)).toBeVisible(); + }) + .then(done) + .catch(done.fail); + }); + + it('allows values with base 64 characters', done => { + $row.find('.js-ci-variable-input-value').val('abcABC123_+=/-'); + + getSetTimeoutPromise() + .then(() => { + expect($wrapper.find(maskingErrorElement)).toHaveClass('hide'); + }) + .then(done) + .catch(done.fail); + }); + + it('rejects values with other special characters', done => { + $row.find('.js-ci-variable-input-value').val('1234567$'); + + getSetTimeoutPromise() + .then(() => { + expect($wrapper.find(maskingErrorElement)).toBeVisible(); + }) + .then(done) + .catch(done.fail); + }); + }); }); describe('toggleEnableRow method', () => { |