From b7c806a061455b875d48d4f5552fb71dfab04117 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Wed, 4 Jul 2018 15:06:20 +0100 Subject: [PATCH] Start purifying page objects --- ui-v2/app/templates/dc/acls/-form.hbs | 2 +- ui-v2/tests/acceptance/dc/acls/delete.feature | 17 +++++++- .../tests/lib/page-object/createDeletable.js | 11 +++++ .../tests/lib/page-object/createSubmitable.js | 11 +++++ ui-v2/tests/pages.js | 41 +++++++++++++------ ui-v2/tests/pages/dc.js | 21 ++++++---- ui-v2/tests/pages/dc/acls/edit.js | 18 ++++---- ui-v2/tests/pages/dc/acls/index.js | 28 ++++++------- ui-v2/tests/pages/dc/intentions/edit.js | 15 ++++--- ui-v2/tests/pages/dc/intentions/index.js | 35 ++++++++-------- ui-v2/tests/pages/dc/kv/edit.js | 18 ++++---- ui-v2/tests/pages/dc/kv/index.js | 25 +++++------ ui-v2/tests/pages/dc/nodes/index.js | 21 +++++----- ui-v2/tests/pages/dc/nodes/show.js | 36 ++++++++-------- ui-v2/tests/pages/dc/services/index.js | 28 ++++++------- ui-v2/tests/pages/dc/services/show.js | 35 ++++++++-------- ui-v2/tests/pages/index.js | 12 +++--- ui-v2/tests/pages/settings.js | 11 +++-- ui-v2/tests/steps.js | 9 ++++ 19 files changed, 223 insertions(+), 171 deletions(-) create mode 100644 ui-v2/tests/lib/page-object/createDeletable.js create mode 100644 ui-v2/tests/lib/page-object/createSubmitable.js diff --git a/ui-v2/app/templates/dc/acls/-form.hbs b/ui-v2/app/templates/dc/acls/-form.hbs index 2d0ef5edf..803444e5a 100644 --- a/ui-v2/app/templates/dc/acls/-form.hbs +++ b/ui-v2/app/templates/dc/acls/-form.hbs @@ -35,7 +35,7 @@ {{# if (and (not create) (not-eq item.ID 'anonymous')) }} {{#confirmation-dialog message='Are you sure you want to delete this ACL token?'}} {{#block-slot 'action' as |confirm|}} - + {{/block-slot}} {{#block-slot 'dialog' as |execute cancel message|}}

diff --git a/ui-v2/tests/acceptance/dc/acls/delete.feature b/ui-v2/tests/acceptance/dc/acls/delete.feature index 9a59d1ec0..4842b2c71 100644 --- a/ui-v2/tests/acceptance/dc/acls/delete.feature +++ b/ui-v2/tests/acceptance/dc/acls/delete.feature @@ -1,6 +1,6 @@ @setupApplicationTest Feature: dc / acls / delete: ACL Delete - Scenario: Delete ACL + Scenario: Deleting an ACL from the ACL listing page Given 1 datacenter model with the value "datacenter" And 1 acl model from yaml --- @@ -15,3 +15,18 @@ Feature: dc / acls / delete: ACL Delete And I click delete on the acls And I click confirmDelete on the acls Then a PUT request is made to "/v1/acl/destroy/key?dc=datacenter" + Scenario: Deleting an ACL from the ACL detail page + Given 1 datacenter model with the value "datacenter" + And 1 acl model from yaml + --- + Name: something + ID: key + --- + When I visit the acl page for yaml + --- + dc: datacenter + acl: something + --- + And I click delete + And I click confirmDelete + Then a PUT request is made to "/v1/acl/destroy/something?dc=datacenter" diff --git a/ui-v2/tests/lib/page-object/createDeletable.js b/ui-v2/tests/lib/page-object/createDeletable.js new file mode 100644 index 000000000..cc3aff4c5 --- /dev/null +++ b/ui-v2/tests/lib/page-object/createDeletable.js @@ -0,0 +1,11 @@ +export default function(clickable) { + return function(obj) { + return { + ...obj, + ...{ + delete: clickable('[data-test-delete]'), + confirmDelete: clickable('button.type-delete'), + }, + }; + }; +} diff --git a/ui-v2/tests/lib/page-object/createSubmitable.js b/ui-v2/tests/lib/page-object/createSubmitable.js new file mode 100644 index 000000000..c566bd7f0 --- /dev/null +++ b/ui-v2/tests/lib/page-object/createSubmitable.js @@ -0,0 +1,11 @@ +export default function(clickable, is) { + return function(obj) { + return { + ...obj, + ...{ + submit: clickable('[type=submit]'), + submitIsEnabled: is(':not(:disabled)', '[type=submit]'), + }, + }; + }; +} diff --git a/ui-v2/tests/pages.js b/ui-v2/tests/pages.js index 99366a40c..175a4dd1c 100644 --- a/ui-v2/tests/pages.js +++ b/ui-v2/tests/pages.js @@ -1,29 +1,44 @@ +import { create, clickable, is, attribute, collection, text } from 'ember-cli-page-object'; +import { visitable } from 'consul-ui/tests/lib/page-object/visitable'; +import createDeletable from 'consul-ui/tests/lib/page-object/createDeletable'; +import createSubmitable from 'consul-ui/tests/lib/page-object/createSubmitable'; + +import page from 'consul-ui/tests/pages/components/page'; +import radiogroup from 'consul-ui/tests/lib/page-object/radiogroup'; + import index from 'consul-ui/tests/pages/index'; import dcs from 'consul-ui/tests/pages/dc'; import settings from 'consul-ui/tests/pages/settings'; +import catalogFilter from 'consul-ui/tests/pages/components/catalog-filter'; import services from 'consul-ui/tests/pages/dc/services/index'; import service from 'consul-ui/tests/pages/dc/services/show'; import nodes from 'consul-ui/tests/pages/dc/nodes/index'; import node from 'consul-ui/tests/pages/dc/nodes/show'; import kvs from 'consul-ui/tests/pages/dc/kv/index'; import kv from 'consul-ui/tests/pages/dc/kv/edit'; +import aclFilter from 'consul-ui/tests/pages/components/acl-filter'; import acls from 'consul-ui/tests/pages/dc/acls/index'; import acl from 'consul-ui/tests/pages/dc/acls/edit'; +import intentionFilter from 'consul-ui/tests/pages/components/intention-filter'; import intentions from 'consul-ui/tests/pages/dc/intentions/index'; import intention from 'consul-ui/tests/pages/dc/intentions/edit'; +const deletable = createDeletable(clickable); +const submitable = createSubmitable(clickable, is); export default { - index, - dcs, - settings, - services, - service, - nodes, - node, - kvs, - kv, - acls, - acl, - intentions, - intention, + index: create(index(visitable, collection)), + dcs: create(dcs(visitable, clickable, attribute, collection)), + services: create(services(visitable, clickable, attribute, collection, page, catalogFilter)), + service: create(service(visitable, attribute, collection, text, catalogFilter)), + nodes: create(nodes(visitable, clickable, attribute, collection, catalogFilter)), + node: create(node(visitable, deletable, clickable, attribute, collection, radiogroup)), + kvs: create(kvs(visitable, deletable, clickable, attribute, collection)), + kv: create(kv(visitable, submitable, deletable)), + acls: create(acls(visitable, deletable, clickable, attribute, collection, aclFilter)), + acl: create(acl(visitable, submitable, deletable)), + intentions: create( + intentions(visitable, deletable, clickable, attribute, collection, intentionFilter) + ), + intention: create(intention(visitable, submitable, deletable)), + settings: create(settings(visitable, submitable)), }; diff --git a/ui-v2/tests/pages/dc.js b/ui-v2/tests/pages/dc.js index ad4eeb9a3..8517a747d 100644 --- a/ui-v2/tests/pages/dc.js +++ b/ui-v2/tests/pages/dc.js @@ -1,9 +1,12 @@ -import { create, visitable, attribute, collection, clickable } from 'ember-cli-page-object'; - -export default create({ - visit: visitable('/:dc/'), - dcs: collection('[data-test-datacenter-picker]'), - showDatacenters: clickable('[data-test-datacenter-selected]'), - selectedDc: attribute('data-test-datacenter-selected', '[data-test-datacenter-selected]'), - selectedDatacenter: attribute('data-test-datacenter-selected', '[data-test-datacenter-selected]'), -}); +export default function(visitable, clickable, attribute, collection) { + return { + visit: visitable('/:dc/'), + dcs: collection('[data-test-datacenter-picker]'), + showDatacenters: clickable('[data-test-datacenter-selected]'), + selectedDc: attribute('data-test-datacenter-selected', '[data-test-datacenter-selected]'), + selectedDatacenter: attribute( + 'data-test-datacenter-selected', + '[data-test-datacenter-selected]' + ), + }; +} diff --git a/ui-v2/tests/pages/dc/acls/edit.js b/ui-v2/tests/pages/dc/acls/edit.js index 705607220..1164d4c0c 100644 --- a/ui-v2/tests/pages/dc/acls/edit.js +++ b/ui-v2/tests/pages/dc/acls/edit.js @@ -1,11 +1,7 @@ -import { create, clickable, triggerable, is } from 'ember-cli-page-object'; -import { visitable } from 'consul-ui/tests/lib/page-object/visitable'; - -export default create({ - // custom visitable - visit: visitable(['/:dc/acls/:acl', '/:dc/acls/create']), - // fillIn: fillable('input, textarea, [contenteditable]'), - name: triggerable('keypress', '[name="name"]'), - submit: clickable('[type=submit]'), - submitIsEnabled: is(':not(:disabled)', '[type=submit]'), -}); +export default function(visitable, submitable, deletable, triggerable) { + return submitable( + deletable({ + visit: visitable(['/:dc/acls/:acl', '/:dc/acls/create']), + }) + ); +} diff --git a/ui-v2/tests/pages/dc/acls/index.js b/ui-v2/tests/pages/dc/acls/index.js index 8b3c60cc5..7c567840e 100644 --- a/ui-v2/tests/pages/dc/acls/index.js +++ b/ui-v2/tests/pages/dc/acls/index.js @@ -1,14 +1,14 @@ -import { create, visitable, collection, attribute, clickable } from 'ember-cli-page-object'; - -import filter from 'consul-ui/tests/pages/components/acl-filter'; -export default create({ - visit: visitable('/:dc/acls'), - acls: collection('[data-test-tabular-row]', { - name: attribute('data-test-acl', '[data-test-acl]'), - acl: clickable('a'), - actions: clickable('label'), - delete: clickable('[data-test-delete]'), - confirmDelete: clickable('button.type-delete'), - }), - filter: filter, -}); +export default function(visitable, deletable, clickable, attribute, collection, filter) { + return { + visit: visitable('/:dc/acls'), + acls: collection( + '[data-test-tabular-row]', + deletable({ + name: attribute('data-test-acl', '[data-test-acl]'), + acl: clickable('a'), + actions: clickable('label'), + }) + ), + filter: filter, + }; +} diff --git a/ui-v2/tests/pages/dc/intentions/edit.js b/ui-v2/tests/pages/dc/intentions/edit.js index d054ff24f..5c6d94550 100644 --- a/ui-v2/tests/pages/dc/intentions/edit.js +++ b/ui-v2/tests/pages/dc/intentions/edit.js @@ -1,8 +1,7 @@ -import { create, clickable } from 'ember-cli-page-object'; -import { visitable } from 'consul-ui/tests/lib/page-object/visitable'; - -export default create({ - // custom visitable - visit: visitable(['/:dc/intentions/:intention', '/:dc/intentions/create']), - submit: clickable('[type=submit]'), -}); +export default function(visitable, submitable, deletable) { + return submitable( + deletable({ + visit: visitable(['/:dc/intentions/:intention', '/:dc/intentions/create']), + }) + ); +} diff --git a/ui-v2/tests/pages/dc/intentions/index.js b/ui-v2/tests/pages/dc/intentions/index.js index b5d2a9372..5ab14b01b 100644 --- a/ui-v2/tests/pages/dc/intentions/index.js +++ b/ui-v2/tests/pages/dc/intentions/index.js @@ -1,16 +1,19 @@ -import { create, visitable, collection, attribute, clickable } from 'ember-cli-page-object'; - -import filter from 'consul-ui/tests/pages/components/intention-filter'; -export default create({ - visit: visitable('/:dc/intentions'), - intentions: collection('[data-test-tabular-row]', { - source: attribute('data-test-intention-source', '[data-test-intention-source]'), - destination: attribute('data-test-intention-destination', '[data-test-intention-destination]'), - action: attribute('data-test-intention-action', '[data-test-intention-action]'), - intention: clickable('a'), - actions: clickable('label'), - delete: clickable('[data-test-delete]'), - confirmDelete: clickable('button.type-delete'), - }), - filter: filter, -}); +export default function(visitable, deletable, clickable, attribute, collection, filter) { + return { + visit: visitable('/:dc/intentions'), + intentions: collection( + '[data-test-tabular-row]', + deletable({ + source: attribute('data-test-intention-source', '[data-test-intention-source]'), + destination: attribute( + 'data-test-intention-destination', + '[data-test-intention-destination]' + ), + action: attribute('data-test-intention-action', '[data-test-intention-action]'), + intention: clickable('a'), + actions: clickable('label'), + }) + ), + filter: filter, + }; +} diff --git a/ui-v2/tests/pages/dc/kv/edit.js b/ui-v2/tests/pages/dc/kv/edit.js index df07d0df5..f7a019705 100644 --- a/ui-v2/tests/pages/dc/kv/edit.js +++ b/ui-v2/tests/pages/dc/kv/edit.js @@ -1,11 +1,7 @@ -import { create, clickable, is } from 'ember-cli-page-object'; -import { visitable } from 'consul-ui/tests/lib/page-object/visitable'; - -export default create({ - // custom visitable - visit: visitable(['/:dc/kv/:kv/edit', '/:dc/kv/create'], str => str), - // fillIn: fillable('input, textarea, [contenteditable]'), - // name: triggerable('keypress', '[name="additional"]'), - submit: clickable('[type=submit]'), - submitIsEnabled: is(':not(:disabled)', '[type=submit]'), -}); +export default function(visitable, submitable, deletable) { + return submitable( + deletable({ + visit: visitable(['/:dc/kv/:kv/edit', '/:dc/kv/create'], str => str), + }) + ); +} diff --git a/ui-v2/tests/pages/dc/kv/index.js b/ui-v2/tests/pages/dc/kv/index.js index 446122e6c..a0c843914 100644 --- a/ui-v2/tests/pages/dc/kv/index.js +++ b/ui-v2/tests/pages/dc/kv/index.js @@ -1,12 +1,13 @@ -import { create, visitable, collection, attribute, clickable } from 'ember-cli-page-object'; - -export default create({ - visit: visitable('/:dc/kv'), - kvs: collection('[data-test-tabular-row]', { - name: attribute('data-test-kv', '[data-test-kv]'), - kv: clickable('a'), - actions: clickable('label'), - delete: clickable('[data-test-delete]'), - confirmDelete: clickable('button.type-delete'), - }), -}); +export default function(visitable, deletable, clickable, attribute, collection) { + return { + visit: visitable('/:dc/kv'), + kvs: collection( + '[data-test-tabular-row]', + deletable({ + name: attribute('data-test-kv', '[data-test-kv]'), + kv: clickable('a'), + actions: clickable('label'), + }) + ), + }; +} diff --git a/ui-v2/tests/pages/dc/nodes/index.js b/ui-v2/tests/pages/dc/nodes/index.js index 963186306..1899e7df5 100644 --- a/ui-v2/tests/pages/dc/nodes/index.js +++ b/ui-v2/tests/pages/dc/nodes/index.js @@ -1,11 +1,10 @@ -import { create, visitable, collection, attribute, clickable } from 'ember-cli-page-object'; -import filter from 'consul-ui/tests/pages/components/catalog-filter'; - -export default create({ - visit: visitable('/:dc/nodes'), - nodes: collection('[data-test-node]', { - name: attribute('data-test-node'), - node: clickable('header a'), - }), - filter: filter, -}); +export default function(visitable, clickable, attribute, collection, filter) { + return { + visit: visitable('/:dc/nodes'), + nodes: collection('[data-test-node]', { + name: attribute('data-test-node'), + node: clickable('header a'), + }), + filter: filter, + }; +} diff --git a/ui-v2/tests/pages/dc/nodes/show.js b/ui-v2/tests/pages/dc/nodes/show.js index 298c51f54..429639768 100644 --- a/ui-v2/tests/pages/dc/nodes/show.js +++ b/ui-v2/tests/pages/dc/nodes/show.js @@ -1,18 +1,18 @@ -import { create, visitable, collection, attribute, clickable } from 'ember-cli-page-object'; - -import radiogroup from 'consul-ui/tests/lib/page-object/radiogroup'; -export default create({ - visit: visitable('/:dc/nodes/:node'), - tabs: radiogroup('tab', ['health-checks', 'services', 'round-trip-time', 'lock-sessions']), - healthchecks: collection('[data-test-node-healthcheck]', { - name: attribute('data-test-node-healthcheck'), - }), - services: collection('#services [data-test-tabular-row]', { - port: attribute('data-test-service-port', '.port'), - }), - sessions: collection('#lock-sessions [data-test-tabular-row]', { - delete: clickable('[data-test-delete]'), - confirmDelete: clickable('button.type-delete'), - TTL: attribute('data-test-session-ttl', '[data-test-session-ttl]'), - }), -}); +export default function(visitable, deletable, clickable, attribute, collection, radiogroup) { + return { + visit: visitable('/:dc/nodes/:node'), + tabs: radiogroup('tab', ['health-checks', 'services', 'round-trip-time', 'lock-sessions']), + healthchecks: collection('[data-test-node-healthcheck]', { + name: attribute('data-test-node-healthcheck'), + }), + services: collection('#services [data-test-tabular-row]', { + port: attribute('data-test-service-port', '.port'), + }), + sessions: collection( + '#lock-sessions [data-test-tabular-row]', + deletable({ + TTL: attribute('data-test-session-ttl', '[data-test-session-ttl]'), + }) + ), + }; +} diff --git a/ui-v2/tests/pages/dc/services/index.js b/ui-v2/tests/pages/dc/services/index.js index acfd554ce..d403b0b10 100644 --- a/ui-v2/tests/pages/dc/services/index.js +++ b/ui-v2/tests/pages/dc/services/index.js @@ -1,16 +1,12 @@ -import { create, visitable, collection, attribute, clickable } from 'ember-cli-page-object'; - -import page from 'consul-ui/tests/pages/components/page'; -import filter from 'consul-ui/tests/pages/components/catalog-filter'; - -export default create({ - visit: visitable('/:dc/services'), - services: collection('[data-test-service]', { - name: attribute('data-test-service'), - service: clickable('a'), - }), - dcs: collection('[data-test-datacenter-picker]'), - navigation: page.navigation, - - filter: filter, -}); +export default function(visitable, clickable, attribute, collection, page, filter) { + return { + visit: visitable('/:dc/services'), + services: collection('[data-test-service]', { + name: attribute('data-test-service'), + service: clickable('a'), + }), + dcs: collection('[data-test-datacenter-picker]'), + navigation: page.navigation, + filter: filter, + }; +} diff --git a/ui-v2/tests/pages/dc/services/show.js b/ui-v2/tests/pages/dc/services/show.js index b98a3655e..483e3a412 100644 --- a/ui-v2/tests/pages/dc/services/show.js +++ b/ui-v2/tests/pages/dc/services/show.js @@ -1,18 +1,17 @@ -import { create, visitable, collection, attribute, text } from 'ember-cli-page-object'; -import filter from 'consul-ui/tests/pages/components/catalog-filter'; - -export default create({ - visit: visitable('/:dc/services/:service'), - nodes: collection('[data-test-node]', { - name: attribute('data-test-node'), - }), - healthy: collection('[data-test-healthy] [data-test-node]', { - name: attribute('data-test-node'), - address: text('header strong'), - }), - unhealthy: collection('[data-test-unhealthy] [data-test-node]', { - name: attribute('data-test-node'), - address: text('header strong'), - }), - filter: filter, -}); +export default function(visitable, attribute, collection, text, filter) { + return { + visit: visitable('/:dc/services/:service'), + nodes: collection('[data-test-node]', { + name: attribute('data-test-node'), + }), + healthy: collection('[data-test-healthy] [data-test-node]', { + name: attribute('data-test-node'), + address: text('header strong'), + }), + unhealthy: collection('[data-test-unhealthy] [data-test-node]', { + name: attribute('data-test-node'), + address: text('header strong'), + }), + filter: filter, + }; +} diff --git a/ui-v2/tests/pages/index.js b/ui-v2/tests/pages/index.js index 28842ef3b..d61dc27bc 100644 --- a/ui-v2/tests/pages/index.js +++ b/ui-v2/tests/pages/index.js @@ -1,6 +1,6 @@ -import { create, visitable, collection } from 'ember-cli-page-object'; - -export default create({ - visit: visitable('/'), - dcs: collection('[data-test-datacenter-list]'), -}); +export default function(visitable, collection) { + return { + visit: visitable('/'), + dcs: collection('[data-test-datacenter-list]'), + }; +} diff --git a/ui-v2/tests/pages/settings.js b/ui-v2/tests/pages/settings.js index 0418b0385..6d9407880 100644 --- a/ui-v2/tests/pages/settings.js +++ b/ui-v2/tests/pages/settings.js @@ -1,6 +1,5 @@ -import { create, visitable, clickable } from 'ember-cli-page-object'; - -export default create({ - visit: visitable('/settings'), - submit: clickable('[type=submit]'), -}); +export default function(visitable, submitable) { + return submitable({ + visit: visitable('/settings'), + }); +} diff --git a/ui-v2/tests/steps.js b/ui-v2/tests/steps.js index a3d9365ab..b8d0a732f 100644 --- a/ui-v2/tests/steps.js +++ b/ui-v2/tests/steps.js @@ -85,6 +85,15 @@ export default function(assert) { .when('I click "$selector"', function(selector) { return click(selector); }) + // TODO: Probably nicer to thing of better vocab than having the 'without " rule' + .when('I click (?!")$property(?!")', function(property) { + try { + return currentPage[property](); + } catch (e) { + console.error(e); + throw new Error(`The '${property}' property on the page object doesn't exist`); + } + }) .when('I click $prop on the $component', function(prop, component) { // Collection var obj;