mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-15 11:07:00 +02:00
* 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
168 lines
6.4 KiB
JavaScript
168 lines
6.4 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
import { render, find, click, fillIn } from '@ember/test-helpers';
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
import sinon from 'sinon';
|
|
|
|
module('Integration | Component | client count config', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
setupMirage(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.router = this.owner.lookup('service:router');
|
|
this.transitionStub = sinon.stub(this.router, 'transitionTo');
|
|
const store = this.owner.lookup('service:store');
|
|
this.createModel = (enabled = 'enable', reporting_enabled = false, minimum_retention_months = 24) => {
|
|
store.pushPayload('clients/config', {
|
|
modelName: 'clients/config',
|
|
id: 'foo',
|
|
data: {
|
|
enabled,
|
|
reporting_enabled,
|
|
minimum_retention_months,
|
|
retention_months: 24,
|
|
},
|
|
});
|
|
this.model = store.peekRecord('clients/config', 'foo');
|
|
};
|
|
});
|
|
|
|
test('it shows the table with the correct rows by default', async function (assert) {
|
|
this.createModel();
|
|
|
|
await render(hbs`<Clients::Config @model={{this.model}} />`);
|
|
|
|
assert.dom('[data-test-clients-config-table]').exists('Clients config table exists');
|
|
const rows = document.querySelectorAll('.info-table-row');
|
|
assert.strictEqual(rows.length, 2, 'renders 2 info table rows');
|
|
assert.ok(
|
|
find('[data-test-row-value="Usage data collection"]').textContent.includes('On'),
|
|
'Enabled value matches model'
|
|
);
|
|
assert.ok(
|
|
find('[data-test-row-value="Retention period"]').textContent.includes('24'),
|
|
'Retention period value matches model'
|
|
);
|
|
});
|
|
|
|
test('it should function in edit mode when reporting is disabled', async function (assert) {
|
|
assert.expect(12);
|
|
|
|
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
|
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
|
const expected = { enabled: 'enable', retention_months: 24 };
|
|
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
|
|
return {};
|
|
});
|
|
|
|
this.createModel('disable');
|
|
|
|
await render(hbs`
|
|
<Clients::Config @model={{this.model}} @mode="edit" />
|
|
`);
|
|
|
|
assert.dom('[data-test-input="enabled"]').isNotChecked('Data collection checkbox is not checked');
|
|
assert
|
|
.dom('label[for="enabled"]')
|
|
.hasText('Data collection is off', 'Correct label renders when data collection is off');
|
|
assert.dom('[data-test-input="retentionMonths"]').hasValue('24', 'Retention months render');
|
|
|
|
await click('[data-test-input="enabled"]');
|
|
await fillIn('[data-test-input="retentionMonths"]', -3);
|
|
await click('[data-test-clients-config-save]');
|
|
assert
|
|
.dom('[data-test-inline-error-message]')
|
|
.hasText(
|
|
'Retention period must be greater than or equal to 24.',
|
|
'Validation error shows for incorrect retention period'
|
|
);
|
|
|
|
await fillIn('[data-test-input="retentionMonths"]', 24);
|
|
await click('[data-test-clients-config-save]');
|
|
assert
|
|
.dom('[data-test-clients-config-modal="title"]')
|
|
.hasText('Turn usage tracking on?', 'Correct modal title renders');
|
|
assert.dom('[data-test-clients-config-modal="on"]').exists('Correct modal description block renders');
|
|
|
|
await click('[data-test-clients-config-modal="continue"]');
|
|
assert.ok(
|
|
this.transitionStub.calledWith('vault.cluster.clients.config'),
|
|
'Route transitions correctly on save success'
|
|
);
|
|
|
|
await click('[data-test-input="enabled"]');
|
|
await click('[data-test-clients-config-save]');
|
|
assert.dom('[data-test-clients-config-modal]').exists('Modal renders');
|
|
assert
|
|
.dom('[data-test-clients-config-modal="title"]')
|
|
.hasText('Turn usage tracking off?', 'Correct modal title renders');
|
|
assert.dom('[data-test-clients-config-modal="off"]').exists('Correct modal description block renders');
|
|
|
|
await click('[data-test-clients-config-modal="cancel"]');
|
|
assert.dom('[data-test-clients-config-modal]').doesNotExist('Modal is hidden on cancel');
|
|
});
|
|
|
|
test('it should function in edit mode when reporting is enabled', async function (assert) {
|
|
assert.expect(6);
|
|
|
|
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
|
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
|
const expected = { enabled: 'enable', retention_months: 48 };
|
|
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
|
|
return {};
|
|
});
|
|
|
|
this.createModel('enable', true, 24);
|
|
|
|
await render(hbs`
|
|
<Clients::Config @model={{this.model}} @mode="edit" />
|
|
`);
|
|
|
|
assert.dom('[data-test-input="enabled"]').isChecked('Data collection input is checked');
|
|
assert
|
|
.dom('[data-test-input="enabled"]')
|
|
.isDisabled('Data collection input disabled when reporting is enabled');
|
|
assert
|
|
.dom('label[for="enabled"]')
|
|
.hasText('Data collection is on', 'Correct label renders when data collection is on');
|
|
assert.dom('[data-test-input="retentionMonths"]').hasValue('24', 'Retention months render');
|
|
|
|
await fillIn('[data-test-input="retentionMonths"]', 5);
|
|
await click('[data-test-clients-config-save]');
|
|
assert
|
|
.dom('[data-test-inline-error-message]')
|
|
.hasText(
|
|
'Retention period must be greater than or equal to 24.',
|
|
'Validation error shows for incorrect retention period'
|
|
);
|
|
|
|
await fillIn('[data-test-input="retentionMonths"]', 48);
|
|
await click('[data-test-clients-config-save]');
|
|
});
|
|
|
|
test('it should not show modal when data collection is not changed', async function (assert) {
|
|
assert.expect(1);
|
|
|
|
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
|
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
|
const expected = { enabled: 'enable', retention_months: 24 };
|
|
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
|
|
return {};
|
|
});
|
|
|
|
this.createModel();
|
|
|
|
await render(hbs`
|
|
<Clients::Config @model={{this.model}} @mode="edit" />
|
|
`);
|
|
await fillIn('[data-test-input="retentionMonths"]', 24);
|
|
await click('[data-test-clients-config-save]');
|
|
});
|
|
});
|