Start purifying page objects

This commit is contained in:
John Cowen 2018-07-04 15:06:20 +01:00
parent 75cb5f695e
commit b7c806a061
19 changed files with 223 additions and 171 deletions

View File

@ -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|}}
<button type="button" class="type-delete" {{action confirm 'delete' item parent}}>Delete</button>
<button type="button" data-test-delete class="type-delete" {{action confirm 'delete' item parent}}>Delete</button>
{{/block-slot}}
{{#block-slot 'dialog' as |execute cancel message|}}
<p>

View File

@ -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"

View File

@ -0,0 +1,11 @@
export default function(clickable) {
return function(obj) {
return {
...obj,
...{
delete: clickable('[data-test-delete]'),
confirmDelete: clickable('button.type-delete'),
},
};
};
}

View File

@ -0,0 +1,11 @@
export default function(clickable, is) {
return function(obj) {
return {
...obj,
...{
submit: clickable('[type=submit]'),
submitIsEnabled: is(':not(:disabled)', '[type=submit]'),
},
};
};
}

View File

@ -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)),
};

View File

@ -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]'
),
};
}

View File

@ -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']),
})
);
}

View File

@ -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,
};
}

View File

@ -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']),
})
);
}

View File

@ -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,
};
}

View File

@ -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),
})
);
}

View File

@ -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'),
})
),
};
}

View File

@ -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,
};
}

View File

@ -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]'),
})
),
};
}

View File

@ -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,
};
}

View File

@ -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,
};
}

View File

@ -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]'),
};
}

View File

@ -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'),
});
}

View File

@ -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;