vault/ui/tests/integration/components/info-table-row-test.js
Jordan Reimer d4766766f2
Ember Upgrade to 4.4 (#17086)
* runs ember-cli-update to 4.4.0

* updates yarn.lock

* updates dependencies causing runtime errors (#17135)

* Inject Store Service When Accessed Implicitly (#17345)

* adds codemod for injecting store service

* adds custom babylon parser with decorators-legacy plugin for jscodeshift transforms

* updates inject-store-service codemod to only look for .extend object expressions and adds recast options

* runs inject-store-service codemod on js files

* replace query-params helper with hash (#17404)

* Updates/removes dependencies throwing errors in Ember 4.4 (#17396)

* updates ember-responsive to latest

* updates ember-composable-helpers to latest and uses includes helper since contains was removed

* updates ember-concurrency to latest

* updates ember-cli-clipboard to latest

* temporary workaround for toolbar-link component throwing errors for using params arg with LinkTo

* adds missing store injection to auth configure route

* fixes issue with string-list component throwing error for accessing prop in same computation

* fixes non-iterable query params issue in mfa methods controller

* refactors field-to-attrs to handle belongsTo rather than fragments

* converts mount-config fragment to belongsTo on auth-method model

* removes ember-api-actions and adds tune method to auth-method adapter

* converts cluster replication attributes from fragment to relationship

* updates ember-data, removes ember-data-fragments and updates yarn to latest

* removes fragments from secret-engine model

* removes fragment from test-form-model

* removes commented out code

* minor change to inject-store-service codemod and runs again on js files

* Remove LinkTo positional params (#17421)

* updates ember-cli-page-object to latest version

* update toolbar-link to support link-to args and not positional params

* adds replace arg to toolbar-link component

* Clean up js lint errors (#17426)

* replaces assert.equal to assert.strictEqual

* update eslint no-console to error and disables invididual intended uses of console

* cleans up hbs lint warnings (#17432)

* Upgrade bug and test fixes (#17500)

* updates inject-service codemod to take arg for service name and runs for flashMessages service

* fixes hbs lint error after merging main

* fixes flash messages

* updates more deps

* bug fixes

* test fixes

* updates ember-cli-content-security-policy and prevents default form submission throwing errors

* more bug and test fixes

* removes commented out code

* fixes issue with code-mirror modifier sending change event on setup causing same computation error

* Upgrade Clean Up (#17543)

* updates deprecation workflow and filter

* cleans up build errors, removes unused ivy-codemirror and sass and updates ember-cli-sass and node-sass to latest

* fixes control groups test that was skipped after upgrade

* updates control group service tests

* addresses review feedback

* updates control group service handleError method to use router.currentURL rather that transition.intent.url

* adds changelog entry
2022-10-18 09:46:02 -06:00

268 lines
9.5 KiB
JavaScript

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');
let 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(4);
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]').hasAttribute('disabled', '', 'Tooltip copy button is disabled');
assert
.dom('[data-test-tooltip-copy]')
.doesNotHaveClass('has-pointer', 'Pointer class not applied when disabled');
this.set('isCopyable', true);
assert.dom('[data-test-tooltip-copy]').doesNotHaveAttribute('disabled', 'Tooltip copy button is enabled');
assert.dom('[data-test-tooltip-copy]').hasClass('has-pointer', 'Pointer class applied to copy button');
});
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 .flight-icon').exists('Renders a dash (-) for empty string value');
this.set('value', null);
assert.dom('div.column.is-flex .flight-icon').exists('Renders a dash (-) for null value');
this.set('value', undefined);
assert.dom('div.column.is-flex .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', '');
let 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>`);
let 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) {
let yearString = new Date().getFullYear().toString();
this.set('value', new Date());
await render(hbs`<InfoTableRow
@label={{this.label}}
@value={{this.value}}
@formatDate={{'yyyy'}}
/>`);
assert.dom('[data-test-value-div]').hasText(yearString, 'Renders date with passed format');
});
});