Merge pull request #4373 from hashicorp/bugfix/gh-4324-kv-trailing-slashes

UI Bugfix - kv trailing slashes
This commit is contained in:
John Cowen 2018-07-13 09:38:02 +01:00 committed by GitHub
commit 5de7879e1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 2 deletions

View file

@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { hash } from 'rsvp';
import { get } from '@ember/object';
import isFolder from 'consul-ui/utils/isFolder';
import WithKvActions from 'consul-ui/mixins/kv/with-actions';
export default Route.extend(WithKvActions, {
@ -12,8 +13,17 @@ export default Route.extend(WithKvActions, {
},
},
repo: service('kv'),
model: function(params) {
beforeModel: function() {
// we are index or folder, so if the key doesn't have a trailing slash
// add one to force a fake findBySlug
const params = this.paramsFor(this.routeName);
const key = params.key || '/';
if (!isFolder(key)) {
return this.replaceWith(this.routeName, key + '/');
}
},
model: function(params) {
let key = params.key || '/';
const dc = this.modelFor('dc').dc.Name;
const repo = get(this, 'repo');
return hash({

View file

@ -0,0 +1,19 @@
@setupApplicationTest
Feature: dc / kvs / trailing slash
Scenario: I have 10 folders
Given 1 datacenter model with the value "datacenter"
And 10 kv models from yaml
When I visit the kvs page for yaml
---
dc: datacenter
kv: foo/bar
---
Then the url should be /datacenter/kv/foo/bar/
And the last GET request was made to "/v1/kv/foo/bar/?keys&dc=datacenter&separator=%2F"
When I visit the kvs page for yaml
---
dc: datacenter
kv: foo/bar/
---
Then the url should be /datacenter/kv/foo/bar/
And the last GET request was made to "/v1/kv/foo/bar/?keys&dc=datacenter&separator=%2F"

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

@ -1,6 +1,6 @@
export default function(visitable, deletable, creatable, clickable, attribute, collection) {
return creatable({
visit: visitable('/:dc/kv'),
visit: visitable(['/:dc/kv/:kv', '/:dc/kv'], str => str),
kvs: collection(
'[data-test-tabular-row]',
deletable({

View file

@ -241,6 +241,15 @@ export default function(assert) {
);
assert.equal(request.url, url, `Expected the request url to be ${url}, was ${request.url}`);
})
.then('the last $method request was made to "$url"', function(method, url) {
const request = api.server.history
.slice(0)
.reverse()
.find(function(item) {
return item.method === method;
});
assert.equal(request.url, url, `Expected the request url to be ${url}, was ${request.url}`);
})
.then('the url should be $url', function(url) {
// TODO: nice! $url should be wrapped in ""
if (url === "''") {