Vault Automation 9538905b86
UI: Build snapshot manage form (#8675) (#8957)
* build mirage handler for snapshot recovery endpoints

* WIP add namespace and mount fields to read/recover form

* change option to engine object

* update badge color according to status and make loaded snapshot reqs within root ns

* wip read reqs and view

* add recovery banner and form validation

* move read view into modal

* tidying

* organize

* tests

* style fixes

* error handling

* tests

* update requests with snapshot params

* style fix

* yarn lock update for latest spec updates

* tests

* add polling for snapshot status

* disable button when not in ready state

* reset errors

* don't poll during tests

* remove todo

* test updates

* fix ns select + test

* remove todo

* styling, tidy, mount options, engine types

* lots of tidying, add manual mount input, slower polling

* make read + recover requests in selected namespace

* link to child ns if recovering there

* test updates

* centralize recovery data values

* type, state and error improvements

---------

Co-authored-by: claire bontempo <cbontempo@hashicorp.com>
Co-authored-by: Lane Wetmore <lane.wetmore@hashicorp.com>
2025-09-03 12:22:30 -06:00

100 lines
3.7 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupRenderingTest } from 'vault/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
const SELECTORS = {
badge: (name) => `[data-test-badge="${name}"]`,
};
module('Integration | Component | recovery/snapshots', function (hooks) {
setupRenderingTest(hooks);
setupMirage(hooks);
hooks.beforeEach(function () {
this.model = {
snapshots: [],
canLoadSnapshot: false,
};
this.version = this.owner.lookup('service:version');
this.version.type = 'enterprise';
});
test('it displays empty state in CE', async function (assert) {
this.version.type = 'community';
await render(hbs`<Recovery::Page::Snapshots @model={{this.model}}/>`);
assert
.dom(GENERAL.emptyStateTitle)
.hasText('Secrets Recovery is an enterprise feature', 'CE empty state title renders');
assert
.dom(GENERAL.emptyStateMessage)
.hasText(
'Secrets Recovery allows you to restore accidentally deleted or lost secrets from a snapshot. The snapshots can be provided via upload or loaded from external storage.',
'CE empty state message renders'
);
assert
.dom(GENERAL.emptyStateActions)
.hasText('Learn more about upgrading', 'CE empty state action renders');
assert.dom(SELECTORS.badge('enterprise')).exists();
});
test('it displays empty state in non root namespace', async function (assert) {
const nsService = this.owner.lookup('service:namespace');
nsService.setNamespace('test-ns');
await render(hbs`<Recovery::Page::Snapshots @model={{this.model}}/>`);
assert
.dom(GENERAL.emptyStateTitle)
.hasText('Snapshot upload is restricted', 'non root namespace empty state title renders');
assert
.dom(GENERAL.emptyStateMessage)
.hasText(
'Snapshot uploading is only available in root namespace. Please navigate to root and upload your snapshot. ',
'non root empty state message renders'
);
assert
.dom(GENERAL.emptyStateActions)
.hasText('Take me to root namespace', 'non root empty state action renders');
});
test('it displays empty state when user cannot load snapshot', async function (assert) {
await render(hbs`<Recovery::Page::Snapshots @model={{this.model}}/>`);
assert.dom(GENERAL.emptyStateTitle).hasText('No snapshot available', 'empty state title renders');
assert
.dom(GENERAL.emptyStateMessage)
.hasText(
'Ready to restore secrets? Please contact your admin to either upload a snapshot or grant you uploading permissions to get started.',
'empty state message renders'
);
assert
.dom(GENERAL.emptyStateActions)
.hasText('Learn more about Secrets Recovery', 'empty state action renders');
});
test('it displays empty state when user can load snapshot', async function (assert) {
this.model.canLoadSnapshot = true;
await render(hbs`<Recovery::Page::Snapshots @model={{this.model}}/>`);
assert
.dom(GENERAL.emptyStateTitle)
.hasText('Upload a snapshot to get started', 'empty state title renders');
assert
.dom(GENERAL.emptyStateMessage)
.hasText(
'Secrets Recovery allows you to restore accidentally deleted or lost secrets from a snapshot. The snapshots can be provided via upload or loaded from external storage.',
'empty state message renders'
);
assert.dom(GENERAL.emptyStateActions).hasText('Upload snapshot', 'empty state action renders');
});
});