vault/ui/tests/integration/components/info-table-row-test.js
malinac02 79b2f09715
UI: HDS adoption replace <CopyButton> component (#22333)
* Part 1: Upgrade HDS to 2.9.0 (#22311)

* UI: HDS adoption replace <CopyButton> part 2 (#22356)

* certificate-card.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* scope-form.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* fix tests caused by changing certificate-card. change hds copy button in certificate-card.hbs

* json-editor.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* masked-input.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* fix error with certificate-card.hbs copy button

* fix tests that deal with certificate-card.hbs

* add class to hds copy buttons to maintain similar styling to curent UI

* info-table-row.hbs: replace 2 <CopyButton> with <Hds::Copy::Button>

* undo change that should instead by merged in from main

* change tooltip copy button to white. cleanup

* add extra tet for oidc scope form. edit css class for the white icon copy button

* fix tests

* UI: HDS adoption replace <CopyButton> part 3 (#22614)

* encrypt.hbs: replace 2 <CopyButton> with <Hds::Copy::Button>

* decrypt.hbs: replace 2 <CopyButton> with <Hds::Copy::Button>

* datakey.hbs. replace 6 <CopyButton> with <Hds::Copy::Button>

* rewrap.hbs: replace 2 <CopyButton> with <Hds::Copy::Button>

* hmac.hbs: replace 2 <CopyButton> with <Hds::Copy::Button>

* fix typo

* add copy-close class to copy & close buttons

* export.hbs: replace 2 <CopyButton> with <Hds::Copy::Button>. fix styling

* sign.hbs: replace 2 <CopyButton> with <Hds::Copy::Button>

* fix test caused by changing <pre> tag to <code> in export.hbs

* rename class

* add extra style to class needed for part 4 of copy button replacement

* UI: HDS adoption replace <CopyButton> part 4 (#22749)

* user-menu.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* transit-form-show.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* configure-ssh-secret.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* tool-hash.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* tool-random.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* tool-rewrap.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* tool-unwrap.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* tool-wrap.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* paths.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* code-snippet.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* cleanup css for code-snippet. add comments for getting rid of code-snippet and replacing with <Hds::Copy::Snippet

* change code-snippet copy icon to gray to match original design

* change code-snippet class

* accounts.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* hover-copy-button.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* add.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* show.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* copy-secret-dropdown.hbs: replace 1 <CopyButton> with <Hds::Copy::Button>

* change styling of 'link' copy buttons

* generate-credentials.hbs: replace 2 <CopyButton> with <Hds::Copy::Button>

* transform-show-transformation.hbs: replace 2 <CopyButton> with <Hds::Copy::Button>

* sign.hbs: replace 2 <CopyButton> with <Hds::Copy::Button>

* hide some copy buttons' icons and use original flash message

* undo cleanup of scss file so that I can put cleanup all into one PR to be more organized

* update code snippet copy button

* UI: HDS adoption replace <CopyButton> part 5: Cleanup (#22884)

* remove unecessary code-snippet.scssn class

* remove copy classes from masked-input.scss

* remove copy button class from text-file.scss

* uninstall ember-cli-clipboard 0.16.0 since there is no longer structure <CopyButton>

* remove copyright message from code-snippet.scss to avoid merge conflicts with main, where the file is deleted

* replace 2 classes with one

* remove unecessary class from copy button

* cleanup classes

* revert changes to avoid merge conflicts

* remove is-block class

* conditionally render private key

* add more info to comment

* remove HoverCopyButton

* add missing selector

* fix control group padding

---------

Co-authored-by: clairebontempo@gmail.com <clairebontempo@gmail.com>
Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>

* rename class to transparent background

* remove unused test selectors

* replace transit actions with Copy::Snippet

* replace transfrom code blocks with code snippet component

* revert extra css fiddling

* misc cleanup, unused action

* remove copy & close buttons from transit modals

* remove is- from class naming

* remove hds-copy-button class

* add other grey class

* more small cleanup

* add -top to margin

* add changelog

---------

Co-authored-by: clairebontempo@gmail.com <clairebontempo@gmail.com>
Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
2023-09-15 23:46:10 +00:00

295 lines
10 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { resolve } from 'rsvp';
import Service from '@ember/service';
import { setupRenderingTest } from 'ember-qunit';
import { render, triggerEvent } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
const VALUE = 'test value';
const LABEL = 'test label';
const TYPE = 'array';
const DEFAULT = 'some default value';
const routerService = Service.extend({
transitionTo() {
return {
followRedirects() {
return resolve();
},
};
},
replaceWith() {
return resolve();
},
});
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');
});
hooks.afterEach(function () {
this.owner.unregister('service:store');
});
test('it renders', async function (assert) {
await render(hbs`<InfoTableRow
@value={{this.value}}
@label={{this.label}}
@defaultShown={{this.default}}
/>`);
assert.dom('[data-test-component="info-table-row"]').exists();
assert.dom('[data-test-row-value]').hasText(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 (even if default exists)');
});
test('it renders a tooltip', async function (assert) {
this.set('tooltipText', 'Tooltip text!');
await render(hbs`<InfoTableRow
@value={{this.value}}
@label={{this.label}}
@tooltipText={{this.tooltipText}}
/>`);
await triggerEvent('[data-test-value-div="test label"] .ember-basic-dropdown-trigger', 'mouseenter');
const tooltip = document.querySelector('div.box').textContent.trim();
assert.strictEqual(tooltip, 'Tooltip text!', 'renders tooltip text');
});
test('it should copy tooltip', async function (assert) {
assert.expect(3);
this.set('isCopyable', false);
await render(hbs`
<InfoTableRow
@label={{this.label}}
@value={{this.value}}
@tooltipText="Foo bar"
@isTooltipCopyable={{this.isCopyable}}
/>
`);
await triggerEvent('[data-test-value-div="test label"] .ember-basic-dropdown-trigger', 'mouseenter');
assert.dom('[data-test-tooltip-copy]').doesNotExist('Tooltip has no copy button');
this.set('isCopyable', true);
assert.dom('[data-test-tooltip-copy]').exists('Tooltip has copy button');
assert
.dom('[data-test-tooltip-copy]')
.hasAttribute('data-clipboard-text', 'Foo bar', 'Copy button will copy the 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) {
// This could be changed in the component so that it adds a link for any item type, but right now it should only add a link if item type is an array.
await render(hbs`<InfoTableRow
@value={{this.value}}
@label={{this.label}}
@isLink={{true}}
/>`);
assert.dom('[data-test-row-value]').hasText(VALUE, 'renders value in code element and not in a tag');
});
test('it renders links if isLink is true and type is array', async function (assert) {
this.set('valueArray', ['valueArray']);
await render(hbs`<InfoTableRow
@value={{this.valueArray}}
@label={{this.label}}
@isLink={{true}}
@type={{this.type}}
/>`);
assert.dom('[data-test-item="valueArray"]').hasText('valueArray', 'Confirm link with item value exist');
});
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`<InfoTableRow
@value={{this.value}}
@label={{this.label}}
@alwaysRender={{true}}
@defaultShown={{this.default}}
/>`);
assert.dom('div.column.is-one-quarter .flight-icon').exists('Renders a dash (-) for the label');
this.set('value', '');
this.set('label', LABEL);
assert.dom('div.column.is-flex-center .flight-icon').exists('Renders a dash (-) for empty string value');
this.set('value', null);
assert.dom('div.column.is-flex-center .flight-icon').exists('Renders a dash (-) for null value');
this.set('value', undefined);
assert.dom('div.column.is-flex-center .flight-icon').exists('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', '');
const dashCount = document.querySelectorAll('.flight-icon').length;
assert.strictEqual(
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) {
await render(hbs`<InfoTableRow
@value={{this.value}}
@label={{this.label}}
@alwaysRender={{true}}>
Block content is here
</InfoTableRow>`);
const block = document.querySelector('[data-test-value-div]').textContent.trim();
assert.strictEqual(block, 'Block content is here', 'renders block passed through');
});
test('Row renders when block content even if alwaysRender = false', async function (assert) {
await render(hbs`<InfoTableRow
@label={{this.label}}
@alwaysRender={{false}}>
Block content
</InfoTableRow>`);
assert.dom('[data-test-value-div]').exists('renders block');
assert.dom('[data-test-value-div]').hasText('Block content', 'renders block');
});
test('Row does not render empty block content when alwaysRender = false', async function (assert) {
await render(hbs`<InfoTableRow
@label={{this.label}}
@alwaysRender={{false}} />`);
assert.dom('[data-test-component="info-table-row"]').doesNotExist();
});
test('Has dashed label if none provided', async function (assert) {
await render(hbs`<InfoTableRow
@value={{this.value}}
/>`);
assert.dom('[data-test-component="info-table-row"]').exists();
assert.dom('[data-test-icon="minus"]').exists('renders dash when no label');
});
test('Truncates the label if too long', async function (assert) {
this.set('label', 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz');
await render(hbs`<InfoTableRow
@label={{this.label}}
@value={{this.value}}
/>`);
assert.dom('[data-test-component="info-table-row"]').exists('Row renders');
assert.dom('[data-test-label-div].label-overflow').exists('Label has class label-overflow');
await triggerEvent('[data-test-row-label]', 'mouseenter');
assert.dom('[data-test-label-tooltip]').exists('Label tooltip exists on hover');
});
test('Renders if block value and alwaysrender=false', async function (assert) {
await render(hbs`<InfoTableRow @alwaysRender={{false}}>{{this.value}}</InfoTableRow>`);
assert.dom('[data-test-component="info-table-row"]').exists();
});
test('Does not render if value is empty and alwaysrender=false', async function (assert) {
await render(hbs`<InfoTableRow @alwaysRender={{false}} @value="" />`);
assert.dom('[data-test-component="info-table-row"]').doesNotExist();
});
test('Renders dash for value if value empty and alwaysRender=true', async function (assert) {
await render(hbs`<InfoTableRow
@label={{this.label}}
@alwaysRender={{true}}
/>`);
assert.dom('[data-test-component="info-table-row"]').exists();
assert.dom('[data-test-value-div] [data-test-icon="minus"]').exists('renders dash for value');
});
test('Renders block over @value or @defaultShown', async function (assert) {
await render(hbs`<InfoTableRow
@label={{this.label}}
@value="bar"
@defaultShown="baz"
>
foo
</InfoTableRow>`);
assert.dom('[data-test-component="info-table-row"]').exists();
assert.dom('[data-test-value-div]').hasText('foo', 'renders block value');
});
test('Renders icons if value is boolean', async function (assert) {
this.set('value', true);
await render(hbs`<InfoTableRow
@label={{this.label}}
@value={{this.value}}
/>`);
assert.dom('[data-test-boolean-true]').exists('check icon exists');
assert.dom('[data-test-value-div]').hasText('Yes', 'Renders yes text');
this.set('value', false);
assert.dom('[data-test-boolean-false]').exists('x icon exists');
assert.dom('[data-test-value-div]').hasText('No', 'renders no text');
});
test('Renders data-test attrs passed from parent', async function (assert) {
this.set('value', true);
await render(hbs`<InfoTableRow
@label={{this.label}}
@value={{this.value}}
data-test-foo-bar
/>`);
assert.dom('[data-test-foo-bar]').exists();
});
test('Formats the value as date when formatDate present', async function (assert) {
this.set('value', new Date('2018-04-03T14:15:30'));
await render(hbs`<InfoTableRow
@label={{this.label}}
@value={{this.value}}
@formatDate={{'yyyy'}}
/>`);
assert.dom('[data-test-value-div]').hasText('2018', 'Renders date with passed format');
});
test('Formats the value as TTL when formatTtl present', async function (assert) {
this.set('value', 6000);
await render(hbs`<InfoTableRow
@label={{this.label}}
@value={{this.value}}
@formatTtl={{true}}
/>`);
assert
.dom('[data-test-value-div]')
.hasText('1 hour 40 minutes', 'Translates number value to largest unit with carryover of minutes');
});
test('Formats string value when formatTtl present', async function (assert) {
this.set('value', '45m');
await render(hbs`<InfoTableRow
@label={{this.label}}
@value={{this.value}}
@formatTtl={{true}}
/>`);
assert.dom('[data-test-value-div]').hasText('45 minutes', 'it formats string duration');
});
});