From 1f1459eba2a368e24c267d74bb967cdd7c32e9ee Mon Sep 17 00:00:00 2001
From: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
Date: Wed, 13 Oct 2021 10:52:23 -0700
Subject: [PATCH] UI/InfoTableRow testing (#12811)
* updates storybook
* adds computed property valueIsEmpty
* adds tests to info table row
---
.../core/addon/components/info-table-row.js | 17 ++++++
.../templates/components/info-table-row.hbs | 2 +-
ui/lib/core/stories/info-table-row.md | 8 +++
ui/lib/core/stories/info-table-row.stories.js | 20 +++++--
.../components/info-table-row-test.js | 53 ++++++++++++++-----
5 files changed, 82 insertions(+), 18 deletions(-)
diff --git a/ui/lib/core/addon/components/info-table-row.js b/ui/lib/core/addon/components/info-table-row.js
index 2ab9083e82..36a81e7d90 100644
--- a/ui/lib/core/addon/components/info-table-row.js
+++ b/ui/lib/core/addon/components/info-table-row.js
@@ -44,4 +44,21 @@ export default Component.extend({
valueIsBoolean: computed('value', function() {
return typeOf(this.value) === 'boolean';
}),
+
+ valueIsEmpty: computed('value', function() {
+ let { value } = this;
+ if (typeOf(value) === 'array' && value.length === 0) {
+ return true;
+ }
+ switch (value) {
+ case undefined:
+ return true;
+ case null:
+ return true;
+ case '':
+ return true;
+ default:
+ return false;
+ }
+ }),
});
diff --git a/ui/lib/core/addon/templates/components/info-table-row.hbs b/ui/lib/core/addon/templates/components/info-table-row.hbs
index 7fcf080181..0f3bfb2ae4 100644
--- a/ui/lib/core/addon/templates/components/info-table-row.hbs
+++ b/ui/lib/core/addon/templates/components/info-table-row.hbs
@@ -34,7 +34,7 @@
{{!-- alwaysRender is still true --}}
{{else if (and (not value) defaultShown)}}
{{defaultShown}}
- {{else if (eq value "")}}
+ {{else if valueIsEmpty}}
{{else}}
{{#if (eq type 'array')}}
diff --git a/ui/lib/core/stories/info-table-row.md b/ui/lib/core/stories/info-table-row.md
index d5c0a54074..07bfc4394e 100644
--- a/ui/lib/core/stories/info-table-row.md
+++ b/ui/lib/core/stories/info-table-row.md
@@ -12,6 +12,14 @@ that the value breaks under the label on smaller viewports.
| label | string | null | The display name for the value. |
| helperText | string | null | Text to describe the value displayed beneath the label. |
| alwaysRender | Boolean | false | Indicates if the component content should be always be rendered. When false, the value of `value` will be used to determine if the component should render. |
+| [type] | string | "array" | The type of value being passed in. This is used for when you want to trim an array. For example, if you have an array value that can equal length 15+ this will trim to show 5 and count how many more are there |
+| [isLink] | Boolean | true | Passed through to InfoTableItemArray. Indicates if the item should contain a link-to component. Only setup for arrays, but this could be changed if needed. |
+| [modelType] | string | null | Passed through to InfoTableItemArray. Tells what model you want data for the allOptions to be returned from. Used in conjunction with the the isLink. |
+| [queryParam] | String | | Passed through to InfoTableItemArray. If you want to specific a tab for the View All XX to display to. Ex: role |
+| [backend] | String | | Passed through to InfoTableItemArray. To specify secrets backend to point link to Ex: transformation |
+| [viewAll] | String | | Passed through to InfoTableItemArray. Specify the word at the end of the link View all. |
+| [tooltipText] | String | | Text if a tooltip should display over the value. |
+| [defaultShown] | String | | Text that renders as value if alwaysRender=true. Eg. "Vault default" |
**Example**
diff --git a/ui/lib/core/stories/info-table-row.stories.js b/ui/lib/core/stories/info-table-row.stories.js
index c16812e718..b19b836a3b 100644
--- a/ui/lib/core/stories/info-table-row.stories.js
+++ b/ui/lib/core/stories/info-table-row.stories.js
@@ -11,13 +11,19 @@ storiesOf('InfoTable/InfoTableRow', module)
() => ({
template: hbs`
Info Table Row
-
+
`,
context: {
label: text('Label', 'TTL'),
- value: text('Value', '30m'),
- helperText: text('helperText', 'A short description'),
+ value: text('Value', '30m (hover to see the tooltip!)'),
+ helperText: text('helperText', 'This is helperText - for a short description'),
alwaysRender: boolean('Always render?', false),
+ tooltipText: text('tooltipText', 'This is tooltipText'),
},
}),
{ notes }
@@ -27,12 +33,16 @@ storiesOf('InfoTable/InfoTableRow', module)
() => ({
template: hbs`
Info Table Row
-
+
`,
context: {
label: 'Local mount?',
value: boolean('Value', true),
- helperText: text('helperText', 'A short description'),
+ helperText: text('helperText', 'This is helperText - for a short description'),
alwaysRender: boolean('Always render?', true),
},
}),
diff --git a/ui/tests/integration/components/info-table-row-test.js b/ui/tests/integration/components/info-table-row-test.js
index bf8462089e..9093109b20 100644
--- a/ui/tests/integration/components/info-table-row-test.js
+++ b/ui/tests/integration/components/info-table-row-test.js
@@ -2,12 +2,13 @@ import { module, test } from 'qunit';
import { resolve } from 'rsvp';
import Service from '@ember/service';
import { setupRenderingTest } from 'ember-qunit';
-import { render } from '@ember/test-helpers';
+import { render, settled, triggerEvent } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
-const VALUE = 'testing';
-const LABEL = 'item';
+const VALUE = 'test value';
+const LABEL = 'test label';
const TYPE = 'array';
+const DEFAULT = 'some default value';
const routerService = Service.extend({
transitionTo() {
@@ -22,13 +23,14 @@ const routerService = Service.extend({
},
});
-module('Integration | Component | InfoTableItem', function(hooks) {
+module('Integration | Component | InfoTableRow', function(hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function() {
this.set('value', VALUE);
this.set('label', LABEL);
this.set('type', TYPE);
+ this.set('default', DEFAULT);
this.owner.register('service:router', routerService);
this.router = this.owner.lookup('service:router');
});
@@ -38,11 +40,10 @@ module('Integration | Component | InfoTableItem', function(hooks) {
});
test('it renders', async function(assert) {
- this.set('alwaysRender', true);
-
await render(hbs``);
assert.dom('[data-test-component="info-table-row"]').exists();
@@ -50,7 +51,24 @@ module('Integration | Component | InfoTableItem', function(hooks) {
assert.equal(string, VALUE, 'renders value as passed through');
this.set('value', '');
- assert.dom('[data-test-label-div]').doesNotExist('does not render if no value and alwaysRender is false');
+ assert
+ .dom('[data-test-label-div]')
+ .doesNotExist('does not render if no value and alwaysRender is false (even if default exists)');
+ });
+
+ test('it renders a tooltip', async function(assert) {
+ this.set('tooltipText', 'Tooltip text!');
+
+ await render(hbs``);
+
+ await triggerEvent('[data-test-value-div="test label"] .ember-basic-dropdown-trigger', 'mouseenter');
+ await settled();
+ let tooltip = document.querySelector('div.box').textContent.trim();
+ assert.equal(tooltip, 'Tooltip text!', 'renders tooltip text');
});
test('it renders a string with no link if isLink is true and the item type is not an array.', async function(assert) {
@@ -76,27 +94,38 @@ module('Integration | Component | InfoTableItem', function(hooks) {
assert.dom('[data-test-item="array"]').hasText('valueArray', 'Confirm link with item value exist');
});
- test('it renders a dash (-) if a label and/or value do not exist', async function(assert) {
+ test('it renders as expected if a label and/or value do not exist', async function(assert) {
this.set('value', VALUE);
this.set('label', '');
+ this.set('default', '');
await render(hbs``);
- assert.dom('[data-test-label-div]').exists('renders label div');
- assert.dom('[data-test-value-div]').exists('renders value div');
+
assert.dom('div.column span').hasClass('hs-icon-s', 'Renders a dash (-) for the label');
this.set('value', '');
this.set('label', LABEL);
- assert.dom('div.column.is-flex span').hasClass('hs-icon-s', 'Renders a dash (-) for the value');
+ assert.dom('div.column.is-flex span').hasClass('hs-icon-s', 'Renders a dash (-) for empty string value');
+
+ this.set('value', null);
+ assert.dom('div.column.is-flex span').hasClass('hs-icon-s', 'Renders a dash (-) for null value');
+
+ this.set('value', undefined);
+ assert.dom('div.column.is-flex span').hasClass('hs-icon-s', 'Renders a dash (-) for undefined value');
+
+ this.set('default', DEFAULT);
+ assert.dom('[data-test-value-div]').hasText(DEFAULT, 'Renders default text if value is empty');
this.set('value', '');
this.set('label', '');
+ this.set('default', '');
let dashCount = document.querySelectorAll('.hs-icon-s').length;
- assert.equal(dashCount, 2, 'Renders dash (-) when both label and value do not exist');
+ assert.equal(dashCount, 2, 'Renders dash (-) when both label and value do not exist (and no defaults)');
});
test('block content overrides any passed in value content', async function(assert) {