Add tests for password reset page functionality
This commit is contained in:
parent
7a1d73ba9e
commit
92c03d4953
4 changed files with 92 additions and 3 deletions
|
@ -5,13 +5,14 @@
|
|||
>
|
||||
<div class="flex flex-wrap -mx-3 mb-6">
|
||||
<div class="input-open">
|
||||
<input class="input" id="grid-email" type="email" aria-labelledby="grid-email" ref="email" required
|
||||
<input class="input" id="grid-email" type="email" aria-labelledby="grid-email-label" required
|
||||
ref="email"
|
||||
v-bind:class="{ 'has-content': email.length > 0 }"
|
||||
v-bind:readonly="showSpinner"
|
||||
v-bind:value="email"
|
||||
v-on:input="updateEmail($event)"
|
||||
/>
|
||||
<label for="grid-email">{{ $t('strings.email') }}</label>
|
||||
<label for="grid-email" id="grid-email-label">{{ $t('strings.email') }}</label>
|
||||
<p class="text-grey-darker text-xs">{{ $t('auth.forgot_password.label_help') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -25,6 +26,7 @@
|
|||
</div>
|
||||
<div class="pt-6 text-center">
|
||||
<router-link class="text-xs text-grey tracking-wide no-underline uppercase hover:text-grey-dark"
|
||||
aria-label="Go to login"
|
||||
:to="{ name: 'login' }"
|
||||
>
|
||||
{{ $t('auth.go_to_login') }}
|
||||
|
|
|
@ -15,10 +15,15 @@ class LoginPage extends BasePage
|
|||
public function elements()
|
||||
{
|
||||
return [
|
||||
'@email' => '#grid-email',
|
||||
'@username' => '#grid-username',
|
||||
'@password' => '#grid-password',
|
||||
'@loginButton' => '#grid-login-button',
|
||||
'@forgotPassword' => 'a[aria-label="Forgot password"]',
|
||||
'@submitButton' => 'button.btn.btn-jumbo[type="submit"]',
|
||||
'@forgotPassword' => 'a[href="/auth/password"][aria-label="Forgot password"]',
|
||||
'@goToLogin' => 'a[href="/auth/login"][aria-label="Go to login"]',
|
||||
'@alertSuccess' => 'div[role="alert"].success > span.message',
|
||||
'@alertDanger' => 'div[role="alert"].danger > span.message',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Tests\Browser\Processes\Authentication;
|
||||
|
||||
use Pterodactyl\Tests\Browser\BrowserTestCase;
|
||||
use Pterodactyl\Tests\Browser\Pages\LoginPage;
|
||||
use Pterodactyl\Tests\Browser\PterodactylBrowser;
|
||||
|
||||
class ForgotPasswordProcessTest extends BrowserTestCase
|
||||
{
|
||||
/**
|
||||
* Test that the password reset page works as expected and displays the expected
|
||||
* success messages to the client when submitted.
|
||||
*/
|
||||
public function testResetPasswordWithInvalidAccount()
|
||||
{
|
||||
$this->browse(function (PterodactylBrowser $browser) {
|
||||
$browser->visit(new LoginPage)
|
||||
->assertSee(trans('auth.forgot_password.label'))
|
||||
->click('@forgotPassword')
|
||||
->waitForLocation('/auth/password')
|
||||
->assertFocused('@email')
|
||||
->assertSeeIn('.input-open > p.text-xs', trans('auth.forgot_password.label_help'))
|
||||
->assertSeeIn('@submitButton', trans('auth.forgot_password.button'))
|
||||
->type('@email', 'unassociated@example.com')
|
||||
->assertSeeIn('@goToLogin', trans('auth.go_to_login'))
|
||||
->press('@submitButton')
|
||||
->waitForLocation('/auth/login')
|
||||
->assertSeeIn('div[role="alert"].success > span.message', 'We have e-mailed your password reset link!')
|
||||
->assertFocused('@username')
|
||||
->assertValue('@username', 'unassociated@example.com');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that you can type in your email address and then click forgot password and have
|
||||
* the email maintained on the new page.
|
||||
*/
|
||||
public function testEmailCarryover()
|
||||
{
|
||||
$this->browse(function (PterodactylBrowser $browser) {
|
||||
$browser->visit(new LoginPage)
|
||||
->type('@username', 'dane@example.com')
|
||||
->click('@forgotPassword')
|
||||
->waitForLocation('/auth/password')
|
||||
->assertFocused('@email')
|
||||
->assertValue('@email', 'dane@example.com');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -3,7 +3,39 @@
|
|||
namespace Pterodactyl\Tests\Browser;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
use Illuminate\Support\Str;
|
||||
use PHPUnit\Framework\Assert as PHPUnit;
|
||||
|
||||
class PterodactylBrowser extends Browser
|
||||
{
|
||||
/**
|
||||
* Perform a case insensitive search for a string in the body.
|
||||
*
|
||||
* @param string $text
|
||||
* @return \Pterodactyl\Tests\Browser\PterodactylBrowser
|
||||
*/
|
||||
public function assertSee($text)
|
||||
{
|
||||
return $this->assertSeeIn('', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a case insensitive search for a string in a given selector.
|
||||
*
|
||||
* @param string $selector
|
||||
* @param string $text
|
||||
* @return \Pterodactyl\Tests\Browser\PterodactylBrowser
|
||||
*/
|
||||
public function assertSeeIn($selector, $text)
|
||||
{
|
||||
$fullSelector = $this->resolver->format($selector);
|
||||
$element = $this->resolver->findOrFail($selector);
|
||||
|
||||
PHPUnit::assertTrue(
|
||||
Str::contains(mb_strtolower($element->getText()), mb_strtolower($text)),
|
||||
"Did not see expected text [{$text}] within element [{$fullSelector}] using case-insensitive search."
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue