From 964b1f65d09ef3dd9d7d9a2be33d846c7fbda21c Mon Sep 17 00:00:00 2001 From: mfluharty Date: Wed, 5 Jun 2019 14:29:29 +0100 Subject: Add frontend specs Test that a regex is provided Test that it is the expected regex Test length of variable Test special character set --- .../ci_variable_list/ajax_variable_list_spec.js | 8 +++ .../ci_variable_list/ci_variable_list_spec.js | 59 ++++++++++++++++++++++ 2 files changed, 67 insertions(+) (limited to 'spec') 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', () => { -- cgit v1.2.1