1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6declare(strict_types=1);
7
8namespace Tests\Browser;
9
10use App\Models\User;
11use Laravel\Dusk\Browser;
12use Tests\DuskTestCase;
13
14class AccountTest extends DuskTestCase
15{
16 public function testUpdatePassword(): void
17 {
18 $this->browse(function (Browser $browserMain, Browser $browserOther) {
19 $userFactory = User::factory();
20
21 $password = $userFactory::DEFAULT_PASSWORD;
22 $user = $userFactory->create();
23
24 $browsers = collect([$browserMain, $browserOther]);
25
26 $browsers->each(fn ($browser) => (
27 $browser->visit('/')
28 ->clickLink('Sign in')
29 ->type('username', $user->user_email)
30 ->type('password', $password)
31 ->press('Sign in')
32 ));
33
34 $browsers->each(fn ($browser) => $browser->waitFor('.user-home'));
35
36 $newPassword = str_random(20);
37
38 $browserMain->visit('/_dusk/verify')
39 ->visitRoute('account.edit')
40 ->type('.js-password-update input[name="user[current_password]"]', $password)
41 ->type('.js-password-update input[name="user[password]"]', $newPassword)
42 ->type('.js-password-update input[name="user[password_confirmation]"]', $newPassword)
43 ->press('.js-password-update button[type=submit]')
44 ->waitForText('Saved')
45 ->clickLink('home')
46 ->waitFor('.user-home');
47
48 $browserOther
49 ->visit('/')
50 ->assertVisible('.landing-hero');
51 });
52 }
53}