ui: Add sorting to ACLs tokens with tests (#8359)

* Add sorting to ACLs tokens with tests

* Create token comparator and implement in template

* Upgrade @hashicorp/consul-api-double to 3.1.6

* Add navigation test to acls tokens
This commit is contained in:
Kenia 2020-07-29 09:41:40 -04:00 committed by hashicorp-ci
parent 53b30dda4d
commit 2179bb0dec
17 changed files with 134 additions and 35 deletions

View File

@ -10,7 +10,7 @@
</dd>
</dl>
{{/if}}
<a href={{href-to 'dc.acls.tokens.edit' item.AccessorID}}>{{substr item.AccessorID -8}}</a>
<a data-test-token={{item.AccessorID}} href={{href-to 'dc.acls.tokens.edit' item.AccessorID}}>{{substr item.AccessorID -8}}</a>
</BlockSlot>
<BlockSlot @name="details">
<dl>

View File

@ -1,5 +1,5 @@
export default (collection, clickable, attribute, text, actions) => () => {
return collection('.consul-token-list li:not(:first-child)', {
return collection('.consul-token-list [data-test-list-row]', {
id: attribute('data-test-token', '[data-test-token]'),
description: text('[data-test-description]'),
policy: text('[data-test-policy].policy', { multiple: true }),

View File

@ -9,25 +9,26 @@
@clientSizeChange={{action "clientSizeChange"}}
>
<li></li>
{{~#each _cells as |cell|~}}
<li
onclick={{action 'click'}} style={{{cell.style}}}
class={{if
(compute (action (or linkable (noop)) cell.item))
'linkable'
{{~#each _cells as |cell|~}}
<li
data-test-list-row
onclick={{action 'click'}} style={{{cell.style}}}
class={{if
(compute (action (or linkable (noop)) cell.item))
'linkable'
}}
>
<YieldSlot @name="header"><div>{{yield cell.item cell.index}}</div></YieldSlot>
<YieldSlot @name="details"><div>{{yield cell.item cell.index}}</div></YieldSlot>
<YieldSlot @name="actions"
@params={{
block-params (component 'more-popover-menu' expanded=(if (eq checked cell.index) true false) onchange=(action "change" cell.index))
}}
>
<YieldSlot @name="header"><div>{{yield cell.item cell.index}}</div></YieldSlot>
<YieldSlot @name="details"><div>{{yield cell.item cell.index}}</div></YieldSlot>
<YieldSlot @name="actions"
@params={{
block-params (component 'more-popover-menu' expanded=(if (eq checked cell.index) true false) onchange=(action "change" cell.index))
}}
>
<div>
{{yield cell.item cell.index}}
</div>
</YieldSlot>
</li>
{{~/each~}}
<div>
{{yield cell.item cell.index}}
</div>
</YieldSlot>
</li>
{{~/each~}}
</EmberNativeScrollable>

View File

@ -1,6 +1,7 @@
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
sortBy: 'sort',
search: {
as: 'filter',
replace: true,

View File

@ -1,6 +1,7 @@
import service from 'consul-ui/sort/comparators/service';
import check from 'consul-ui/sort/comparators/check';
import intention from 'consul-ui/sort/comparators/intention';
import token from 'consul-ui/sort/comparators/token';
export function initialize(container) {
// Service-less injection using private properties at a per-project level
@ -9,6 +10,7 @@ export function initialize(container) {
service: service(),
check: check(),
intention: intention(),
token: token(),
};
Sort.reopen({
comparator: function(type) {

View File

@ -7,6 +7,7 @@ export default Route.extend(WithTokenActions, {
repo: service('repository/token'),
settings: service('settings'),
queryParams: {
sortBy: 'sort',
search: {
as: 'filter',
replace: true,

View File

@ -0,0 +1,3 @@
export default () => key => {
return key;
};

View File

@ -1,5 +1,5 @@
%notice {
margin-bottom: 1em;
margin: 1em 0;
}
%notice-success::before {
@extend %with-check-circle-fill-color-icon;

View File

@ -3,6 +3,14 @@
{{else}}
{{title 'Access Controls'}}
{{/if}}
{{#let (selectable-key-values
(array "CreateTime:desc" "Newest to oldest")
(array "CreateTime:asc" "Oldest to newest")
selected=sortBy
)
as |sort|
}}
<AppView
@class="token list"
@loading={{isLoading}}
@ -31,20 +39,28 @@
<BlockSlot @name="actions">
<a data-test-create href="{{href-to 'dc.acls.tokens.create'}}" class="type-create">Create</a>
</BlockSlot>
<BlockSlot @name="content">
{{#if (gt items.length 0) }}
<BlockSlot @name="toolbar">
{{#if (gt items.length 0)}}
<SearchBar
data-test-intention-filter="true"
@value={{search}}
@onsearch={{action (mut search) value="target.value"}}
@secondary="sort"
@selected={{sort.selected}}
@options={{sort.items}}
@onchange={{action (mut sortBy) value='target.value'}}
/>
{{/if}}
{{/if}}
</BlockSlot>
<BlockSlot @name="content">
{{#if (token/is-legacy items)}}
<p data-test-notification-update class="notice info"><strong>Update.</strong> We have upgraded our ACL System to allow the creation of reusable policies that can be applied to tokens. Read more about the changes and how to upgrade legacy tokens in our <a href="{{env 'CONSUL_DOCS_URL'}}/guides/acl-migrate-tokens.html" target="_blank" rel="noopener noreferrer">documentation</a>.</p>
{{/if}}
<ChangeableSet @dispatcher={{searchable 'token' items}} @terms={{search}}>
{{#let (sort-by (comparator 'token' sort.selected.key) items) as |sorted|}}
<ChangeableSet @dispatcher={{searchable 'token' sorted}} @terms={{search}}>
<BlockSlot @name="set" as |filtered|>
<ConsulTokenList
@items={{sort-by "CreateTime:desc" filtered}}
@items={{filtered}}
@token={{token}}
@onuse={{action send 'use'}}
@ondelete={{action send 'delete'}}
@ -75,5 +91,7 @@
</EmptyState>
</BlockSlot>
</ChangeableSet>
{{/let}}
</BlockSlot>
</AppView>
{{/let}}

View File

@ -0,0 +1,15 @@
@setupApplicationTest
Feature: dc / tokens / navigation
Scenario: Clicking a token in the listing and back again
Given 1 datacenter model with the value "dc-1"
And 3 token models
When I visit the tokens page for yaml
---
dc: dc-1
---
Then the url should be /dc-1/acls/tokens
And the title should be "Tokens - Consul"
Then I see 3 token models
When I click token on the tokens
And I click "[data-test-back]"
Then the url should be /dc-1/acls/tokens

View File

@ -0,0 +1,39 @@
@setupApplicationTest
Feature: dc / acls / tokens / sorting
Scenario: Sorting Tokens
Given 1 datacenter model with the value "dc-1"
And 4 token models from yaml
---
- AccessorID: "00000000-0000-0000-0000-000000000001"
CreateTime: "2018-09-15T11:58:09.197Z"
- AccessorID: "00000000-0000-0000-0000-000000000002"
CreateTime: "2020-09-15T11:58:09.197Z"
- AccessorID: "00000000-0000-0000-0000-000000000003"
CreateTime: "2007-09-15T11:58:09.197Z"
- AccessorID: "00000000-0000-0000-0000-000000000004"
CreateTime: "2011-09-15T11:58:09.197Z"
---
When I visit the tokens page for yaml
---
dc: dc-1
---
Then the url should be /dc-1/acls/tokens
Then I see 4 token models
When I click selected on the sort
When I click options.1.button on the sort
Then I see id on the tokens vertically like yaml
---
- "00000000-0000-0000-0000-000000000003"
- "00000000-0000-0000-0000-000000000004"
- "00000000-0000-0000-0000-000000000001"
- "00000000-0000-0000-0000-000000000002"
---
When I click selected on the sort
When I click options.0.button on the sort
Then I see id on the tokens vertically like yaml
---
- "00000000-0000-0000-0000-000000000002"
- "00000000-0000-0000-0000-000000000001"
- "00000000-0000-0000-0000-000000000004"
- "00000000-0000-0000-0000-000000000003"
---

View File

@ -46,8 +46,7 @@ Feature: page-navigation
| node | nodes | /dc-1/nodes/node-0/health-checks | /v1/session/node/node-0?dc=dc-1&ns=@namespace | /dc-1/nodes |
| kv | kvs | /dc-1/kv/0-key-value/edit | /v1/session/info/ee52203d-989f-4f7a-ab5a-2bef004164ca?dc=dc-1&ns=@namespace | /dc-1/kv |
# | acl | acls | /dc-1/acls/anonymous | /v1/acl/info/anonymous?dc=dc-1 | /dc-1/acls |
# These Endpoints will be datacenters due to the datacenters checkbox selectors
| token | tokens | /dc-1/acls/tokens/ee52203d-989f-4f7a-ab5a-2bef004164ca | /v1/catalog/datacenters | /dc-1/acls/tokens |
# These Endpoints will be datacenters due to the datacenters checkbox selectors | /dc-1/acls/tokens |
| policy | policies | /dc-1/acls/policies/ee52203d-989f-4f7a-ab5a-2bef004164ca | /v1/catalog/datacenters | /dc-1/acls/policies |
# | token | tokens | /dc-1/acls/tokens/00000000-0000-0000-0000-000000000000 | /v1/acl/token/00000000-0000-0000-0000-000000000000?dc=dc-1 | /dc-1/acls/tokens |
# | policy | policies | /dc-1/acls/policies/ee52203d-989f-4f7a-ab5a-2bef004164ca | /v1/acl/policy/ee52203d-989f-4f7a-ab5a-2bef004164ca?dc=dc-1 | /dc-1/acls/policies |

View File

@ -0,0 +1,10 @@
import steps from '../../../steps';
// step definitions that are shared between features should be moved to the
// tests/acceptance/steps/steps.js file
export default function(assert) {
return steps(assert).then('I should find a file', function() {
assert.ok(true, this.step);
});
}

View File

@ -0,0 +1,10 @@
import steps from '../../../steps';
// step definitions that are shared between features should be moved to the
// tests/acceptance/steps/steps.js file
export default function(assert) {
return steps(assert).then('I should find a file', function() {
assert.ok(true, this.step);
});
}

View File

@ -164,7 +164,7 @@ export default {
roles: create(roles(visitable, creatable, consulRoleList, freetextFilter)),
// TODO: This needs a policyList
role: create(role(visitable, submitable, deletable, cancelable, policySelector, tokenList)),
tokens: create(tokens(visitable, creatable, text, consulTokenList, freetextFilter)),
tokens: create(tokens(visitable, creatable, text, consulTokenList, popoverSelect)),
token: create(
token(visitable, submitable, deletable, cancelable, clickable, policySelector, roleSelector)
),

View File

@ -1,9 +1,9 @@
export default function(visitable, creatable, text, tokens, filter) {
export default function(visitable, creatable, text, tokens, popoverSelect) {
return {
visit: visitable('/:dc/acls/tokens'),
update: text('[data-test-notification-update]'),
tokens: tokens(),
filter: filter(),
sort: popoverSelect(),
...creatable(),
};
}

View File

@ -1223,9 +1223,9 @@
js-yaml "^3.13.1"
"@hashicorp/consul-api-double@^3.0.0":
version "3.1.3"
resolved "https://registry.yarnpkg.com/@hashicorp/consul-api-double/-/consul-api-double-3.1.3.tgz#62f8780c8513e9b37f29302543c29143b4024141"
integrity sha512-IZ90RK8g4/QPxQpRLnatwpBQh9Z3kQJjOGiUVz+CrSlXg4KRLhQCFFz/gI2vmhAXRACyTxIWuydPV6BcN4ptZA==
version "3.1.6"
resolved "https://registry.yarnpkg.com/@hashicorp/consul-api-double/-/consul-api-double-3.1.6.tgz#46095438b6989a12cab382a88fdb7b227d834794"
integrity sha512-mRH7X7k1zSu/Aq+rs5VoJYrIhD3pO57d+j98dicfs+3KaMO1mQYFYKgyugY/g0kY9FQH3+vySeZ0W5nQs45V1Q==
"@hashicorp/ember-cli-api-double@^3.1.0":
version "3.1.0"