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

Code before:
import { spy } from 'sinon';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
import { SECRET_ENGINE_SELECTORS as SES } from 'vault/tests/helpers/secret-engine/secret-engine-selectors';
import { setupMirage } from 'ember-cli-mirage/test-support';

module('Acceptance | totp key backend', function (hooks) {
  setupApplicationTest(hooks);
  setupMirage(hooks);

  const createVaultKey = async (keyName, issuer, accountName) => {
    await fillIn(GENERAL.inputByAttr('name'), keyName);
    await fillIn(GENERAL.inputByAttr('issuer'), issuer);
    await fillIn(GENERAL.inputByAttr('accountName'), accountName);
    await click('[data-test-totp-create]');
  };

  hooks.beforeEach(function () {
    const flash = this.owner.lookup('service:flash-messages');
    this.flashSuccessSpy = spy(flash, 'success');
    this.flashDangerSpy = spy(flash, 'danger');

    this.uid = uuidv4();
    return authPage.login();
  });

  test('it views 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(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();
  });

Review comment (suggestion):
great job writing acceptance tests to test navigational items! this is exactly what we want to use these for

Code after:
import { v4 as uuidv4 } from 'uuid';
import sinon from 'sinon';

const SELECTORS = {
  menuItem: (item) => `[data-test-popup-menu="${item}"]`,
};

module('Acceptance | totp key backend', function (hooks) {
  setupApplicationTest(hooks);

  const createVaultKey = async (keyName, issuer, accountName) => {
    await fillIn(GENERAL.inputByAttr('name'), keyName);
    await fillIn(GENERAL.inputByAttr('issuer'), issuer);
    await fillIn(GENERAL.inputByAttr('accountName'), accountName);
    await click(GENERAL.saveButton);
    await click(GENERAL.backButton);
  };

  const createNonVaultKey = async (keyName, issuer, accountName, url, key) => {
    await click('[data-test-radio="Other service"]');
    await fillIn(GENERAL.inputByAttr('name'), keyName);
    await fillIn(GENERAL.inputByAttr('issuer'), issuer);
    await fillIn(GENERAL.inputByAttr('accountName'), accountName);
    if (url) await fillIn(GENERAL.inputByAttr('url'), url);
    if (key) await fillIn(GENERAL.inputByAttr('key'), key);
    await click(GENERAL.saveButton);
  };

  hooks.beforeEach(async function () {
    this.uid = uuidv4();
    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(),