UI: Test readonly ServiceIdentity rules (#5865)

This commit is contained in:
John Cowen 2019-06-04 17:55:10 +01:00 committed by GitHub
parent 8fe230fbac
commit 174fcb557f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 17 deletions

View File

@ -94,16 +94,15 @@ Feature: dc / acls / policies / as many / add new: Add new policy
| token | | token |
| role | | role |
------------- -------------
@ignore: Scenario: Try to edit the Service Identity using the code editor
Scenario: Click the cancel form And I click serviceIdentity on the policies.form
Then ok Then I can't fill in the policies.form with yaml
# And I click cancel on the policyForm ---
Rules: key {}
---
Where: Where:
------------- -------------
| Model | | Model |
| token | | token |
| role | | role |
------------- -------------
@ignore
Scenario: Make sure the Service Identity Rules are readonly
Then ok

View File

@ -1,8 +1,13 @@
export default function(scenario, find, fillIn, triggerKeyEvent, currentPage) { export default function(scenario, find, fillIn, triggerKeyEvent, currentPage) {
const dont = `( don't| shouldn't| can't)?`;
const fillInElement = function(page, name, value) { const fillInElement = function(page, name, value) {
const cm = document.querySelector(`textarea[name="${name}"] + .CodeMirror`); const cm = document.querySelector(`textarea[name="${name}"] + .CodeMirror`);
if (cm) { if (cm) {
cm.CodeMirror.setValue(value); if (!cm.CodeMirror.options.readOnly) {
cm.CodeMirror.setValue(value);
} else {
throw new Error(`The ${name} editor is set to readonly`);
}
return page; return page;
} else { } else {
return page.fillIn(name, value); return page.fillIn(name, value);
@ -22,16 +27,16 @@ export default function(scenario, find, fillIn, triggerKeyEvent, currentPage) {
}) })
.then( .then(
[ [
'I fill in the $property form with yaml\n$yaml', `I${dont} fill in the $property form with yaml\n$yaml`,
'I fill in $property with yaml\n$yaml', `I${dont} fill in $property with yaml\n$yaml`,
'I fill in the $property with yaml\n$yaml', `I${dont} fill in the $property with yaml\n$yaml`,
'I fill in the property form with json\n$json', `I${dont} fill in the property form with json\n$json`,
'I fill in the $property form on the $component component with yaml\n$yaml', `I${dont} fill in the $property form on the $component component with yaml\n$yaml`,
'I fill in the $property form on the $component component with json\n$json', `I${dont} fill in the $property form on the $component component with json\n$json`,
'I fill in the $property on the $component component with yaml\n$yaml', `I${dont} fill in the $property on the $component component with yaml\n$yaml`,
], ],
function(property, component, data, next) { function(negative, property, component, data, next) {
try { try {
switch (true) { switch (true) {
case typeof component === 'string': case typeof component === 'string':
@ -51,7 +56,18 @@ export default function(scenario, find, fillIn, triggerKeyEvent, currentPage) {
} }
return Object.keys(data).reduce(function(prev, item, i, arr) { return Object.keys(data).reduce(function(prev, item, i, arr) {
const name = `${obj.prefix || property}[${item}]`; const name = `${obj.prefix || property}[${item}]`;
return fillInElement(prev, name, data[item]); if (negative) {
try {
fillInElement(prev, name, data[item]);
throw new TypeError(`${item} is editable`);
} catch (e) {
if (e instanceof TypeError) {
throw e;
}
}
} else {
return fillInElement(prev, name, data[item]);
}
}, obj); }, obj);
} catch (e) { } catch (e) {
throw e; throw e;