vault/ui/tests/integration/components/ldap/page/configure-test.js
claire bontempo 43258c28fa
UI: HDS adoption replace <Modal> (#23382)
* UI: Part 1 - hds adoption replace <Modal> (#23363)

* replace policy-form modal

* replace clients/attribution modal

* clients/config modal

* scope form odal

* remove button type

* include toolbar to match other example templates

* rotate credentials modal

* add toolbar button class for hds buttons

* transformation-edit modal

* add back test selector

* add route arg to button!

* update link status

* fix link-status tests

* remove prevent default

* update db tests

* update tests

* use page alert for hcp link status banner

* fix scopy button selector

* fix sidebar test

* change to neutral banner

* UI: Part 2 - hds adoption replace <Modal>  (#23398)

* upgrade HDS library (adds support for snippet containers

* cleanup flight icons

* replace transit key action modals

* re-add deps as devDeps

* remove line

* address transit tests

* UI: Part 3 - hds adoption replace <Modal> (#23415)

* cleanup css

* cleanup extra type attr

* masked input download modal

* use Hds::Button in  download button"

* fix size of modal

* tiny icon fix

* refactor download button to always render download icon

* update tests

* UI: Part 3.5 - hds adoption replace <Modal> (#23448)

* replication-promote modal

* replication component modals

* replication add secondary modal

* move update text for diff

* UI: Part 4 - hds adoption replace <Modal>  (#23451)

* k8 configure modal

* kv delete modal

* ldap modals

* pki modals

* add trash icon

* move deps

* UI: Part 5 - hds adoption replace <Modal> (#23471)

* replace confirmation modals
---------

* UI: Part 6 - hds adoption replace <Modal>  (#23484)

* search select with modal

* policy search select modal

* replace date dropdown for client dashboard

* change padding to top

* update policy example args

* lolllll test typo wow

* update dropdown tests

* shamir flow modals!

* add one more container

* update test selectors

* UI: Final hds adoption replace <Modal> cleanup PR (#23522)

* search select with modal

* policy search select modal

* replace date dropdown for client dashboard

* change padding to top

* update policy example args

* lolllll test typo wow

* update dropdown tests

* shamir flow modals!

* add one more container

* update test selectors

* remove wormhole and modal component

* fix selectors

* uninstall wormhole

* remove shamir-modal-flow class

* fix confirm modal test

* fix pki and kv test

* fix toolbar selector kv

* client and download button test

* fix-confirmation-modal-padding

* fix replication modal tests so relevant modal opens (#23540)

* more confirmation modal tests

* adds changelog
2023-10-06 22:06:36 +00:00

148 lines
5.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { setupEngine } from 'ember-engines/test-support';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { render, click, fillIn } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { Response } from 'miragejs';
import sinon from 'sinon';
import { generateBreadcrumbs } from 'vault/tests/helpers/ldap';
const selectors = {
radioCard: '[data-test-radio-card="OpenLDAP"]',
save: '[data-test-config-save]',
binddn: '[data-test-field="binddn"] input',
bindpass: '[data-test-field="bindpass"] input',
};
module('Integration | Component | ldap | Page::Configure', function (hooks) {
setupRenderingTest(hooks);
setupEngine(hooks, 'ldap');
setupMirage(hooks);
const fillAndSubmit = async (rotate) => {
await click(selectors.radioCard);
await fillIn(selectors.binddn, 'foo');
await fillIn(selectors.bindpass, 'bar');
await click(selectors.save);
await click(`[data-test-save-${rotate}-rotate]`);
};
hooks.beforeEach(function () {
this.store = this.owner.lookup('service:store');
this.newModel = this.store.createRecord('ldap/config', { backend: 'ldap-new' });
this.existingConfig = {
schema: 'openldap',
binddn: 'cn=vault,ou=Users,dc=hashicorp,dc=com',
bindpass: 'foobar',
};
this.store.pushPayload('ldap/config', {
modelName: 'ldap/config',
backend: 'ldap-edit',
...this.existingConfig,
});
this.editModel = this.store.peekRecord('ldap/config', 'ldap-edit');
this.breadcrumbs = generateBreadcrumbs('ldap', 'configure');
this.model = this.newModel; // most of the tests use newModel but set this to editModel when needed
this.renderComponent = () => {
return render(hbs`<Page::Configure @model={{this.model}} @breadcrumbs={{this.breadcrumbs}} />`, {
owner: this.engine,
});
};
this.transitionStub = sinon.stub(this.owner.lookup('service:router'), 'transitionTo');
});
test('it should render empty state when schema is not selected', async function (assert) {
await this.renderComponent();
assert.dom('[data-test-empty-state-title]').hasText('Choose an option', 'Empty state title renders');
assert
.dom('[data-test-empty-state-message]')
.hasText('Pick an option above to see available configuration options', 'Empty state title renders');
assert.dom(selectors.save).isDisabled('Save button is disabled when schema is not selected');
await click(selectors.radioCard);
assert
.dom('[data-test-component="empty-state"]')
.doesNotExist('Empty state is hidden when schema is selected');
});
test('it should render validation messages for invalid form', async function (assert) {
await this.renderComponent();
await click(selectors.radioCard);
await click(selectors.save);
assert
.dom('[data-test-field="binddn"] [data-test-inline-error-message]')
.hasText('Administrator distinguished name is required.', 'Validation message renders for binddn');
assert
.dom('[data-test-field="bindpass"] [data-test-inline-error-message]')
.hasText('Administrator password is required.', 'Validation message renders for bindpass');
assert
.dom('[data-test-invalid-form-message] p')
.hasText('There are 2 errors with this form.', 'Invalid form message renders');
});
test('it should save new configuration without rotating root password', async function (assert) {
assert.expect(2);
this.server.post('/ldap-new/config', () => {
assert.ok(true, 'POST request made to save config');
return new Response(204, {});
});
await this.renderComponent();
await fillAndSubmit('without');
assert.ok(
this.transitionStub.calledWith('vault.cluster.secrets.backend.ldap.configuration'),
'Transitions to configuration route on save success'
);
});
test('it should save new configuration and rotate root password', async function (assert) {
assert.expect(3);
this.server.post('/ldap-new/config', () => {
assert.ok(true, 'POST request made to save config');
return new Response(204, {});
});
this.server.post('/ldap-new/rotate-root', () => {
assert.ok(true, 'POST request made to rotate root password');
return new Response(204, {});
});
await this.renderComponent();
await fillAndSubmit('with');
assert.ok(
this.transitionStub.calledWith('vault.cluster.secrets.backend.ldap.configuration'),
'Transitions to configuration route on save success'
);
});
test('it should populate fields when editing form', async function (assert) {
this.model = this.editModel;
await this.renderComponent();
assert.dom(selectors.radioCard).isChecked('Correct radio card is checked for schema value');
assert.dom(selectors.binddn).hasValue(this.existingConfig.binddn, 'binddn value renders');
await fillIn(selectors.binddn, 'foobar');
await click('[data-test-config-cancel]');
assert.strictEqual(this.model.binddn, this.existingConfig.binddn, 'Model is rolled back on cancel');
assert.ok(
this.transitionStub.calledWith('vault.cluster.secrets.backend.ldap.configuration'),
'Transitions to configuration route on save success'
);
});
});