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

Code before:
    // Check with restricted permissions
    await authPage.login(token);
    await click('[data-test-sidebar-nav-link="Secrets Engines"]');
    assert.dom(`[data-test-secrets-backend-link="${backend}"]`).exists('Shows backend on secret list page');
    await navToConnection(backend, connection);
    assert.strictEqual(
      currentURL(),
      `/vault/secrets/${backend}/show/${connection}`,
      'Allows reading connection'
    );
    assert
      .dom('[data-test-database-connection-delete]')
      .doesNotExist('Delete button does not show due to permissions');
    assert
      .dom('[data-test-database-connection-reset]')
      .doesNotExist('Reset button does not show due to permissions');
    assert.dom('[data-test-secret-create]').doesNotExist('Add role button does not show due to permissions');
    assert.dom('[data-test-edit-link]').doesNotExist('Edit button does not show due to permissions');
    await visit(`/vault/secrets/${backend}/overview`);
    assert.dom('[data-test-overview-card="Connections"]').exists('Connections card exists on overview');
    assert
      .dom('[data-test-overview-card="Roles"]')
      .doesNotExist('Roles card does not exist on overview w/ policy');
    assert.dom('.overview-card h2').hasText('1', 'Lists the correct number of connections');
    // confirm get credentials card is an option to select. Regression bug.
    await typeIn('.ember-text-field', 'blah');
    assert.dom('[data-test-get-credentials]').isEnabled();
    // [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

Review comment (performance):
A note: We have been slowly adding generic selectors to our `tests/helpers/general-selectors.ts` file, where this specific selector now exists. This file however, is old enough we don't import it. In the future if you run into a selector change, check if the test file imports `import { GENERAL } from 'vault/tests/helpers/general-selectors';`. If it does then you could do something like `GENERAL.inputSearch('search-input-role')`. Again, not something to change here, but more a note for the future.

Code after:
    assert.dom('[data-test-edit-link]').hasText('Edit configuration', 'Edit button exists with correct text');
    await authPage.logout();
    // Check with restricted permissions
    await authPage.login(token);
    await click('[data-test-sidebar-nav-link="Secrets Engines"]');
    assert.dom(`[data-test-secrets-backend-link="${backend}"]`).exists('Shows backend on secret list page');
    await navToConnection(backend, connection);
    assert.strictEqual(
      currentURL(),
      `/vault/secrets/${backend}/show/${connection}`,
      'Allows reading connection'
    );
    assert
      .dom('[data-test-database-connection-delete]')
      .doesNotExist('Delete button does not show due to permissions');
    assert
      .dom('[data-test-database-connection-reset]')
      .doesNotExist('Reset button does not show due to permissions');
    assert.dom('[data-test-secret-create]').doesNotExist('Add role button does not show due to permissions');
    assert.dom('[data-test-edit-link]').doesNotExist('Edit button does not show due to permissions');
    await visit(`/vault/secrets/${backend}/overview`);
    assert.dom('[data-test-overview-card="Connections"]').exists('Connections card exists on overview');
    assert
      .dom('[data-test-overview-card="Roles"]')
      .doesNotExist('Roles card does not exist on overview w/ policy');
    assert.dom('.overview-card h2').hasText('1', 'Lists the correct number of connections');
    // confirm get credentials card is an option to select. Regression bug.
    await typeIn(GENERAL.inputSearch('search-input-role'), 'blah');
    assert.dom('[data-test-get-credentials]').isEnabled();
    // [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 });