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

Code before:
    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}}/>`);

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

    this.nsService.path = '';
  });

  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(

Review comment (refactor):
I believe if you set the namespace service as a const you can remove this cleanup...which could eventually become a flake later if timing gets off

Code after:
    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');
  });