From 67402b3d26dc4f59b45408d4d29894ca4f73622a Mon Sep 17 00:00:00 2001 From: John Cowen Date: Thu, 5 Jul 2018 13:43:03 +0100 Subject: [PATCH] Tests and comments regarding the previous 2 commits --- ui-v2/app/models/kv.js | 6 ++- ui-v2/tests/acceptance/dc/kvs/update.feature | 51 +++++++++++++++++++- ui-v2/tests/helpers/type-to-url.js | 26 +++++----- ui-v2/tests/steps.js | 18 +++++-- ui-v2/yarn.lock | 4 +- 5 files changed, 82 insertions(+), 23 deletions(-) diff --git a/ui-v2/app/models/kv.js b/ui-v2/app/models/kv.js index 66e3a2126c..313cb587a3 100644 --- a/ui-v2/app/models/kv.js +++ b/ui-v2/app/models/kv.js @@ -13,7 +13,11 @@ export default Model.extend({ [SLUG_KEY]: attr('string'), LockIndex: attr('number'), Flags: attr('number'), - Value: attr('string'), + // TODO: Consider defaulting all strings to '' because `typeof null !== 'string'` + // look into what other transformers do with `null` also + // preferably removeNull would be done in this layer also as if a property is `null` + // default Values don't kick in, which also explains `Tags` elsewhere + Value: attr('string'), //, {defaultValue: function() {return '';}} CreateIndex: attr('string'), ModifyIndex: attr('string'), Session: attr('string'), diff --git a/ui-v2/tests/acceptance/dc/kvs/update.feature b/ui-v2/tests/acceptance/dc/kvs/update.feature index 1f00f7c257..ba54ebf6c9 100644 --- a/ui-v2/tests/acceptance/dc/kvs/update.feature +++ b/ui-v2/tests/acceptance/dc/kvs/update.feature @@ -1,7 +1,8 @@ @setupApplicationTest Feature: dc / kvs / update: KV Update - Scenario: Update to [Name] change value to [Value] + Background: Given 1 datacenter model with the value "datacenter" + Scenario: Update to [Name] change value to [Value] And 1 kv model from yaml --- Key: [Name] @@ -25,6 +26,54 @@ Feature: dc / kvs / update: KV Update | key-name | a value | | folder/key-name | a value | -------------------------------------------- + Scenario: Update to a key change value to ' ' + And 1 kv model from yaml + --- + Key: key + --- + When I visit the kv page for yaml + --- + dc: datacenter + kv: key + --- + Then the url should be /datacenter/kv/key/edit + Then I fill in with yaml + --- + value: ' ' + --- + And I submit + Then a PUT request is made to "/v1/kv/key?dc=datacenter" with the body " " + Scenario: Update to a key change value to '' + And 1 kv model from yaml + --- + Key: key + --- + When I visit the kv page for yaml + --- + dc: datacenter + kv: key + --- + Then the url should be /datacenter/kv/key/edit + Then I fill in with yaml + --- + value: '' + --- + And I submit + Then a PUT request is made to "/v1/kv/key?dc=datacenter" with no body + Scenario: Update to a key when the value is empty + And 1 kv model from yaml + --- + Key: key + Value: ~ + --- + When I visit the kv page for yaml + --- + dc: datacenter + kv: key + --- + Then the url should be /datacenter/kv/key/edit + And I submit + Then a PUT request is made to "/v1/kv/key?dc=datacenter" with no body @ignore Scenario: The feedback dialog says success or failure Then ok diff --git a/ui-v2/tests/helpers/type-to-url.js b/ui-v2/tests/helpers/type-to-url.js index 470a5f2915..401c8c0b91 100644 --- a/ui-v2/tests/helpers/type-to-url.js +++ b/ui-v2/tests/helpers/type-to-url.js @@ -1,34 +1,32 @@ export default function(type) { - let url = null; + let requests = null; switch (type) { case 'dc': - url = ['/v1/catalog/datacenters']; + requests = ['/v1/catalog/datacenters']; break; case 'service': - url = ['/v1/internal/ui/services', '/v1/health/service/']; + requests = ['/v1/internal/ui/services', '/v1/health/service/']; break; case 'node': - url = ['/v1/internal/ui/nodes']; + requests = ['/v1/internal/ui/nodes']; break; case 'kv': - url = '/v1/kv/'; + requests = ['/v1/kv/']; break; case 'acl': - url = ['/v1/acl/list']; + requests = ['/v1/acl/list']; break; case 'session': - url = ['/v1/session/node/']; + requests = ['/v1/session/node/']; break; } - return function(actual) { - if (url === null) { + // TODO: An instance of URL should come in here (instead of 2 args) + return function(url, method) { + if (requests === null) { return false; } - if (typeof url === 'string') { - return url === actual; - } - return url.some(function(item) { - return actual.indexOf(item) === 0; + return requests.some(function(item) { + return method.toUpperCase() === 'GET' && url.indexOf(item) === 0; }); }; } diff --git a/ui-v2/tests/steps.js b/ui-v2/tests/steps.js index 901843bd12..b25655e4c1 100644 --- a/ui-v2/tests/steps.js +++ b/ui-v2/tests/steps.js @@ -207,12 +207,20 @@ export default function(assert) { ); assert.equal(request.url, url, `Expected the request url to be ${url}, was ${request.url}`); const body = request.requestBody; - assert.equal( - body, - data, - `Expected the request body to be ${body}, was ${request.requestBody}` - ); + assert.equal(body, data, `Expected the request body to be ${data}, was ${body}`); }) + .then('a $method request is made to "$url" with no body', function(method, url) { + const request = api.server.history[api.server.history.length - 2]; + assert.equal( + request.method, + method, + `Expected the request method to be ${method}, was ${request.method}` + ); + assert.equal(request.url, url, `Expected the request url to be ${url}, was ${request.url}`); + const body = request.requestBody; + assert.equal(body, null, `Expected the request body to be null, was ${body}`); + }) + .then('a $method request is made to "$url"', function(method, url) { const request = api.server.history[api.server.history.length - 2]; assert.equal( diff --git a/ui-v2/yarn.lock b/ui-v2/yarn.lock index 50303e742d..6b5f7f3443 100644 --- a/ui-v2/yarn.lock +++ b/ui-v2/yarn.lock @@ -70,8 +70,8 @@ "@glimmer/di" "^0.2.0" "@hashicorp/api-double@^1.3.0": - version "1.3.1" - resolved "https://registry.yarnpkg.com/@hashicorp/api-double/-/api-double-1.3.1.tgz#fd9d706674b934857a638459c2bb52d2f2809455" + version "1.4.0" + resolved "https://registry.yarnpkg.com/@hashicorp/api-double/-/api-double-1.4.0.tgz#17ddad8e55370de0d24151a38c5f029bc207cafe" dependencies: "@gardenhq/o" "^8.0.1" "@gardenhq/tick-control" "^2.0.0"