vault/ui/tests/integration/components/pki/pki-not-valid-after-form-test.js
hashicorp-copywrite[bot] 0b12cdcfd1
[COMPLIANCE] License changes (#22290)
* 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>
2023-08-10 18:14:03 -07:00

139 lines
5.1 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 } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupEngine } from 'ember-engines/test-support';
import { SELECTORS } from 'vault/tests/helpers/pki/pki-not-valid-after-form';
module('Integration | Component | pki-not-valid-after-form', function (hooks) {
setupRenderingTest(hooks);
setupEngine(hooks, 'pki');
hooks.beforeEach(function () {
this.store = this.owner.lookup('service:store');
this.model = this.store.createRecord('pki/role', { backend: 'pki' });
this.attr = {
helpText: '',
options: {
helperTextEnabled: 'toggled on and shows text',
},
};
});
test('it should render the component with ttl selected by default', async function (assert) {
assert.expect(3);
await render(
hbs`
<div class="has-top-margin-xxl">
<PkiNotValidAfterForm
@model={{this.model}}
@attr={{this.attr}}
/>
</div>
`,
{ owner: this.engine }
);
assert.dom(SELECTORS.ttlForm).exists('shows the TTL picker');
assert.dom(SELECTORS.ttlTimeInput).hasValue('', 'default TTL is empty');
assert.dom(SELECTORS.radioTtl).isChecked('ttl is selected by default');
});
test('it clears and resets model properties from cache when changing radio selection', async function (assert) {
await render(
hbs`
<div class="has-top-margin-xxl">
<PkiNotValidAfterForm
@model={{this.model}}
@attr={{this.attr}}
/>
</div>
`,
{ owner: this.engine }
);
assert.dom(SELECTORS.radioTtl).isChecked('notBeforeDate radio is selected');
assert.dom(SELECTORS.ttlForm).exists({ count: 1 }, 'shows TTL form');
assert.dom(SELECTORS.radioDate).isNotChecked('NotAfter selection not checked');
assert.dom(SELECTORS.dateInput).doesNotExist('does not show date input field');
await click(SELECTORS.radioDateLabel);
assert.dom(SELECTORS.radioDate).isChecked('selects NotAfter radio when label clicked');
assert.dom(SELECTORS.dateInput).exists({ count: 1 }, 'shows date input field');
assert.dom(SELECTORS.radioTtl).isNotChecked('notBeforeDate radio is deselected');
assert.dom(SELECTORS.ttlForm).doesNotExist('hides TTL form');
const utcDate = '1994-11-05';
const notAfterExpected = '1994-11-05T00:00:00.000Z';
const ttlDate = 1;
await fillIn('[data-test-input="not_after"]', utcDate);
assert.strictEqual(
this.model.notAfter,
notAfterExpected,
'sets the model property notAfter when this value is selected and filled in.'
);
await click('[data-test-radio-button="ttl"]');
assert.strictEqual(
this.model.notAfter,
'',
'The notAfter is cleared on the model because the radio button was selected.'
);
await fillIn('[data-test-ttl-value="TTL"]', ttlDate);
assert.strictEqual(
this.model.ttl,
'1s',
'The ttl is now saved on the model because the radio button was selected.'
);
await click('[data-test-radio-button="not_after"]');
assert.strictEqual(this.model.ttl, '', 'TTL is cleared after radio select.');
assert.strictEqual(this.model.notAfter, notAfterExpected, 'notAfter gets populated from local cache');
});
test('Form renders properly for edit when TTL present', async function (assert) {
this.model = this.store.createRecord('pki/role', { backend: 'pki', ttl: 6000 });
await render(
hbs`
<div class="has-top-margin-xxl">
<PkiNotValidAfterForm
@model={{this.model}}
@attr={{this.attr}}
/>
</div>
`,
{ owner: this.engine }
);
assert.dom(SELECTORS.radioTtl).isChecked('notBeforeDate radio is selected');
assert.dom(SELECTORS.ttlForm).exists({ count: 1 }, 'shows TTL form');
assert.dom(SELECTORS.radioDate).isNotChecked('NotAfter selection not checked');
assert.dom(SELECTORS.dateInput).doesNotExist('does not show date input field');
assert.dom(SELECTORS.ttlTimeInput).hasValue('100', 'TTL value is correctly shown');
assert.dom(SELECTORS.ttlUnitInput).hasValue('m', 'TTL unit is correctly shown');
});
test('Form renders properly for edit when notAfter present', async function (assert) {
const utcDate = '1994-11-05T00:00:00.000Z';
this.model = this.store.createRecord('pki/role', { backend: 'pki', notAfter: utcDate });
await render(
hbs`
<div class="has-top-margin-xxl">
<PkiNotValidAfterForm
@model={{this.model}}
@attr={{this.attr}}
/>
</div>
`,
{ owner: this.engine }
);
assert.dom(SELECTORS.radioDate).isChecked('notAfter radio is selected');
assert.dom(SELECTORS.dateInput).exists({ count: 1 }, 'shows date picker');
assert.dom(SELECTORS.radioTtl).isNotChecked('ttl radio not selected');
assert.dom(SELECTORS.ttlForm).doesNotExist('does not show date TTL picker');
// Due to timezones, can't check specific match on input date
assert.dom(SELECTORS.dateInput).hasAnyValue('date input shows date');
});
});