mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-22 23:21:08 +02:00
* build out snapshots index route * add card for loaded snapshot * add tests * lint fix and remove logs * use api enum * lint fix * remove extra imports * tidy * routing updates * update tests * update styling * improve types * lint * add copyright header * update capability check * pull out header * add copyright headers * update url * Update ui/app/routes/vault/cluster/recovery/snapshots/snapshot.ts Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com> * test + error handling updates * update details route and add integration tests * tidy tests and pull out header title * lint * test updates --------- Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
119 lines
4.3 KiB
JavaScript
119 lines
4.3 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';
|
|
import { dateFormat } from 'core/helpers/date-format';
|
|
|
|
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');
|
|
});
|
|
|
|
// TODO will move over to separate test file with further feature work
|
|
test('it displays loaded snapshot card', async function (assert) {
|
|
const expiryDate = dateFormat(
|
|
[new Date('2023-09-20T10:51:53.961861096-04:00'), 'MMMM do yyyy, h:mm:ss a'],
|
|
{}
|
|
);
|
|
|
|
this.model = {
|
|
snapshot_id: '6ecc06a9-3592-26f9-40cb-8d1b511890a6',
|
|
status: 'ready',
|
|
expires_at: expiryDate,
|
|
};
|
|
|
|
await render(hbs`<Recovery::Page::Snapshots::SnapshotManage @model={{this.model}}/>`);
|
|
|
|
assert.dom(SELECTORS.badge('status')).hasText('ready', 'status badge renders');
|
|
});
|
|
});
|