open-vault/ui/tests/integration/components/info-table-row-test.js
Jordan Reimer 5c2a08de6d
Ember Upgrade to 3.24 (#13443)
* Update browserslist

* Add browserslistrc

* ember-cli-update --to 3.26, fix conflicts

* Run codemodes that start with ember-*

* More codemods - before cp*

* More codemods (curly data-test-*)

* WIP ember-basic-dropdown template errors

* updates ember-basic-dropdown and related deps to fix build issues

* updates basic dropdown instances to new version API

* updates more deps -- ember-template-lint is working again

* runs no-implicit-this codemod

* creates and runs no-quoteless-attributes codemod

* runs angle brackets codemod

* updates lint:hbs globs to only touch hbs files

* removes yield only templates

* creates and runs deprecated args transform

* supresses lint error for invokeAction on LinkTo component

* resolves remaining ambiguous path lint errors

* resolves simple-unless lint errors

* adds warnings for deprecated tagName arg on LinkTo components

* adds warnings for remaining curly component invocation

* updates global template lint rules

* resolves remaining template lint errors

* disables some ember specfic lint rules that target pre octane patterns

* js lint fix run

* resolves remaining js lint errors

* fixes test run

* adds npm-run-all dep

* fixes test attribute issues

* fixes console acceptance tests

* fixes tests

* adds yield only wizard/tutorial-active template

* fixes more tests

* attempts to fix more flaky tests

* removes commented out settled in transit test

* updates deprecations workflow and adds initializer to filter by version

* updates flaky policies acl old test

* updates to flaky transit test

* bumps ember deps down to LTS version

* runs linters after main merge

* fixes client count tests after bad merge conflict fixes

* fixes client count history test

* more updates to lint config

* another round of hbs lint fixes after extending stylistic rule

* updates lint-staged commands

* removes indent eslint rule since it seems to break things

* fixes bad attribute in transform-edit-form template

* test fixes

* fixes enterprise tests

* adds changelog

* removes deprecated ember-concurrency-test-waiters dep and adds @ember/test-waiters

* flaky test fix

Co-authored-by: hashishaw <cshaw@hashicorp.com>
2021-12-16 20:44:29 -07:00

166 lines
5.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.equal(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="array"]').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.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) {
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.equal(block, 'Block content is here', 'renders block passed through');
});
});