Skip to content

Commit

Permalink
UI: User reset password test less flakey (#24826)
Browse files Browse the repository at this point in the history
  • Loading branch information
hashishaw authored Jan 11, 2024
1 parent 0a427b9 commit a1c2e49
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions ui/tests/acceptance/reset-password-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
*/

import { module, test } from 'qunit';
import sinon from 'sinon';
import { currentURL, click, fillIn, settled } from '@ember/test-helpers';
import { currentURL, click, fillIn, settled, waitFor } from '@ember/test-helpers';
import { setupApplicationTest } from 'vault/tests/helpers';
import authPage from 'vault/tests/pages/auth';
import { createPolicyCmd, deleteAuthCmd, mountAuthCmd, runCmd } from '../helpers/commands';
import { v4 as uuidv4 } from 'uuid';

const SUCCESS_MESSAGE = 'Successfully reset password';

module('Acceptance | reset password', function (hooks) {
setupApplicationTest(hooks);

Expand All @@ -26,7 +27,7 @@ module('Acceptance | reset password', function (hooks) {

hooks.afterEach(async function () {
await authPage.login();
await runCmd(deleteAuthCmd(this.userpass), false);
await runCmd([deleteAuthCmd(this.userpass), `delete sys/policies/acl/${this.userpass}`], false);
});

test('does not allow password reset for non-userpass users', async function (assert) {
Expand All @@ -38,8 +39,6 @@ module('Acceptance | reset password', function (hooks) {
});

test('allows password reset for userpass users logged in via dropdown', async function (assert) {
const flashMessages = this.owner.lookup('service:flashMessages');
const flashSpy = sinon.spy(flashMessages, 'success');
await authPage.login();
await runCmd([
mountAuthCmd('userpass', this.userpass),
Expand All @@ -62,13 +61,12 @@ module('Acceptance | reset password', function (hooks) {
assert.dom('[data-test-title]').hasText('Reset password', 'page title');
await fillIn('[data-test-textarea]', 'newpassword');
await click('[data-test-reset-password-save]');
assert.true(flashSpy.calledOnceWith('Successfully reset password'), 'Shows success message');
await waitFor('[data-test-flash-message]');
assert.dom('[data-test-flash-message]').hasText(`Success ${SUCCESS_MESSAGE}`);
assert.dom('[data-test-textarea]').hasValue('', 'Resets input after save');
});

test('allows password reset for userpass users logged in via tab', async function (assert) {
const flashMessages = this.owner.lookup('service:flashMessages');
const flashSpy = sinon.spy(flashMessages, 'success');
await authPage.login();
await runCmd([
mountAuthCmd('userpass', this.userpass),
Expand All @@ -95,7 +93,8 @@ module('Acceptance | reset password', function (hooks) {
assert.dom('[data-test-title]').hasText('Reset password', 'page title');
await fillIn('[data-test-textarea]', 'newpassword');
await click('[data-test-reset-password-save]');
assert.true(flashSpy.calledOnceWith('Successfully reset password'), 'Shows success message');
await waitFor('[data-test-flash-message]');
assert.dom('[data-test-flash-message]').hasText(`Success ${SUCCESS_MESSAGE}`);
assert.dom('[data-test-textarea]').hasValue('', 'Resets input after save');
});
});

0 comments on commit a1c2e49

Please sign in to comment.