From dc741f0f9c01e728f56a49f3a78da8d7cc9540cb Mon Sep 17 00:00:00 2001 From: Kianna <30884335+kiannaquach@users.noreply.github.com> Date: Thu, 26 Jan 2023 10:46:16 -0800 Subject: [PATCH] VAULT-12950 Add breacrumbs to create + edit roles and configure (#18861) --- .../addon/components/page/configure.hbs | 3 + .../components/page/role/create-and-edit.hbs | 3 + ui/lib/kubernetes/addon/routes/configure.js | 10 +++ .../kubernetes/addon/routes/roles/create.js | 10 +++ .../addon/routes/roles/role/edit.js | 11 ++++ .../kubernetes/addon/templates/configure.hbs | 2 +- .../addon/templates/roles/create.hbs | 2 +- .../addon/templates/roles/role/edit.hbs | 2 +- .../kubernetes/page/configure-test.js | 28 ++++++-- .../page/role/create-and-edit-test.js | 66 +++++++++++++++---- 10 files changed, 114 insertions(+), 23 deletions(-) diff --git a/ui/lib/kubernetes/addon/components/page/configure.hbs b/ui/lib/kubernetes/addon/components/page/configure.hbs index cab576c88..a5a934c7a 100644 --- a/ui/lib/kubernetes/addon/components/page/configure.hbs +++ b/ui/lib/kubernetes/addon/components/page/configure.hbs @@ -1,4 +1,7 @@ + + +

Configure kubernetes diff --git a/ui/lib/kubernetes/addon/components/page/role/create-and-edit.hbs b/ui/lib/kubernetes/addon/components/page/role/create-and-edit.hbs index 5e71eb5e8..89974f301 100644 --- a/ui/lib/kubernetes/addon/components/page/role/create-and-edit.hbs +++ b/ui/lib/kubernetes/addon/components/page/role/create-and-edit.hbs @@ -1,4 +1,7 @@ + + +

{{if @model.isNew "Create role" "Edit role"}} diff --git a/ui/lib/kubernetes/addon/routes/configure.js b/ui/lib/kubernetes/addon/routes/configure.js index abf6e4045..3ac8b1907 100644 --- a/ui/lib/kubernetes/addon/routes/configure.js +++ b/ui/lib/kubernetes/addon/routes/configure.js @@ -5,4 +5,14 @@ export default class KubernetesConfigureRoute extends FetchConfigRoute { const backend = this.secretMountPath.get(); return this.configModel || this.store.createRecord('kubernetes/config', { backend }); } + + setupController(controller, resolvedModel) { + super.setupController(controller, resolvedModel); + + controller.breadcrumbs = [ + { label: 'secrets', route: 'secrets', linkExternal: true }, + { label: resolvedModel.backend, route: 'overview' }, + { label: 'configure' }, + ]; + } } diff --git a/ui/lib/kubernetes/addon/routes/roles/create.js b/ui/lib/kubernetes/addon/routes/roles/create.js index be35f940f..9fd86f043 100644 --- a/ui/lib/kubernetes/addon/routes/roles/create.js +++ b/ui/lib/kubernetes/addon/routes/roles/create.js @@ -9,4 +9,14 @@ export default class KubernetesRolesCreateRoute extends Route { const backend = this.secretMountPath.get(); return this.store.createRecord('kubernetes/role', { backend }); } + + setupController(controller, resolvedModel) { + super.setupController(controller, resolvedModel); + + controller.breadcrumbs = [ + { label: resolvedModel.backend, route: 'overview' }, + { label: 'roles', route: 'roles' }, + { label: 'create' }, + ]; + } } diff --git a/ui/lib/kubernetes/addon/routes/roles/role/edit.js b/ui/lib/kubernetes/addon/routes/roles/role/edit.js index 503e555a1..008ca9be6 100644 --- a/ui/lib/kubernetes/addon/routes/roles/role/edit.js +++ b/ui/lib/kubernetes/addon/routes/roles/role/edit.js @@ -10,4 +10,15 @@ export default class KubernetesRoleEditRoute extends Route { const { name } = this.paramsFor('roles.role'); return this.store.queryRecord('kubernetes/role', { backend, name }); } + + setupController(controller, resolvedModel) { + super.setupController(controller, resolvedModel); + + controller.breadcrumbs = [ + { label: resolvedModel.backend, route: 'overview' }, + { label: 'roles', route: 'roles' }, + { label: resolvedModel.name, route: 'roles.role' }, + { label: 'edit' }, + ]; + } } diff --git a/ui/lib/kubernetes/addon/templates/configure.hbs b/ui/lib/kubernetes/addon/templates/configure.hbs index ca54b8924..ade9f95d5 100644 --- a/ui/lib/kubernetes/addon/templates/configure.hbs +++ b/ui/lib/kubernetes/addon/templates/configure.hbs @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/ui/lib/kubernetes/addon/templates/roles/create.hbs b/ui/lib/kubernetes/addon/templates/roles/create.hbs index 9c66bafe2..a5770ab85 100644 --- a/ui/lib/kubernetes/addon/templates/roles/create.hbs +++ b/ui/lib/kubernetes/addon/templates/roles/create.hbs @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/ui/lib/kubernetes/addon/templates/roles/role/edit.hbs b/ui/lib/kubernetes/addon/templates/roles/role/edit.hbs index 9c66bafe2..a5770ab85 100644 --- a/ui/lib/kubernetes/addon/templates/roles/role/edit.hbs +++ b/ui/lib/kubernetes/addon/templates/roles/role/edit.hbs @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/ui/tests/integration/components/kubernetes/page/configure-test.js b/ui/tests/integration/components/kubernetes/page/configure-test.js index 5c0cede41..a4c9f1cbc 100644 --- a/ui/tests/integration/components/kubernetes/page/configure-test.js +++ b/ui/tests/integration/components/kubernetes/page/configure-test.js @@ -27,11 +27,17 @@ module('Integration | Component | kubernetes | Page::Configure', function (hooks ...this.existingConfig, }); this.editModel = this.store.peekRecord('kubernetes/config', 'kubernetes-edit'); + this.breadcrumbs = [ + { label: 'secrets', route: 'secrets', linkExternal: true }, + { label: 'kubernetes', route: 'overview' }, + { label: 'configure' }, + ]; }); test('it should display proper options when toggling radio cards', async function (assert) { - await render(hbs``, { owner: this.engine }); - + await render(hbs``, { + owner: this.engine, + }); assert .dom('[data-test-radio-card="local"] input') .isChecked('Local cluster radio card is checked by default'); @@ -65,7 +71,9 @@ module('Integration | Component | kubernetes | Page::Configure', function (hooks return new Response(status, {}); }); - await render(hbs``, { owner: this.engine }); + await render(hbs``, { + owner: this.engine, + }); await click('[data-test-config] button'); assert @@ -100,7 +108,9 @@ module('Integration | Component | kubernetes | Page::Configure', function (hooks const stub = sinon.stub(this.owner.lookup('service:router'), 'transitionTo'); - await render(hbs``, { owner: this.engine }); + await render(hbs``, { + owner: this.engine, + }); await click('[data-test-radio-card="manual"]'); await fillIn('[data-test-input="kubernetesHost"]', this.existingConfig.kubernetes_host); @@ -118,7 +128,9 @@ module('Integration | Component | kubernetes | Page::Configure', function (hooks const stub = sinon.stub(this.owner.lookup('service:router'), 'transitionTo'); - await render(hbs``, { owner: this.engine }); + await render(hbs``, { + owner: this.engine, + }); assert.dom('[data-test-radio-card="manual"] input').isChecked('Manual config radio card is checked'); assert @@ -153,7 +165,9 @@ module('Integration | Component | kubernetes | Page::Configure', function (hooks }); this.model = this.store.peekRecord('kubernetes/config', 'kubernetes-edit-2'); - await render(hbs``, { owner: this.engine }); + await render(hbs``, { + owner: this.engine, + }); assert.dom('[data-test-radio-card="local"] input').isChecked('Local cluster radio card is checked'); assert @@ -175,7 +189,7 @@ module('Integration | Component | kubernetes | Page::Configure', function (hooks await render( hbs` - + `, { owner: this.engine } ); diff --git a/ui/tests/integration/components/kubernetes/page/role/create-and-edit-test.js b/ui/tests/integration/components/kubernetes/page/role/create-and-edit-test.js index fe09563f7..c91e5912e 100644 --- a/ui/tests/integration/components/kubernetes/page/role/create-and-edit-test.js +++ b/ui/tests/integration/components/kubernetes/page/role/create-and-edit-test.js @@ -32,10 +32,18 @@ module('Integration | Component | kubernetes | Page::Role::CreateAndEdit', funct }; this.newModel = store.createRecord('kubernetes/role', { backend: 'kubernetes-test' }); + this.breadcrumbs = [ + { label: this.newModel.backend, route: 'overview' }, + { label: 'roles', route: 'roles' }, + { label: 'create' }, + ]; }); test('it should display placeholder when generation preference is not selected', async function (assert) { - await render(hbs``, { owner: this.engine }); + await render( + hbs``, + { owner: this.engine } + ); assert .dom('[data-test-empty-state-title]') .hasText('Choose an option above', 'Empty state title renders'); @@ -49,7 +57,10 @@ module('Integration | Component | kubernetes | Page::Role::CreateAndEdit', funct }); test('it should display different form fields based on generation preference selection', async function (assert) { - await render(hbs``, { owner: this.engine }); + await render( + hbs``, + { owner: this.engine } + ); const commonFields = [ 'name', 'allowedKubernetesNamespaces', @@ -76,7 +87,10 @@ module('Integration | Component | kubernetes | Page::Role::CreateAndEdit', funct }); test('it should clear specific form fields when switching generation preference', async function (assert) { - await render(hbs``, { owner: this.engine }); + await render( + hbs``, + { owner: this.engine } + ); await click('[data-test-radio-card="basic"]'); await fillIn('[data-test-input="serviceAccountName"]', 'test'); @@ -129,7 +143,10 @@ module('Integration | Component | kubernetes | Page::Role::CreateAndEdit', funct this.server.post('/kubernetes-test/roles/role-1', () => assert.ok('POST request made to save role')); - await render(hbs``, { owner: this.engine }); + await render( + hbs``, + { owner: this.engine } + ); await click('[data-test-radio-card="basic"]'); await click('[data-test-save]'); assert.dom('[data-test-inline-error-message]').hasText('Name is required', 'Validation error renders'); @@ -150,7 +167,10 @@ module('Integration | Component | kubernetes | Page::Role::CreateAndEdit', funct for (const pref of ['basic', 'expanded', 'full']) { const trait = { expanded: 'withRoleName', full: 'withRoleRules' }[pref]; this.role = this.getRole(trait); - await render(hbs``, { owner: this.engine }); + await render( + hbs``, + { owner: this.engine } + ); assert.dom(`[data-test-radio-card="${pref}"] input`).isChecked('Correct radio card is checked'); assert.dom('[data-test-input="name"]').hasValue(this.role.name, 'Role name is populated'); const selector = { @@ -176,7 +196,10 @@ module('Integration | Component | kubernetes | Page::Role::CreateAndEdit', funct }); test('it should show and hide annotations and labels', async function (assert) { - await render(hbs``, { owner: this.engine }); + await render( + hbs``, + { owner: this.engine } + ); await click('[data-test-radio-card="basic"]'); assert.dom('[data-test-annotations]').doesNotExist('Annotations and labels are hidden'); @@ -194,12 +217,16 @@ module('Integration | Component | kubernetes | Page::Role::CreateAndEdit', funct test('it should expand annotations and labels when editing if they were populated', async function (assert) { this.role = this.getRole(); - await render(hbs``, { owner: this.engine }); + await render(hbs``, { + owner: this.engine, + }); assert .dom('[data-test-annotations]') .doesNotExist('Annotations and labels are collapsed initially when not defined'); this.role = this.getRole('withRoleRules'); - await render(hbs``, { owner: this.engine }); + await render(hbs``, { + owner: this.engine, + }); assert .dom('[data-test-annotations]') .exists('Annotations and labels are expanded initially when defined'); @@ -207,7 +234,9 @@ module('Integration | Component | kubernetes | Page::Role::CreateAndEdit', funct test('it should restore role rule example', async function (assert) { this.role = this.getRole('withRoleRules'); - await render(hbs``, { owner: this.engine }); + await render(hbs``, { + owner: this.engine, + }); const addedText = 'this will be add to the start of the first line in the JsonEditor'; await fillIn('[data-test-component="code-mirror-modifier"] textarea', addedText); await click('[data-test-restore-example]'); @@ -227,7 +256,10 @@ module('Integration | Component | kubernetes | Page::Role::CreateAndEdit', funct ); }); - await render(hbs``, { owner: this.engine }); + await render( + hbs``, + { owner: this.engine } + ); await click('[data-test-radio-card="full"]'); await fillIn('[data-test-input="name"]', 'role-1'); await fillIn('[data-test-select-template]', '5'); @@ -242,7 +274,10 @@ module('Integration | Component | kubernetes | Page::Role::CreateAndEdit', funct assert.strictEqual(payload.generated_role_rules, null, 'Generated roles rules are not set'); }); - await render(hbs``, { owner: this.engine }); + await render( + hbs``, + { owner: this.engine } + ); await click('[data-test-radio-card="full"]'); await fillIn('[data-test-input="name"]', 'role-1'); await fillIn('[data-test-select-template]', '5'); @@ -253,14 +288,19 @@ module('Integration | Component | kubernetes | Page::Role::CreateAndEdit', funct test('it should go back to list route and clean up model', async function (assert) { const unloadSpy = sinon.spy(this.newModel, 'unloadRecord'); - await render(hbs``, { owner: this.engine }); + await render( + hbs``, + { owner: this.engine } + ); await click('[data-test-cancel]'); assert.ok(unloadSpy.calledOnce, 'New model is unloaded on cancel'); assert.ok(this.transitionCalledWith('roles'), 'Transitions to roles list on cancel'); this.role = this.getRole(); const rollbackSpy = sinon.spy(this.role, 'rollbackAttributes'); - await render(hbs``, { owner: this.engine }); + await render(hbs``, { + owner: this.engine, + }); await click('[data-test-cancel]'); assert.ok(rollbackSpy.calledOnce, 'Attributes are rolled back for existing model on cancel'); assert.ok(this.transitionCalledWith('roles'), 'Transitions to roles list on cancel');