Repository: hashicorp/vault
File: ui/tests/acceptance/auth/auth-list-test.js (JavaScript)

Code before:
    await click(SELECTORS.saveBtn);
    assert.strictEqual(currentURL(), `/vault/access/${this.path2}/item/user`);
    // Confirm that the user was created. There was a bug where the apiPath was not being updated when toggling between auth routes.
    assert.dom(SELECTORS.listItem).hasText(this.user2, 'user2 exists in the list');

    // Confirm that the auth method 1 shows user1. There was a bug where the user was not listed when toggling between auth routes.
    await click(SELECTORS.methods);
    await click(SELECTORS.backendLink(this.path1));
    assert.dom(SELECTORS.listItem).hasText(this.user1, 'user1 exists in the list');
  });

  module('auth methods are linkable and link to correct view', function (hooks) {
    hooks.beforeEach(async function () {
      this.uid = uuidv4();
      await visit('/vault/access');
    });

    // Test all auth methods, not just those you can log in with
    methods()
      .map((backend) => backend.type)
      .forEach((type) => {
        test(`${type} auth method`, async function (assert) {
          const supportManaged = supportedManagedAuthBackends();
          const path = type === 'token' ? 'token' : `auth-list-${type}-${this.uid}`;
          if (type !== 'token') {
            await enablePage.enable(type, path);
          }
          await settled();
          await visit('/vault/access');

          // check popup menu
          const itemCount = type === 'token' ? 2 : 3;
          await click(`[data-test-auth-backend-link="${path}"] [data-test-popup-menu-trigger]`);
          assert
            .dom(`[data-test-auth-backend-link="${path}"] .hds-dropdown-list-item`)
            .exists({ count: itemCount }, `shows ${itemCount} dropdown items for ${type}`);

          // all auth methods should be linkable
          await click(`[data-test-auth-backend-link="${path}"]`);
          if (!supportManaged.includes(type)) {
            assert.dom('[data-test-auth-section-tab]').exists({ count: 1 });
            assert
              .dom('[data-test-auth-section-tab]')
              .hasText('Configuration', `only shows configuration tab for ${type} auth method`);
            assert.dom('[data-test-doc-link] .doc-link').exists(`includes doc link for ${type} auth method`);
          } else {
            let expectedTabs = 2;
            if (type === 'ldap' || type === 'okta') {
              expectedTabs = 3;
            }
            assert

Review comment (suggestion):
this was the method that I swapped out. if we have semi-regular flaky behavior and page objects are involved, I head there first. I removed the nested use of them by replacing this function that relied on page objects.

Code after:
    // enable a second user in the second userpass backend
    await createUser(this.path2, this.user2);

    // verify the second user is listed after creation
    assert.dom(SELECTORS.listItem).hasText(this.user2, 'user2 exists in the list');

    // check that switching back to the first auth method shows the first user
    await click(SELECTORS.methods);
    await click(AUTH_FORM.linkedBlockAuth(this.path1));
    assert.dom(SELECTORS.listItem).hasText(this.user1, 'user1 exists in the list');
  });

  module('auth methods are linkable and link to correct view', function (hooks) {
    hooks.beforeEach(async function () {
      this.uid = uuidv4();
      await visit('/vault/access');
    });

    // Test all auth methods, not just those you can log in with
    methods()
      .map((backend) => backend.type)
      .forEach((type) => {
        test(`${type} auth method`, async function (assert) {
          const supportManaged = MANAGED_AUTH_BACKENDS;
          const isTokenType = type === 'token';
          const path = isTokenType ? 'token' : `auth-list-${type}-${this.uid}`;

          // Enable auth if the backend is not type token
          if (!isTokenType) {
            await visit('/vault/settings/auth/enable');
            await click(MOUNT_BACKEND_FORM.mountType(type));
            await fillIn(GENERAL.inputByAttr('path'), path);
            await click(GENERAL.saveButton);
          }

          await visit('/vault/access');

          // check popup menu for auth method
          const itemCount = isTokenType ? 2 : 3;
          const triggerSelector = `${AUTH_FORM.linkedBlockAuth(path)} [data-test-popup-menu-trigger]`;
          const itemSelector = `${AUTH_FORM.linkedBlockAuth(path)} .hds-dropdown-list-item`;

          await click(triggerSelector);
          assert
            .dom(itemSelector)
            .exists({ count: itemCount }, `shows ${itemCount} dropdown items for ${type}`);

          // check that auth methods are linkable
          await click(AUTH_FORM.linkedBlockAuth(path));

          if (!supportManaged.includes(type)) {