mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-18 12:37:02 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
100 lines
3.6 KiB
JavaScript
100 lines
3.6 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
import Service from '@ember/service';
|
|
import { click, find, render, typeIn } from '@ember/test-helpers';
|
|
import { selectChoose, clickTrigger } from 'ember-power-select/test-support/helpers';
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
import sinon from 'sinon';
|
|
|
|
const TITLE = 'Get Credentials';
|
|
const SEARCH_LABEL = 'Role to use';
|
|
|
|
const storeService = Service.extend({
|
|
query(modelType) {
|
|
return new Promise((resolve, reject) => {
|
|
switch (modelType) {
|
|
case 'database/role':
|
|
resolve([{ id: 'my-role', backend: 'database' }]);
|
|
break;
|
|
default:
|
|
reject({ httpStatus: 404, message: 'not found' });
|
|
break;
|
|
}
|
|
reject({ httpStatus: 404, message: 'not found' });
|
|
});
|
|
},
|
|
});
|
|
|
|
module('Integration | Component | get-credentials-card', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.router = this.owner.lookup('service:router');
|
|
this.router.transitionTo = sinon.stub();
|
|
|
|
this.owner.unregister('service:store');
|
|
this.owner.register('service:store', storeService);
|
|
this.set('title', TITLE);
|
|
this.set('searchLabel', SEARCH_LABEL);
|
|
});
|
|
|
|
hooks.afterEach(function () {
|
|
this.router.transitionTo.reset();
|
|
});
|
|
|
|
test('it shows a disabled button when no item is selected', async function (assert) {
|
|
await render(hbs`<GetCredentialsCard @title={{this.title}} @searchLabel={{this.searchLabel}}/>`);
|
|
assert.dom('[data-test-get-credentials]').isDisabled();
|
|
});
|
|
|
|
test('it shows button that can be clicked to credentials route when an item is selected', async function (assert) {
|
|
const models = ['database/role'];
|
|
this.set('models', models);
|
|
await render(
|
|
hbs`<GetCredentialsCard @title={{this.title}} @searchLabel={{this.searchLabel}} @placeholder="Search for a role..." @models={{this.models}} @type="role"/>`
|
|
);
|
|
assert
|
|
.dom('[data-test-component="search-select"]#search-input-role')
|
|
.exists('renders search select component by default');
|
|
assert
|
|
.dom('[data-test-component="search-select"]#search-input-role')
|
|
.hasText('Search for a role...', 'renders placeholder text passed to search select');
|
|
await clickTrigger();
|
|
await selectChoose('', 'my-role');
|
|
assert.dom('[data-test-get-credentials]').isEnabled();
|
|
await click('[data-test-get-credentials]');
|
|
assert.propEqual(
|
|
this.router.transitionTo.lastCall.args,
|
|
['vault.cluster.secrets.backend.credentials', 'my-role'],
|
|
'transitionTo is called with correct route and role name'
|
|
);
|
|
});
|
|
|
|
test('it renders input search field when renderInputSearch=true and shows placeholder text', async function (assert) {
|
|
await render(
|
|
hbs`<GetCredentialsCard @title={{this.title}} @renderInputSearch={{true}} @placeholder="secret/" @backend="kv" @type="secret"/>`
|
|
);
|
|
assert
|
|
.dom('[data-test-component="search-select"]')
|
|
.doesNotExist('does not render search select component');
|
|
assert.strictEqual(
|
|
find('[data-test-search-roles] input').placeholder,
|
|
'secret/',
|
|
'renders placeholder text passed to search input'
|
|
);
|
|
await typeIn('[data-test-search-roles] input', 'test');
|
|
assert.dom('[data-test-get-credentials]').isEnabled('submit button enables after typing input text');
|
|
await click('[data-test-get-credentials]');
|
|
assert.propEqual(
|
|
this.router.transitionTo.lastCall.args,
|
|
['vault.cluster.secrets.backend.show', 'test'],
|
|
'transitionTo is called with correct route and secret name'
|
|
);
|
|
});
|
|
});
|