From e48167d9312c0c4aef83fe9bc0926db8faa39489 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Tue, 4 Jun 2019 17:55:10 +0100 Subject: [PATCH] UI: Test readonly ServiceIdentity rules (#5865) --- .../dc/acls/policies/as-many/add-new.feature | 13 ++++--- ui-v2/tests/steps/interactions/form.js | 36 +++++++++++++------ 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/ui-v2/tests/acceptance/dc/acls/policies/as-many/add-new.feature b/ui-v2/tests/acceptance/dc/acls/policies/as-many/add-new.feature index 73f60a771..6a5df30e2 100644 --- a/ui-v2/tests/acceptance/dc/acls/policies/as-many/add-new.feature +++ b/ui-v2/tests/acceptance/dc/acls/policies/as-many/add-new.feature @@ -94,16 +94,15 @@ Feature: dc / acls / policies / as many / add new: Add new policy | token | | role | ------------- -@ignore: - Scenario: Click the cancel form - Then ok - # And I click cancel on the policyForm + Scenario: Try to edit the Service Identity using the code editor + And I click serviceIdentity on the policies.form + Then I can't fill in the policies.form with yaml + --- + Rules: key {} + --- Where: ------------- | Model | | token | | role | ------------- -@ignore - Scenario: Make sure the Service Identity Rules are readonly - Then ok diff --git a/ui-v2/tests/steps/interactions/form.js b/ui-v2/tests/steps/interactions/form.js index 60d91b8fa..8b9708d35 100644 --- a/ui-v2/tests/steps/interactions/form.js +++ b/ui-v2/tests/steps/interactions/form.js @@ -1,8 +1,13 @@ export default function(scenario, find, fillIn, triggerKeyEvent, currentPage) { + const dont = `( don't| shouldn't| can't)?`; const fillInElement = function(page, name, value) { const cm = document.querySelector(`textarea[name="${name}"] + .CodeMirror`); 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; } else { return page.fillIn(name, value); @@ -22,16 +27,16 @@ export default function(scenario, find, fillIn, triggerKeyEvent, currentPage) { }) .then( [ - 'I fill in the $property form with yaml\n$yaml', - 'I fill in $property with yaml\n$yaml', - 'I 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 yaml\n$yaml`, + `I${dont} fill in $property with yaml\n$yaml`, + `I${dont} fill in the $property with yaml\n$yaml`, + `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 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 form on the $component component with yaml\n$yaml`, + `I${dont} fill in the $property form on the $component component with json\n$json`, + `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 { switch (true) { 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) { 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); } catch (e) { throw e;