2021-02-24 18:23:58 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { resolve } from 'rsvp';
|
|
|
|
import Service from '@ember/service';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2021-10-13 17:52:23 +00:00
|
|
|
import { render, settled, triggerEvent } from '@ember/test-helpers';
|
2021-02-24 18:23:58 +00:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
|
2021-10-13 17:52:23 +00:00
|
|
|
const VALUE = 'test value';
|
|
|
|
const LABEL = 'test label';
|
2021-02-24 18:23:58 +00:00
|
|
|
const TYPE = 'array';
|
2021-10-13 17:52:23 +00:00
|
|
|
const DEFAULT = 'some default value';
|
2021-02-24 18:23:58 +00:00
|
|
|
|
|
|
|
const routerService = Service.extend({
|
|
|
|
transitionTo() {
|
|
|
|
return {
|
|
|
|
followRedirects() {
|
|
|
|
return resolve();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
replaceWith() {
|
|
|
|
return resolve();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-10-13 17:52:23 +00:00
|
|
|
module('Integration | Component | InfoTableRow', function(hooks) {
|
2021-02-24 18:23:58 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function() {
|
|
|
|
this.set('value', VALUE);
|
|
|
|
this.set('label', LABEL);
|
|
|
|
this.set('type', TYPE);
|
2021-10-13 17:52:23 +00:00
|
|
|
this.set('default', DEFAULT);
|
2021-02-24 18:23:58 +00:00
|
|
|
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={{value}}
|
|
|
|
@label={{label}}
|
2021-10-13 17:52:23 +00:00
|
|
|
@defaultShown={{default}}
|
2021-02-24 18:23:58 +00:00
|
|
|
/>`);
|
|
|
|
|
|
|
|
assert.dom('[data-test-component="info-table-row"]').exists();
|
2021-10-22 21:16:02 +00:00
|
|
|
assert.dom('[data-test-row-value]').hasText(VALUE, 'renders value as passed through');
|
2021-07-21 19:47:52 +00:00
|
|
|
|
|
|
|
this.set('value', '');
|
2021-10-13 17:52:23 +00:00
|
|
|
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={{value}}
|
|
|
|
@label={{label}}
|
|
|
|
@tooltipText={{tooltipText}}
|
|
|
|
/>`);
|
|
|
|
|
|
|
|
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');
|
2021-02-24 18:23:58 +00:00
|
|
|
});
|
|
|
|
|
2021-10-21 15:26:56 +00:00
|
|
|
test('it should copy tooltip', async function(assert) {
|
|
|
|
assert.expect(4);
|
|
|
|
|
|
|
|
this.set('isCopyable', false);
|
|
|
|
|
|
|
|
await render(hbs`
|
|
|
|
<InfoTableRow
|
|
|
|
@label={{label}}
|
|
|
|
@value={{value}}
|
|
|
|
@tooltipText="Foo bar"
|
|
|
|
@isTooltipCopyable={{isCopyable}}
|
|
|
|
/>
|
|
|
|
`);
|
|
|
|
|
|
|
|
await triggerEvent('[data-test-value-div="test label"] .ember-basic-dropdown-trigger', 'mouseenter');
|
|
|
|
await settled();
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2021-02-24 18:23:58 +00:00
|
|
|
test('it renders a string with no link if isLink is true and the item type is not an array.', async function(assert) {
|
2021-07-21 19:47:52 +00:00
|
|
|
// 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.
|
2021-02-24 18:23:58 +00:00
|
|
|
await render(hbs`<InfoTableRow
|
|
|
|
@value={{value}}
|
|
|
|
@label={{label}}
|
|
|
|
@isLink={{true}}
|
|
|
|
/>`);
|
2021-10-22 21:16:02 +00:00
|
|
|
assert.dom('[data-test-row-value]').hasText(VALUE, 'renders value in code element and not in a tag');
|
2021-02-24 18:23:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it renders links if isLink is true and type is array', async function(assert) {
|
|
|
|
this.set('valueArray', ['valueArray']);
|
|
|
|
await render(hbs`<InfoTableRow
|
|
|
|
@value={{valueArray}}
|
|
|
|
@label={{label}}
|
|
|
|
@isLink={{true}}
|
|
|
|
@type={{type}}
|
|
|
|
/>`);
|
|
|
|
|
|
|
|
assert.dom('[data-test-item="array"]').hasText('valueArray', 'Confirm link with item value exist');
|
|
|
|
});
|
2021-07-21 19:47:52 +00:00
|
|
|
|
2021-10-13 17:52:23 +00:00
|
|
|
test('it renders as expected if a label and/or value do not exist', async function(assert) {
|
2021-07-21 19:47:52 +00:00
|
|
|
this.set('value', VALUE);
|
|
|
|
this.set('label', '');
|
2021-10-13 17:52:23 +00:00
|
|
|
this.set('default', '');
|
2021-07-21 19:47:52 +00:00
|
|
|
|
|
|
|
await render(hbs`<InfoTableRow
|
|
|
|
@value={{value}}
|
|
|
|
@label={{label}}
|
|
|
|
@alwaysRender={{true}}
|
2021-10-13 17:52:23 +00:00
|
|
|
@defaultShown={{default}}
|
2021-07-21 19:47:52 +00:00
|
|
|
/>`);
|
2021-10-13 17:52:23 +00:00
|
|
|
|
2021-07-21 19:47:52 +00:00
|
|
|
assert.dom('div.column span').hasClass('hs-icon-s', 'Renders a dash (-) for the label');
|
|
|
|
|
|
|
|
this.set('value', '');
|
|
|
|
this.set('label', LABEL);
|
2021-10-13 17:52:23 +00:00
|
|
|
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');
|
2021-07-21 19:47:52 +00:00
|
|
|
|
|
|
|
this.set('value', '');
|
|
|
|
this.set('label', '');
|
2021-10-13 17:52:23 +00:00
|
|
|
this.set('default', '');
|
2021-07-21 19:47:52 +00:00
|
|
|
let dashCount = document.querySelectorAll('.hs-icon-s').length;
|
2021-10-13 17:52:23 +00:00
|
|
|
assert.equal(dashCount, 2, 'Renders dash (-) when both label and value do not exist (and no defaults)');
|
2021-07-21 19:47:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('block content overrides any passed in value content', async function(assert) {
|
|
|
|
await render(hbs`<InfoTableRow
|
|
|
|
@value={{value}}
|
|
|
|
@label={{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');
|
|
|
|
});
|
2021-02-24 18:23:58 +00:00
|
|
|
});
|