Skip to content

Commit

Permalink
pki-generate-toggle-group optionally takes @groups args
Browse files Browse the repository at this point in the history
  • Loading branch information
hashishaw committed Jan 26, 2023
1 parent f85c739 commit 10e3dc1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ui/lib/pki/addon/components/pki-generate-toggle-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PkiActionModel from 'vault/models/pki/action';

interface Args {
model: PkiActionModel;
groups: Map<[key: string], Array<string>> | null;
}

export default class PkiGenerateToggleGroupsComponent extends Component<Args> {
Expand All @@ -21,6 +22,7 @@ export default class PkiGenerateToggleGroupsComponent extends Component<Args> {
}

get groups() {
if (this.args.groups) return this.args.groups;
const groups = {
'Key parameters': this.keyParamFields,
'Subject Alternative Name (SAN) Options': ['altNames', 'ipSans', 'uriSans', 'otherSans'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const selectors = {
keys: '[data-test-toggle-group="Key parameters"]',
sanOptions: '[data-test-toggle-group="Subject Alternative Name (SAN) Options"]',
subjectFields: '[data-test-toggle-group="Additional subject fields"]',
toggleByName: (name) => `[data-test-toggle-group="${name}}]`,
};

module('Integration | Component | PkiGenerateToggleGroups', function (hooks) {
Expand Down Expand Up @@ -94,4 +95,32 @@ module('Integration | Component | PkiGenerateToggleGroups', function (hooks) {
assert.dom(`[data-test-input="${key}"]`).exists(`${key} input renders`);
});
});

test('it should render groups according to the passed @groups', async function (assert) {
assert.expect(11);
const fieldsA = ['ou', 'organization'];
const fieldsZ = ['country', 'locality', 'province', 'streetAddress', 'postalCode'];
this.set('groups', {
'Group A': fieldsA,
'Group Z': fieldsZ,
});
await render(hbs`<PkiGenerateToggleGroups @model={{this.model}} @groups={{this.groups}} />`, {
owner: this.engine,
});

assert.dom(selectors.toggleByName('Group A')).hasText('Group A', 'First group renders');
assert.dom(selectors.toggleByName('Group Z')).hasText('Group Z', 'Second group renders');

await click(selectors.toggleByName('Group A'));
assert.dom('[data-test-field]').exists({ count: fieldsA.length }, 'Correct number of fields render');
fieldsA.forEach((key) => {
assert.dom(`[data-test-input="${key}"]`).exists(`${key} input renders`);
});

await click(selectors.toggleByName('Group Z'));
assert.dom('[data-test-field]').exists({ count: fieldsZ.length }, 'Correct number of fields render');
fieldsZ.forEach((key) => {
assert.dom(`[data-test-input="${key}"]`).exists(`${key} input renders`);
});
});
});

0 comments on commit 10e3dc1

Please sign in to comment.