Skip to content

Commit 92c03d4

Browse files
committed
Add tests for password reset page functionality
1 parent 7a1d73b commit 92c03d4

File tree

4 files changed

+92
-3
lines changed

4 files changed

+92
-3
lines changed

resources/assets/scripts/components/auth/ForgotPassword.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
>
66
<div class="flex flex-wrap -mx-3 mb-6">
77
<div class="input-open">
8-
<input class="input" id="grid-email" type="email" aria-labelledby="grid-email" ref="email" required
8+
<input class="input" id="grid-email" type="email" aria-labelledby="grid-email-label" required
9+
ref="email"
910
v-bind:class="{ 'has-content': email.length > 0 }"
1011
v-bind:readonly="showSpinner"
1112
v-bind:value="email"
1213
v-on:input="updateEmail($event)"
1314
/>
14-
<label for="grid-email">{{ $t('strings.email') }}</label>
15+
<label for="grid-email" id="grid-email-label">{{ $t('strings.email') }}</label>
1516
<p class="text-grey-darker text-xs">{{ $t('auth.forgot_password.label_help') }}</p>
1617
</div>
1718
</div>
@@ -25,6 +26,7 @@
2526
</div>
2627
<div class="pt-6 text-center">
2728
<router-link class="text-xs text-grey tracking-wide no-underline uppercase hover:text-grey-dark"
29+
aria-label="Go to login"
2830
:to="{ name: 'login' }"
2931
>
3032
{{ $t('auth.go_to_login') }}

tests/Browser/Pages/LoginPage.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ public function url(): string
1515
public function elements()
1616
{
1717
return [
18+
'@email' => '#grid-email',
1819
'@username' => '#grid-username',
1920
'@password' => '#grid-password',
2021
'@loginButton' => '#grid-login-button',
21-
'@forgotPassword' => 'a[aria-label="Forgot password"]',
22+
'@submitButton' => 'button.btn.btn-jumbo[type="submit"]',
23+
'@forgotPassword' => 'a[href="/auth/password"][aria-label="Forgot password"]',
24+
'@goToLogin' => 'a[href="/auth/login"][aria-label="Go to login"]',
25+
'@alertSuccess' => 'div[role="alert"].success > span.message',
26+
'@alertDanger' => 'div[role="alert"].danger > span.message',
2227
];
2328
}
2429
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Pterodactyl\Tests\Browser\Processes\Authentication;
4+
5+
use Pterodactyl\Tests\Browser\BrowserTestCase;
6+
use Pterodactyl\Tests\Browser\Pages\LoginPage;
7+
use Pterodactyl\Tests\Browser\PterodactylBrowser;
8+
9+
class ForgotPasswordProcessTest extends BrowserTestCase
10+
{
11+
/**
12+
* Test that the password reset page works as expected and displays the expected
13+
* success messages to the client when submitted.
14+
*/
15+
public function testResetPasswordWithInvalidAccount()
16+
{
17+
$this->browse(function (PterodactylBrowser $browser) {
18+
$browser->visit(new LoginPage)
19+
->assertSee(trans('auth.forgot_password.label'))
20+
->click('@forgotPassword')
21+
->waitForLocation('/auth/password')
22+
->assertFocused('@email')
23+
->assertSeeIn('.input-open > p.text-xs', trans('auth.forgot_password.label_help'))
24+
->assertSeeIn('@submitButton', trans('auth.forgot_password.button'))
25+
->type('@email', 'unassociated@example.com')
26+
->assertSeeIn('@goToLogin', trans('auth.go_to_login'))
27+
->press('@submitButton')
28+
->waitForLocation('/auth/login')
29+
->assertSeeIn('div[role="alert"].success > span.message', 'We have e-mailed your password reset link!')
30+
->assertFocused('@username')
31+
->assertValue('@username', 'unassociated@example.com');
32+
});
33+
}
34+
35+
/**
36+
* Test that you can type in your email address and then click forgot password and have
37+
* the email maintained on the new page.
38+
*/
39+
public function testEmailCarryover()
40+
{
41+
$this->browse(function (PterodactylBrowser $browser) {
42+
$browser->visit(new LoginPage)
43+
->type('@username', 'dane@example.com')
44+
->click('@forgotPassword')
45+
->waitForLocation('/auth/password')
46+
->assertFocused('@email')
47+
->assertValue('@email', 'dane@example.com');
48+
});
49+
}
50+
}

tests/Browser/PterodactylBrowser.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,39 @@
33
namespace Pterodactyl\Tests\Browser;
44

55
use Laravel\Dusk\Browser;
6+
use Illuminate\Support\Str;
7+
use PHPUnit\Framework\Assert as PHPUnit;
68

79
class PterodactylBrowser extends Browser
810
{
11+
/**
12+
* Perform a case insensitive search for a string in the body.
13+
*
14+
* @param string $text
15+
* @return \Pterodactyl\Tests\Browser\PterodactylBrowser
16+
*/
17+
public function assertSee($text)
18+
{
19+
return $this->assertSeeIn('', $text);
20+
}
21+
22+
/**
23+
* Perform a case insensitive search for a string in a given selector.
24+
*
25+
* @param string $selector
26+
* @param string $text
27+
* @return \Pterodactyl\Tests\Browser\PterodactylBrowser
28+
*/
29+
public function assertSeeIn($selector, $text)
30+
{
31+
$fullSelector = $this->resolver->format($selector);
32+
$element = $this->resolver->findOrFail($selector);
33+
34+
PHPUnit::assertTrue(
35+
Str::contains(mb_strtolower($element->getText()), mb_strtolower($text)),
36+
"Did not see expected text [{$text}] within element [{$fullSelector}] using case-insensitive search."
37+
);
38+
39+
return $this;
40+
}
941
}

0 commit comments

Comments
 (0)