vault/ui/tests/integration/components/kv-suggestion-input-test.js
Vault Automation bf32d52450
[UI] Ember Data Migration - KV Cleanup (#9623) (#9794)
* adds error handling for control groups to api service as post request middleware

* updates kv list route to use api service

* updates kv config route to use api service

* updates kv secrets overview route to use api service

* updates kv secret details route to use api service

* adds kv form

* updates kv metadata details route to use api service

* updates kv paths and version history routes to use api service

* refactors kv-data-fields component to form component

* updates kv secret create route to use api service

* updates kv secret edit route to use api service

* updates kv metadata edit route to use api service

* adds waitFor to async middleware in api service to attempt to fix race conditions in tests

* adds kvMetadata path to capabilities path map

* fixes kv list item delete test selector

* removes kv models, adapters and serializers

* removes store from kv addon

* removes ember data related test helpers from kv-run-commands

* updates comments that referred to kv ember data models

* updates kv-page-header tests

* updates model-form-fields test to use totp-key model rather than kv/data

* removes another reference to kv/data model from path-help test

* fixes kv v2 workflow create tests

* fixes issue returning metadata for secret when latest version is deleted

* decodes uri in path returned by api service parseError method

* fixes kv v2 edge cases tests

* fixes issue deleteing control group token in api service

* decodes url for control group token lookup in api service

* fixes version history linked block link

* defaults cas to 0 when creating new secret

* removes log

* adds ember-template-lint to kv engine

* more test fixes

* updates kv-suggestion-input component to use api service

* removes kv metadata model reference from quick actions card

* fixes sync destination sync secrets tests

* updates kv helpers from classic format

* updates kv helpers imports

* reverts to use secret.version in details edit route

* fixes isDeleted import in kv version history test

* adds waitFor to api service parseError method

* reverts removing async from addQueryParams api method

* attempts to fix test flakiness requesting custom metadata from data endpoint

* more tweaks to requesting metadata from data

* adds waitFor to requestData method

Co-authored-by: Jordan Reimer <zofskeez@gmail.com>
2025-10-02 12:52:26 -06:00

131 lines
4.7 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, click, fillIn, typeIn } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
import sinon from 'sinon';
const {
searchSelect: { option, options },
kvSuggestion: { input },
} = GENERAL;
module('Integration | Component | kv-suggestion-input', function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
this.label = 'Input something';
this.mountPath = 'secret/';
this.apiStub = sinon
.stub(this.owner.lookup('service:api').secrets, 'kvV2List')
.resolves({ keys: ['foo/', 'my-secret'] });
this.renderComponent = () =>
render(hbs`
<KvSuggestionInput
@label={{this.label}}
@subText="Suggestions will display"
@value={{this.secretPath}}
@mountPath={{this.mountPath}}
@onChange={{fn (mut this.secretPath)}}
/>
`);
});
test('it should render label and sub text', async function (assert) {
await this.renderComponent();
assert.dom('label').hasText('Input something', 'Label renders');
assert.dom('[data-test-label-subtext]').hasText('Suggestions will display', 'Label subtext renders');
this.label = null;
await this.renderComponent();
assert.dom('label').doesNotExist('Label is hidden when arg is not provided');
});
test('it should disable input when mountPath is not provided', async function (assert) {
this.mountPath = null;
await this.renderComponent();
assert.dom(input).isDisabled('Input is disabled when mountPath is not provided');
});
test('it should fetch suggestions for initial mount path', async function (assert) {
await this.renderComponent();
assert.dom(options).doesNotExist('Suggestions are hidden initially');
await click(input);
['foo/', 'my-secret'].forEach((secret, index) => {
assert.dom(option(index)).hasText(secret, 'Suggestion renders for initial mount path');
});
});
test('it should fetch secrets and update suggestions on mountPath change', async function (assert) {
this.apiStub.resolves({ keys: ['test1'] });
this.mountPath = 'foo/';
await this.renderComponent();
await click(input);
assert.dom(option()).hasText('test1', 'Suggestions are fetched and render on mountPath change');
});
test('it should filter current result set', async function (assert) {
await this.renderComponent();
await click(input);
await typeIn(input, 'sec');
assert.dom(options).exists({ count: 1 }, 'Correct number of options render based on input value');
assert.dom(option()).hasText('my-secret', 'Result set is filtered');
});
test('it should replace filter terms with full path to secret', async function (assert) {
await this.renderComponent();
await fillIn(input, 'sec');
await click(option());
assert.dom(input).hasValue('my-secret', 'Partial term replaced with selected secret');
await fillIn(input, '');
this.apiStub.resolves({ keys: ['secret-nested', 'bar', 'baz'] });
await click(option());
await fillIn(input, 'nest');
await click(option());
assert
.dom(input)
.hasValue('foo/secret-nested', 'Partial term in nested path replaced with selected secret');
});
test('it should fetch secrets at nested paths', async function (assert) {
await this.renderComponent();
this.apiStub.resolves({ keys: ['bar/'] });
await click(input);
await click(option());
assert.dom(input).hasValue('foo/', 'Input value updates on select');
assert.dom(option()).hasText('bar/', 'Suggestions are fetched at new path');
this.apiStub.resolves({ keys: ['baz/'] });
await click(option());
assert.dom(input).hasValue('foo/bar/', 'Input value updates on select');
assert.dom(option()).hasText('baz/', 'Suggestions are fetched at new path');
this.apiStub.resolves({ keys: ['nested-secret'] });
await typeIn(input, 'baz/');
assert.dom(option()).hasText('nested-secret', 'Suggestions are fetched at new path');
});
test('it should only render dropdown when suggestions exist', async function (assert) {
await this.renderComponent();
await click(input);
assert.dom(options).exists({ count: 2 }, 'Suggestions render');
await fillIn(input, 'bar');
assert.dom(options).doesNotExist('Drop down is hidden when there are no suggestions');
await fillIn(input, '');
assert.dom(options).exists({ count: 2 }, 'Suggestions render');
this.apiStub.resolves({ keys: [] });
await click(option());
assert.dom(options).doesNotExist('Drop down is hidden when there are no suggestions');
});
});