Merge pull request #4373 from hashicorp/bugfix/gh-4324-kv-trailing-slashes
UI Bugfix - kv trailing slashes
This commit is contained in:
commit
5de7879e1d
|
@ -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({
|
||||
|
|
19
ui-v2/tests/acceptance/dc/kvs/trailing-slash.feature
Normal file
19
ui-v2/tests/acceptance/dc/kvs/trailing-slash.feature
Normal 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"
|
10
ui-v2/tests/acceptance/steps/dc/kvs/trailing-slash-steps.js
Normal file
10
ui-v2/tests/acceptance/steps/dc/kvs/trailing-slash-steps.js
Normal 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);
|
||||
});
|
||||
}
|
|
@ -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({
|
||||
|
|
|
@ -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 === "''") {
|
||||
|
|
Loading…
Reference in a new issue