vault/ui/tests/integration/components/info-table-row-test.js
Jordan Reimer 9750dcaa7d
Key Management Secrets Engine Phase 1 (#15036)
* KMSE: Key Model / Adapter / Serializer setup (#13638)

* First pass model

* KMS key adapter (create/update), serializer, model

* Add last rotated and provider to key

* KeyEdit secret-edit component, and more key model stuff

* add formatDate param support to infotablerow

* Add keymgmt key to routes and options-for-backend

* Rename keymgmt-key to keymgmt/key

* Add test, cleanup

* Add mirage handler for kms

* Address PR comments

* KMS Providers (#13797)

* adds pagination-controls component

* adds kms provider model, adapter and serializer

* adds kms provider-edit component

* updates secrets routes to handle itemType query param for kms

* updates kms key adapter to query by provider

* adds tests for provider-edit component

* refactors kms provider adapter to account for dynamic path

* adds model-validations-helper util

* removes keymgmt from supported-secret-backends

* fixes issue generating url for fetching keys for a provider

* updates modelType method on secret-edit route to accept options object as arg rather than transition

* adds additional checks to ensure queryParams are defined in options object for modelType method

* UI/keymgmt distribute key (#13840)

* Add distribution details on key page, and empty states if no permissions

* Allow search-select component to return object so parent can tell when new item was created

* Add stringarray transform

* Distribute component first pass

* Refactor distribute component for use with internal object rather than ember-data model

* Specific permission denied errors on key edit

* Allow inline errors on search-select component

* Style updates for form errors

* Styling and error messages on distribute component

* Allow block template on inline alert so we can add doc links

* Add distribute action, flash messages, cleanup

* Cleanup & Add tests

* More cleanup

* Address PR comments

* Move disable operations logic to commponent class

* KMSE Enable/Config (#14835)

* adds keymgmt secrets engine as supported backend

* adds comment to check on keymgmt as member of adp module

* updates kms provider to use model-validations decorator

* fixes lint errors and tests

Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com>
2022-04-20 12:40:27 -06:00

264 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.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');
});
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');
});
});