From bfde310ec04ca3b64c12cb4e0fec75ba5285a65a Mon Sep 17 00:00:00 2001
From: Angel Garbarino
Date: Tue, 25 Oct 2022 12:58:11 -0700
Subject: [PATCH] UI/vault 9268/pki component tests (#17609)
* wip
* work in progress
* pki-role-form-test
* clean up
* radio-select-ttl-or-string test
* clean up
* add yielded check
* 12 to 13
* add pki-key-usage test
* remove meep
* key-params test
* clean up
* clean up
* pr comments
---
ui/app/models/pki/pki-role-engine.js | 3 +-
.../components/radio-select-ttl-or-string.hbs | 5 +-
.../components/radio-select-ttl-or-string.js | 11 +-
ui/lib/core/addon/helpers/is-active-route.js | 2 +-
.../addon/components/pki-key-parameters.hbs | 2 +-
ui/lib/pki/addon/components/pki-key-usage.hbs | 2 +-
ui/lib/pki/addon/components/pki-key-usage.js | 2 +
ui/lib/pki/addon/components/pki-role-form.hbs | 15 ++-
ui/tests/helpers/pki-engine.js | 30 +++++
.../components/pki/pki-key-parameters-test.js | 101 ++++++++++++++++
.../components/pki/pki-key-usage-test.js | 85 +++++++++++++
.../components/pki/pki-role-form-test.js | 112 ++++++++++++++++++
.../pki/radio-select-ttl-or-string-test.js | 90 ++++++++++++++
13 files changed, 448 insertions(+), 12 deletions(-)
create mode 100644 ui/tests/helpers/pki-engine.js
create mode 100644 ui/tests/integration/components/pki/pki-key-parameters-test.js
create mode 100644 ui/tests/integration/components/pki/pki-key-usage-test.js
create mode 100644 ui/tests/integration/components/pki/pki-role-form-test.js
create mode 100644 ui/tests/integration/components/pki/radio-select-ttl-or-string-test.js
diff --git a/ui/app/models/pki/pki-role-engine.js b/ui/app/models/pki/pki-role-engine.js
index 8460ca5e75..c2fa644d56 100644
--- a/ui/app/models/pki/pki-role-engine.js
+++ b/ui/app/models/pki/pki-role-engine.js
@@ -22,8 +22,7 @@ export default class PkiRoleEngineModel extends Model {
@attr('string', {
label: 'Issuer reference',
defaultValue: 'default',
- subText:
- 'Specifies the issuer that will be used to create certificates with this role. To find this, run [command]. By default, we will use the mounts default issuer.',
+ subText: `Specifies the issuer that will be used to create certificates with this role. To find this, run read -field=default pki_int/config/issuers in the console. By default, we will use the mounts default issuer.`,
})
issuerRef;
diff --git a/ui/lib/core/addon/components/radio-select-ttl-or-string.hbs b/ui/lib/core/addon/components/radio-select-ttl-or-string.hbs
index 60ff240bc4..cc37e22bd2 100644
--- a/ui/lib/core/addon/components/radio-select-ttl-or-string.hbs
+++ b/ui/lib/core/addon/components/radio-select-ttl-or-string.hbs
@@ -5,6 +5,7 @@
@value="ttl"
@onChange={{this.onRadioButtonChange}}
@groupValue={{this.groupValue}}
+ data-test-radio-button="ttl"
/>
{{#if (eq this.groupValue "specificDate")}}
{{/if}}
diff --git a/ui/lib/core/addon/components/radio-select-ttl-or-string.js b/ui/lib/core/addon/components/radio-select-ttl-or-string.js
index b9d1e29702..e63869bbfa 100644
--- a/ui/lib/core/addon/components/radio-select-ttl-or-string.js
+++ b/ui/lib/core/addon/components/radio-select-ttl-or-string.js
@@ -28,16 +28,21 @@ export default class RadioSelectTtlOrString extends Component {
// Clear the previous selection if they have clicked the other radio button.
if (selection === 'specificDate') {
this.args.model.set('ttl', '');
- this.ttlTime = ''; //clear out the form field
+ this.ttlTime = '';
}
- if (selection === 'tll') {
+ if (selection === 'ttl') {
this.args.model.set('notAfter', '');
- this.notAfter = ''; //clear out the form field
+ this.notAfter = '';
+ this.args.model.set('ttl', this.ttlTime);
}
}
@action setAndBroadcastTtl(value) {
let valueToSet = value.enabled === true ? `${value.seconds}s` : 0;
+ if (this.groupValue === 'specificDate') {
+ // do not save ttl on the model until the ttl radio button is selected
+ return;
+ }
this.args.model.set('ttl', `${valueToSet}`);
}
diff --git a/ui/lib/core/addon/helpers/is-active-route.js b/ui/lib/core/addon/helpers/is-active-route.js
index 36029f8839..9151b5a58a 100644
--- a/ui/lib/core/addon/helpers/is-active-route.js
+++ b/ui/lib/core/addon/helpers/is-active-route.js
@@ -19,7 +19,7 @@ export default Helper.extend({
const currentRoute = router.get('currentRouteName');
let currentURL = router.get('currentURL');
// if we have any query params we want to discard them
- currentURL = currentURL.split('?')[0];
+ currentURL = currentURL?.split('?')[0];
const comparator = isExact ? exact : startsWith;
if (!currentRoute) {
return false;
diff --git a/ui/lib/pki/addon/components/pki-key-parameters.hbs b/ui/lib/pki/addon/components/pki-key-parameters.hbs
index 2715338d00..b27ce153e6 100644
--- a/ui/lib/pki/addon/components/pki-key-parameters.hbs
+++ b/ui/lib/pki/addon/components/pki-key-parameters.hbs
@@ -49,7 +49,7 @@
data-test-input={{attr.name}}
>
{{#each (path-or-array attr.options.possibleValues @model) as |val|}}
-
{{/each}}
diff --git a/ui/lib/pki/addon/components/pki-key-usage.hbs b/ui/lib/pki/addon/components/pki-key-usage.hbs
index 2e4e12ffcc..95713271d7 100644
--- a/ui/lib/pki/addon/components/pki-key-usage.hbs
+++ b/ui/lib/pki/addon/components/pki-key-usage.hbs
@@ -8,7 +8,7 @@
data-test-toggle-group={{@group}}
/>
{{#if (get @model prop)}}
-
+
-