Repository: hashicorp/vault
File: ui/tests/acceptance/secrets/backend/totp/key-test.js (JavaScript)

Code before:
    const path = `totp-${this.uid}`;
    const keyName = 'totp-key';
    const issuer = 'totp-issuer';
    const accountName = 'totp-acount';

    assert.strictEqual(
      currentURL(),
      `/vault/secrets/${path}/list`,
      'After enabling totp secrets engine it navigates to keys list'
    );

    await click(SES.createSecret);
    await createVaultKey(keyName, issuer, accountName);
    await settled();
    await listPage.visit({ backend: path, id: keyName });
    await click('[data-test-popup-menu-trigger]');
    assert.dom('.hds-dropdown li:nth-of-type(1)').hasText('Details', 'first list item is "details"');
    await click('.hds-dropdown li:nth-of-type(1) a');
    assert.dom('.title').hasText(`TOTP key ${keyName}`);
    assert.dom('[data-test-totp-key-details]').exists();
  });

  test('it deletes a key via menu option', async function (assert) {
    // Setup TOTP engine
    const mountPath = `totp-${this.uid}`;
    await enablePage.enable('totp', mountPath);

    const path = `totp-${this.uid}`;
    const keyName = 'totp-key';
    const issuer = 'totp-issuer';
    const accountName = 'totp-acount';

    assert.strictEqual(
      currentURL(),
      `/vault/secrets/${path}/list`,
      'After enabling totp secrets engine it navigates to keys list'
    );

    await click(SES.createSecret);
    await createVaultKey(keyName, issuer, accountName);
    await settled();
    await listPage.visit({ backend: path, id: keyName });
    await click('[data-test-popup-menu-trigger]');
    assert.dom('.hds-dropdown li:nth-of-type(2)').hasText('Delete', 'first list item is "details"');
    await click('.hds-dropdown li:nth-of-type(2) [data-test-confirm-action-trigger]');
    await click('[data-test-confirm-button]');
    assert.dom(SES.secretLink(keyName)).doesNotExist(`${keyName}: key is no longer in the list`);
  });

  test('it creates a key with Vault as the provider', async function (assert) {
    // Setup TOTP engine

Review comment (security):
Instead of using ember-cli-page-object here, we can just directly use the mount backend helper [here](https://github.com/hashicorp/vault/blob/main/ui/tests/helpers/components/mount-backend-form-helpers.js#L10)

it might be useful to update the function to check the `currentUrl()` and visit `/vault/settings/auth/enable` if we're not already there. That would pave the way for us to eventually replace all instances of `enablePage` 🎉 

Code after:
    this.mountPath = `totp-${this.uid}`;
    this.path = `totp-${this.uid}`;
    this.keyName = 'totp-key';
    this.issuer = 'totp-issuer';
    this.accountName = 'totp-acount';
    this.url =
      'otpauth://totp/test-issuer:my-account?algorithm=SHA1&digits=6&issuer=test-issuer&period=30&secret=HICPOBIMFO4YYHFYX3QPVYUL2YEPVJKU';
    this.key = 'VCUDXBWFQXUEAIJYXH5YB62D5WFNQXFA';

    const flash = this.owner.lookup('service:flash-messages');
    this.flashSuccessSpy = sinon.spy(flash, 'success');

    await authPage.login();
    // Setup TOTP engine
    await visit('/vault/settings/mount-secret-backend');
    await mountBackend('totp', this.mountPath);
  });

  test('it views a key via menu option', async function (assert) {
    assert.strictEqual(
      currentURL(),
      `/vault/secrets/${this.path}/list`,
      'After enabling totp secrets engine it navigates to keys list'
    );

    await click(SES.createSecret);
    await createVaultKey(this.keyName, this.issuer, this.accountName);
    await visit(`/vault/secrets/${this.path}`);
    await click(GENERAL.menuTrigger);
    await click(`${SELECTORS.menuItem('details')}`);

    assert.dom('.title').hasText(`TOTP key ${this.keyName}`);
    assert.dom('[data-test-totp-key-details]').exists();

    assert.strictEqual(
      currentURL(),
      `/vault/secrets/${this.path}/show/${this.keyName}`,
      'After clicking details option it navigates to key detail view'
    );
  });

  test('it deletes a key via menu option', async function (assert) {
    await click(SES.createSecret);
    await createVaultKey(this.keyName, this.issuer, this.accountName);
    await waitUntil(() => currentURL() === `/vault/secrets/${this.path}/show/${this.keyName}`);
    await visit(`/vault/secrets/${this.path}`);
    await click(GENERAL.menuTrigger);
    await click(GENERAL.confirmTrigger);
    await click(GENERAL.confirmButton);
    assert.dom(SES.secretLink(this.keyName)).doesNotExist(`${this.keyName}: key is no longer in the list`);