Repository: hashicorp/vault
File: ui/tests/integration/components/database-role-edit-test.js (JavaScript)

Code before:
    this.server.post('/sys/capabilities-self', capabilitiesStub('database/static-creds/my-role', ['create']));
    this.server.post(`/database/static-roles/my-static-role`, (schema, req) => {
      assert.true(true, 'request made to create static role');
      assert.propEqual(
        JSON.parse(req.requestBody),
        {
          path: 'static-roles',
          username: 'staticTestUser',
          password: 'testPassword',
          rotation_period: '172800s', // 2 days in seconds
          skip_import_rotation: true,
        },
        'it creates a static role with correct payload'
      );
    });

    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="create"/>`);
    await fillIn('[data-test-ttl-value="Rotation period"]', '2');
    await click('[data-test-toggle-input="toggle-skip_import_rotation"]');
    await fillIn('[data-test-input="password"]', 'testPassword'); // fill in password field

    await click('[data-test-secret-save]');

    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="show"/>`);
    assert.dom('[data-test-value-div="Rotate immediately"]').containsText('No');
    assert.dom('[data-test-value="Password"]').doesNotExist(); // verify password field doesn't show on details view

    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="edit"/>`);
    assert.dom('[data-test-icon="edit"]').exists(); // verify password field is enabled for edit & enable button is rendered bc role hasn't been rotated
  });

  test('enterprise: it should successfully create user that does rotate immediately & verify warning modal pops up', async function (assert) {
    this.version.type = 'enterprise';
    this.server.post('/sys/capabilities-self', capabilitiesStub('database/static-creds/my-role', ['create']));

    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="create"/>`);
    await click('[data-test-secret-save]');

    assert.dom('[data-test-issuer-warning]').exists(); // check if warning modal shows after clicking save
    await click('[data-test-issuer-save]'); // click continue button on modal

    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="show"/>`);
    assert.dom('[data-test-value-div="Rotate immediately"]').containsText('Yes');

    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="edit"/>`);
    assert.dom('[data-test-icon="edit"]').doesNotExist(); // verify password field is disabled for edit & enable button isn't rendered bc role has already been rotated
  });

  test('it should show Get credentials button when a user has the correct policy', async function (assert) {
    this.server.post('/sys/capabilities-self', capabilitiesStub('database/static-creds/my-role', ['read']));
    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="show"/>`);

Review comment (suggestion):
Same comment here, if these selectors already exists in general-selectors, replace them with that pattern.

Code after:
    this.version.type = 'enterprise';
    this.server.post('/sys/capabilities-self', capabilitiesStub('database/static-creds/my-role', ['create']));
    this.server.post(`/database/static-roles/my-static-role`, (schema, req) => {
      assert.true(true, 'request made to create static role');
      assert.propEqual(
        JSON.parse(req.requestBody),
        {
          path: 'static-roles',
          username: 'staticTestUser',
          password: 'testPassword',
          rotation_period: '172800s', // 2 days in seconds
          skip_import_rotation: true,
        },
        'it creates a static role with correct payload'
      );
    });

    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="create"/>`);
    await fillIn(GENERAL.ttl.input('Rotation period'), '2');
    await click(GENERAL.toggleInput('toggle-skip_import_rotation'));
    await fillIn(GENERAL.inputByAttr('password'), 'testPassword'); // fill in password field

    await click('[data-test-secret-save]');

    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="show"/>`);
    assert.dom(GENERAL.infoRowValue('Rotate immediately')).containsText('No');
    assert.dom(GENERAL.infoRowValue('password')).doesNotExist(); // verify password field doesn't show on details view

    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="edit"/>`);
    assert.dom(GENERAL.icon('edit')).exists(); // verify password field is enabled for edit & enable button is rendered bc role hasn't been rotated
  });

  test('enterprise: it should successfully create user that does rotate immediately & verify warning modal pops up', async function (assert) {
    this.version.type = 'enterprise';
    this.server.post('/sys/capabilities-self', capabilitiesStub('database/static-creds/my-role', ['create']));

    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="create"/>`);
    await click('[data-test-secret-save]');

    assert.dom('[data-test-issuer-warning]').exists(); // check if warning modal shows after clicking save
    await click('[data-test-issuer-save]'); // click continue button on modal

    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="show"/>`);
    assert.dom(GENERAL.infoRowValue('Rotate immediately')).containsText('Yes');

    this.modelStatic.last_vault_rotation = '2025-04-21T12:51:59.063124-04:00'; // Setting a sample rotation time here to simulate what returns from BE after rotation
    await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="edit"/>`);
    assert.dom(GENERAL.icon('edit')).doesNotExist(); // verify password field is disabled for edit & enable button isn't rendered bc role has already been rotated
  });

  test('it should show Get credentials button when a user has the correct policy', async function (assert) {