2019-11-25 03:27:59 +07:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
2020-12-16 08:47:31 +07:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2019-11-25 03:27:59 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
func (wds *WebDriverSession) doInitiatePasswordReset(ctx context.Context, t *testing.T, username string) {
|
2020-12-16 08:47:31 +07:00
|
|
|
err := wds.WaitElementLocatedByID(ctx, t, "reset-password-button").Click()
|
|
|
|
require.NoError(t, err)
|
2019-11-25 03:27:59 +07:00
|
|
|
// Fill in username
|
2020-12-16 08:47:31 +07:00
|
|
|
err = wds.WaitElementLocatedByID(ctx, t, "username-textfield").SendKeys(username)
|
|
|
|
require.NoError(t, err)
|
2019-11-25 03:27:59 +07:00
|
|
|
// And click on the reset button
|
2020-12-16 08:47:31 +07:00
|
|
|
err = wds.WaitElementLocatedByID(ctx, t, "reset-button").Click()
|
|
|
|
require.NoError(t, err)
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (wds *WebDriverSession) doCompletePasswordReset(ctx context.Context, t *testing.T, newPassword1, newPassword2 string) {
|
|
|
|
link := doGetLinkFromLastMail(t)
|
|
|
|
wds.doVisit(t, link)
|
|
|
|
|
2020-12-16 08:47:31 +07:00
|
|
|
err := wds.WaitElementLocatedByID(ctx, t, "password1-textfield").SendKeys(newPassword1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = wds.WaitElementLocatedByID(ctx, t, "password2-textfield").SendKeys(newPassword2)
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = wds.WaitElementLocatedByID(ctx, t, "reset-button").Click()
|
|
|
|
require.NoError(t, err)
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (wds *WebDriverSession) doSuccessfullyCompletePasswordReset(ctx context.Context, t *testing.T, newPassword1, newPassword2 string) {
|
|
|
|
wds.doCompletePasswordReset(ctx, t, newPassword1, newPassword2)
|
|
|
|
wds.verifyIsFirstFactorPage(ctx, t)
|
|
|
|
}
|
|
|
|
|
2020-11-27 16:59:22 +07:00
|
|
|
func (wds *WebDriverSession) doUnsuccessfulPasswordReset(ctx context.Context, t *testing.T, newPassword1, newPassword2 string) {
|
|
|
|
wds.doCompletePasswordReset(ctx, t, newPassword1, newPassword2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wds *WebDriverSession) doResetPassword(ctx context.Context, t *testing.T, username, newPassword1, newPassword2 string, unsuccessful bool) {
|
2019-11-25 03:27:59 +07:00
|
|
|
wds.doInitiatePasswordReset(ctx, t, username)
|
|
|
|
// then wait for the "email sent notification"
|
|
|
|
wds.verifyMailNotificationDisplayed(ctx, t)
|
2020-11-27 16:59:22 +07:00
|
|
|
|
|
|
|
if unsuccessful {
|
|
|
|
wds.doUnsuccessfulPasswordReset(ctx, t, newPassword1, newPassword2)
|
|
|
|
} else {
|
|
|
|
wds.doSuccessfullyCompletePasswordReset(ctx, t, newPassword1, newPassword2)
|
|
|
|
}
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|