Repository: hashicorp/vault
File: ui/tests/integration/components/recovery/page/snapshots-test.js (JavaScript)

Code before:

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) {
    this.nsService = this.owner.lookup('service:namespace');
    this.nsService.path = 'parent1/child1';
    this.server.get('/sys/internal/ui/namespaces', () => {
      return { data: { keys: ['parent1/', 'parent1/child1/'] } };
    });

    await render(hbs`<Recovery::Page::Snapshots @model={{this.model}}/>`);


Review comment (suggestion):
In the future, you can always make this a convenience function in the `beforeEach` hook so if the component args ever change, we only have to update it in one place rather than each test
```js
    this.renderComponent = () => render(hbs`<Recovery::Page::Snapshots @model={{this.model}}/>`);
    // in a test
    await this.renderComponent()
```

Code after:

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');