Commit 964b1f65 authored by mfluharty's avatar mfluharty

Add frontend specs

Test that a regex is provided
Test that it is the expected regex
Test length of variable
Test special character set
parent c3130068
...@@ -32,6 +32,7 @@ describe('AjaxFormVariableList', () => { ...@@ -32,6 +32,7 @@ describe('AjaxFormVariableList', () => {
saveButton, saveButton,
errorBox, errorBox,
saveEndpoint: container.dataset.saveEndpoint, saveEndpoint: container.dataset.saveEndpoint,
maskableRegex: container.dataset.maskableRegex,
}); });
spyOn(ajaxVariableList, 'updateRowsWithPersistedVariables').and.callThrough(); spyOn(ajaxVariableList, 'updateRowsWithPersistedVariables').and.callThrough();
...@@ -220,4 +221,11 @@ describe('AjaxFormVariableList', () => { ...@@ -220,4 +221,11 @@ describe('AjaxFormVariableList', () => {
expect(row.dataset.isPersisted).toEqual('true'); 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);
});
});
}); });
...@@ -150,6 +150,65 @@ describe('VariableList', () => { ...@@ -150,6 +150,65 @@ describe('VariableList', () => {
.then(done) .then(done)
.catch(done.fail); .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', () => { describe('toggleEnableRow method', () => {
......
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