mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-16 19:47: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>
87 lines
3.3 KiB
JavaScript
87 lines
3.3 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import sinon from 'sinon';
|
|
import { setupRenderingTest } from 'vault/tests/helpers';
|
|
import { click, render, settled, typeIn } from '@ember/test-helpers';
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
import { SHAMIR_FORM } from 'vault/tests/helpers/components/shamir';
|
|
|
|
module('Integration | Component | shamir/form', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.submitSpy = sinon.spy();
|
|
});
|
|
|
|
test('it does calls callback only if key value present', async function (assert) {
|
|
await render(hbs`
|
|
<Shamir::Form @onSubmit={{this.submitSpy}} @progress={{0}} @threshold={{3}} />
|
|
`);
|
|
assert.dom(SHAMIR_FORM.submitButton).hasText('Submit', 'Submit button has default text');
|
|
await click(SHAMIR_FORM.submitButton);
|
|
assert.dom(SHAMIR_FORM.progress).doesNotExist('Hides progress bar if none made');
|
|
assert.ok(this.submitSpy.notCalled, 'onSubmit was not called');
|
|
await typeIn(SHAMIR_FORM.input, 'this-is-the-key');
|
|
assert.dom(SHAMIR_FORM.input).hasValue('this-is-the-key', 'input value set');
|
|
assert.dom(SHAMIR_FORM.inputLabel).hasText('Shamir key portion', 'label has default text');
|
|
await click(SHAMIR_FORM.submitButton);
|
|
assert.ok(
|
|
this.submitSpy.calledOnceWith({ key: 'this-is-the-key' }),
|
|
'onSubmit called with correct params'
|
|
);
|
|
assert.dom(SHAMIR_FORM.input).hasValue('', 'key value reset after submit');
|
|
|
|
await render(hbs`
|
|
<Shamir::Form @onSubmit={{this.submitSpy}} @progress={{0}} @threshold={{3}} @alwaysShowProgress={{true}} @buttonText="Do the thing" @inputLabel="Unseal key">
|
|
<div data-test-block-content>Hello</div>
|
|
</Shamir::Form>
|
|
`);
|
|
|
|
assert.dom('[data-test-block-content]').hasText('Hello', 'renders block content');
|
|
assert.dom(SHAMIR_FORM.submitButton).hasText('Do the thing', 'uses passed button text');
|
|
assert.dom(SHAMIR_FORM.inputLabel).hasText('Unseal key', 'uses passed inputLabel');
|
|
assert.dom(SHAMIR_FORM.otpInfo).doesNotExist('no OTP info shown');
|
|
assert
|
|
.dom(SHAMIR_FORM.progress)
|
|
.hasText('0/3 keys provided', 'displays textual progress when alwaysShowProgress=true');
|
|
});
|
|
|
|
test('it shows OTP info if provided', async function (assert) {
|
|
await render(hbs`
|
|
<Shamir::Form
|
|
@onSubmit={{this.submitSpy}}
|
|
@progress={{2}}
|
|
@threshold={{4}}
|
|
@otp="this-is-otp"
|
|
@inputLabel="Please input key"
|
|
>
|
|
<div data-test-block-content>Hello</div>
|
|
</Shamir::Form>
|
|
`);
|
|
|
|
assert.dom(SHAMIR_FORM.otpInfo).exists('shows OTP info');
|
|
assert.dom(SHAMIR_FORM.otpCode).hasText('this-is-otp', 'shows OTP code');
|
|
assert.dom(SHAMIR_FORM.progress).hasText('2/4 keys provided', 'displays textual progress');
|
|
assert.dom('[data-test-block-content]').hasText('Hello', 'renders block content');
|
|
});
|
|
|
|
test('renders errors provided', async function (assert) {
|
|
this.set('errors', ['first error', 'this is fine']);
|
|
await render(hbs`
|
|
<Shamir::Form
|
|
@onSubmit={{this.submitSpy}}
|
|
@errors={{this.errors}}
|
|
/>
|
|
`);
|
|
assert.dom(SHAMIR_FORM.error).exists({ count: 2 }, 'renders errors');
|
|
|
|
this.set('errors', []);
|
|
await settled();
|
|
assert.dom(SHAMIR_FORM.error).doesNotExist('errors cleared');
|
|
});
|
|
});
|