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

Code before:
      assert
        .dom('[data-test-credentials-warning]')
        .exists('shows warning about credentials only being available once');
      assert
        .dom(`[data-test-value-div="Username"] [data-test-masked-input]`)
        .hasText('***********', 'Username is masked');
      await click(`[data-test-value-div="Username"] [data-test-button="toggle-masked"]`);
      assert
        .dom(`[data-test-value-div="Username"] [data-test-masked-input]`)
        .hasText('generated-username', 'Username is generated');

      assert
        .dom(`[data-test-value-div="Password"] [data-test-masked-input]`)
        .hasText('***********', 'Password is masked');
      await click(`[data-test-value-div="Password"] [data-test-button="toggle-masked"]`);
      assert
        .dom(`[data-test-value-div="Password"] [data-test-masked-input]`)
        .hasText('generated-password', 'Password is generated');
      assert.dom(PAGE.infoRowValue('Lease Duration')).hasText('3600', 'shows lease duration from response');
      assert
        .dom(PAGE.infoRowValue('Lease ID'))
        .hasText(`database/creds/${roleName}/abcd`, 'shows lease ID from response');
    });
  });

  module('static roles', function () {
    test('set parent db to rotate static roles immediately, verify static role reflects that default', async function (assert) {
      this.connection = `connect-${this.backend}`;
      await visit(`/vault/secrets/${this.backend}/create`);
      await fillOutConnection(this.connection);
      await click(FORM.saveBtn);
      await visit(`/vault/secrets/${this.backend}/show/${this.connection}`);

      const roleName = 'static-role';
      await click(PAGE.addRole);
      assert.strictEqual(
        currentURL(),
        `/vault/secrets/${this.backend}/create?initialKey=${this.connection}&itemType=role`,
        'Takes you to create role page'
      );

      await fillIn(FORM.inputByAttr('name'), roleName);

      await fillIn(FORM.inputByAttr('type'), 'static');

      assert
        .dom('[data-test-toggle-subtext]')
        .containsText(`Vault will rotate the password for this static role on creation.`);
    });

    test('set parent db to not rotate static roles immediately, verify static role reflects that default', async function (assert) {

Review comment (suggestion):
will expand these two tests but opening review as-is now for any suggestions/opinions on this structure

Code after:
      assert
        .dom('[data-test-credentials-warning]')
        .exists('shows warning about credentials only being available once');
      assert
        .dom(`[data-test-value-div="Username"] [data-test-masked-input]`)
        .hasText('***********', 'Username is masked');
      await click(`[data-test-value-div="Username"] [data-test-button="toggle-masked"]`);
      assert
        .dom(`[data-test-value-div="Username"] [data-test-masked-input]`)
        .hasText('generated-username', 'Username is generated');

      assert
        .dom(`[data-test-value-div="Password"] [data-test-masked-input]`)
        .hasText('***********', 'Password is masked');
      await click(`[data-test-value-div="Password"] [data-test-button="toggle-masked"]`);
      assert
        .dom(`[data-test-value-div="Password"] [data-test-masked-input]`)
        .hasText('generated-password', 'Password is generated');
      assert.dom(PAGE.infoRowValue('Lease Duration')).hasText('3600', 'shows lease duration from response');
      assert
        .dom(PAGE.infoRowValue('Lease ID'))
        .hasText(`database/creds/${roleName}/abcd`, 'shows lease ID from response');
    });
  });

  module('static roles', function (hooks) {
    hooks.beforeEach(async function () {
      this.setup = async ({ toggleRotateOff = false }) => {
        this.connection = `connect-${this.backend}`;
        await visit(`/vault/secrets/${this.backend}/create`);
        await fillOutConnection(this.connection);
        if (toggleRotateOff) {
          await click('[data-test-toggle-input="toggle-skip_static_role_rotation_import"]');
        }
        await click(FORM.saveBtn);
        await visit(`/vault/secrets/${this.backend}/show/${this.connection}`);
      };
    });

    test('set parent db to rotate static roles immediately, verify static role reflects that default', async function (assert) {
      await this.setup({ toggleRotateOff: false });

      const roleName = 'static-role';
      await click(PAGE.addRole);
      assert.strictEqual(
        currentURL(),
        `/vault/secrets/${this.backend}/create?initialKey=${this.connection}&itemType=role`,
        'Takes you to create role page'
      );

      await fillIn(FORM.inputByAttr('name'), roleName);