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

Code before:
    // [BANDAID] navigate away to fix test failing on capabilities-self check before teardown
    await visit('/vault/secrets');
  });

  test('connection_url is decoded', async function (assert) {
    const backend = this.backend;
    const connection = await newConnection(
      backend,
      'mongodb-database-plugin',
      '{{username}}/{{password}}@mongo:1521/XEPDB1'
    );
    await navToConnection(backend, connection);
    assert
      .dom('[data-test-row-value="Connection URL"]')
      .hasText('{{username}}/{{password}}@mongo:1521/XEPDB1');
  });

  test('Role create form', async function (assert) {
    const backend = this.backend;
    // Connection needed for role fields
    await newConnection(backend);
    await rolePage.visitCreate({ backend });
    await rolePage.name('bar');
    assert
      .dom('[data-test-component="empty-state"]')
      .exists({ count: 1 }, 'One empty state exists before selections made');
    await clickTrigger('#database');
    assert.strictEqual(searchSelectComponent.options.length, 1, 'list shows existing connections so far');
    await selectChoose('#database', '.ember-power-select-option', 0);
    assert
      .dom('[data-test-component="empty-state"]')
      .exists({ count: 2 }, 'Two empty states exist before selections made');
    await rolePage.roleType('static');
    assert.dom('[data-test-component="empty-state"]').doesNotExist('Empty states go away');
    assert.dom('[data-test-input="username"]').exists('Username field appears for static role');
    assert
      .dom('[data-test-toggle-input="Rotation period"]')
      .exists('Rotation period field appears for static role');
    await rolePage.roleType('dynamic');
    assert
      .dom('[data-test-toggle-input="Generated credentials’s Time-to-Live (TTL)"]')
      .exists('TTL field exists for dynamic');
    assert
      .dom('[data-test-toggle-input="Generated credentials’s maximum Time-to-Live (Max TTL)"]')
      .exists('Max TTL field exists for dynamic');
    // Real connection (actual running db) required to save role, so we aren't testing that flow yet
  });

  test('root and limited access', async function (assert) {
    const backend = this.backend;
    const NO_ROLES_POLICY = `

Review comment (suggestion):
```suggestion
      .exists({ count: 1 }, 'One empty state exists before database selection is made');
```

Code after:
    // [BANDAID] navigate away to fix test failing on capabilities-self check before teardown
    await visit('/vault/secrets');
  });

  test('connection_url is decoded', async function (assert) {
    const backend = this.backend;
    const connection = await newConnection(
      backend,
      'mongodb-database-plugin',
      '{{username}}/{{password}}@mongo:1521/XEPDB1'
    );
    await navToConnection(backend, connection);
    assert
      .dom('[data-test-row-value="Connection URL"]')
      .hasText('{{username}}/{{password}}@mongo:1521/XEPDB1');
  });

  test('Role create form', async function (assert) {
    const backend = this.backend;
    // Connection needed for role fields
    await newConnection(backend);
    await rolePage.visitCreate({ backend });
    await rolePage.name('bar');
    assert
      .dom('[data-test-component="empty-state"]')
      .exists({ count: 1 }, 'One empty state exists before database selection is made');
    await clickTrigger('#database');
    assert.strictEqual(searchSelectComponent.options.length, 1, 'list shows existing connections so far');
    await selectChoose('#database', '.ember-power-select-option', 0);
    assert
      .dom('[data-test-component="empty-state"]')
      .exists({ count: 2 }, 'Two empty states exist after a database is selected');
    await rolePage.roleType('static');
    assert.dom('[data-test-component="empty-state"]').doesNotExist('Empty states go away');
    assert.dom('[data-test-input="username"]').exists('Username field appears for static role');
    assert
      .dom('[data-test-toggle-input="Rotation period"]')
      .exists('Rotation period field appears for static role');
    await rolePage.roleType('dynamic');
    assert
      .dom('[data-test-toggle-input="Generated credentials’s Time-to-Live (TTL)"]')
      .exists('TTL field exists for dynamic');
    assert
      .dom('[data-test-toggle-input="Generated credentials’s maximum Time-to-Live (Max TTL)"]')
      .exists('Max TTL field exists for dynamic');
    // Real connection (actual running db) required to save role, so we aren't testing that flow yet
  });

  test('root and limited access', async function (assert) {
    const backend = this.backend;
    const NO_ROLES_POLICY = `