Skip to content

Commit

Permalink
Fix up some existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
John Cowen committed Nov 19, 2019
1 parent b76e01b commit 40e528f
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 13 deletions.
4 changes: 3 additions & 1 deletion ui-v2/app/components/toggle-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export default Component.extend({
dom: service('dom'),
// TODO(octane): Remove when we can move to glimmer components
// so we aren't using ember-test-selectors
supportsDataTestProperties: true,
// supportsDataTestProperties: true,
// the above doesn't seem to do anything so still need to find a way
// to pass through data-test-properties
tagName: '',
// TODO: reserved for the moment but we don't need it yet
onblur: null,
Expand Down
16 changes: 9 additions & 7 deletions ui-v2/app/templates/components/hashicorp-consul.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
{{#if dc}}
<ul>
{{#if (env 'CONSUL_NSPACES_ENABLED')}}
{{!FIXME only show this if I'm allowed to see it right now we can only be sure you are allowed to see this if ACLs are disabled until we have further API support}}
{{#let (or canManageNamespaces (not (env 'CONSUL_ACLS_ENABLED'))) as |nspaceManagement|}}
<li>
{{#if (eq nspaces.length 1) }}
{{#if (and (eq nspaces.length 1) (not nspaceManagement)) }}
<span data-test-nspace-selected={{nspace.Name}}>{{nspace.Name}}</span>
{{ else }}
{{#toggle-button data-test-toggle-button="nspaces"}}
{{#toggle-button name="nspaces"}}
{{nspace.Name}}
{{/toggle-button}}
<div>
Expand All @@ -33,8 +35,7 @@
<a href={{href-to 'nspace.dc.services' (concat '~' item.Name) dc.Name}}>{{item.Name}}</a>
</li>
{{/each}}
{{!FIXME only show this if I'm allowed to see it right now we can only be sure you are allowed to see this if ACLs are disabled until we have further API support}}
{{#if (not (env 'CONSUL_ACLS_ENABLED')) }}
{{#if nspaceManagement }}
<li data-test-main-nav-nspaces>
<a href={{href-to 'dc.nspaces' dc.Name}}>Manage namespaces</a>
</li>
Expand All @@ -43,19 +44,20 @@
</div>
{{/if}}
</li>
{{/let}}
{{/if}}
<li>
{{#if (eq dcs.length 1) }}
{{#if (or (not dcs) (eq dcs.length 1)) }}
<span data-test-datacenter-selected={{dc.Name}}>{{dc.Name}}</span>
{{ else }}
{{#toggle-button data-test-toggle-button="datacenters"}}
{{#toggle-button name="datacenters"}}
{{dc.Name}}
{{/toggle-button}}
<div>
<ul>
{{#each dcs as |item|}}
<li data-test-datacenter-picker class={{if (eq dc.Name item.Name) 'is-active'}}>
<a href={{href-to 'dc.services' item.Name}}>{{item.Name}}</a>
<a href={{href-mut (hash dc=item.Name)}}>{{item.Name}}</a>
</li>
{{/each}}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion ui-v2/app/templates/components/toggle-button.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<input type="checkbox" id={{concat 'toggle-button-' guid}} onchange={{action 'change'}} />
<label data-test-toggle-button="datacenters" for={{concat 'toggle-button-' guid}}>{{yield}}</label>
<label data-test-toggle-button={{name}} for={{concat 'toggle-button-' guid}}>{{yield}}</label>
2 changes: 1 addition & 1 deletion ui-v2/tests/acceptance/dc/acls/tokens/login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Feature: dc / acls / tokens / login
secret: something
---
And I submit
Then a GET request is made to "/v1/acl/token/self?dc=dc-1" from yaml
Then a GET request was made to "/v1/acl/token/self?dc=dc-1" from yaml
---
headers:
X-Consul-Token: something
Expand Down
2 changes: 1 addition & 1 deletion ui-v2/tests/acceptance/dc/services/error.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Feature: dc / services / error
dc: dc-1
---
Then I see the text "500 (The backend responded with an error)" in "[data-test-error]"
And I click "[data-test-toggle-button='datacenters']"
When I click dc on the navigation
And I see 2 datacenter models
9 changes: 7 additions & 2 deletions ui-v2/tests/integration/serializers/session-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { get } from 'consul-ui/tests/helpers/api';
import { HEADERS_SYMBOL as META, HEADERS_DATACENTER as DC } from 'consul-ui/utils/http/consul';
module('Integration | Adapter | session | response', function(hooks) {
import {
HEADERS_SYMBOL as META,
HEADERS_DATACENTER as DC,
HEADERS_NAMESPACE as NSPACE,
} from 'consul-ui/utils/http/consul';
module('Integration | Serializer | session | response', function(hooks) {
setupTest(hooks);
const dc = 'dc-1';
const id = 'session-id';
Expand Down Expand Up @@ -50,6 +54,7 @@ module('Integration | Adapter | session | response', function(hooks) {
Datacenter: dc,
[META]: {
[DC.toLowerCase()]: dc,
[NSPACE.toLowerCase()]: payload[0].Namespace || undefinedNspace,
},
Namespace: payload[0].Namespace || undefinedNspace,
uid: `["${payload[0].Namespace || undefinedNspace}","${dc}","${id}"]`,
Expand Down
1 change: 1 addition & 0 deletions ui-v2/tests/integration/services/repository/node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ test('findBySlug returns the correct data for item endpoint', function(assert) {
meta: {
cursor: undefined,
dc: dc,
nspace: nspace,
},
});
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const undefinedNspace = 'default';
service.meta = {
cursor: undefined,
dc: dc,
nspace: payload.Namespace,
};

return service;
Expand Down
28 changes: 28 additions & 0 deletions ui-v2/tests/steps/assertions/http.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// TODO: This entire file/steps need refactoring out so that they don't depend on order
// unless you specifically ask it to assert for order of requests
// this should also let us simplify the entire API for these steps
// an reword them to make more sense
export default function(scenario, assert, lastNthRequest) {
// lastNthRequest should return a
// {
Expand Down Expand Up @@ -122,5 +126,29 @@ export default function(scenario, assert, lastNthRequest) {
})
);
assert.equal(diff.size, 0, `Expected requests "${[...diff].join(', ')}"`);
})
.then('a $method request was made to "$url" from yaml\n$yaml', function(method, url, yaml) {
const requests = lastNthRequest(null, method);
const request = requests.find(function(item) {
return method === item.method && url === item.url;
});
let data = yaml.body || {};
const body = JSON.parse(request.requestBody);
Object.keys(data).forEach(function(key, i, arr) {
assert.equal(
body[key],
data[key],
`Expected the payload to contain ${key} to equal ${body[key]}, ${key} was ${data[key]}`
);
});
data = yaml.headers || {};
const headers = request.requestHeaders;
Object.keys(data).forEach(function(key, i, arr) {
assert.equal(
headers[key],
data[key],
`Expected the payload to contain ${key} to equal ${headers[key]}, ${key} was ${data[key]}`
);
});
});
}

0 comments on commit 40e528f

Please sign in to comment.