Skip to content

Commit 256dd5a

Browse files
Convert user profile Cypress tests to Laravel Dusk (Kitware#3638)
This Cypress test has been particularly flaky of late.
1 parent fec2255 commit 256dd5a

4 files changed

Lines changed: 169 additions & 131 deletions

File tree

resources/js/vue/components/ProfilePage.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,25 @@
3030
v-model="profileForm.fname"
3131
name="fname"
3232
label="First Name"
33+
test-id="fname-input"
3334
/>
3435
<InputField
3536
v-model="profileForm.lname"
3637
name="lname"
3738
label="Last Name"
39+
test-id="lname-input"
3840
/>
3941
<InputField
4042
v-model="profileForm.email"
4143
name="email"
4244
label="Email"
45+
test-id="email-input"
4346
/>
4447
<InputField
4548
v-model="profileForm.institution"
4649
name="institution"
4750
label="Institution"
51+
test-id="institution-input"
4852
/>
4953

5054
<div class="tw-flex tw-justify-end tw-mt-4">
@@ -53,6 +57,7 @@
5357
value="Update Profile"
5458
name="updateprofile"
5559
class="tw-btn tw-btn-sm tw-btn-primary"
60+
data-test="update-profile-button"
5661
>
5762
</div>
5863
</form>
@@ -76,18 +81,21 @@
7681
name="oldpasswd"
7782
type="password"
7883
label="Current Password"
84+
test-id="oldpasswd-input"
7985
/>
8086
<InputField
8187
v-model="passwordForm.passwd"
8288
name="passwd"
8389
type="password"
8490
label="New Password"
91+
test-id="passwd-input"
8592
/>
8693
<InputField
8794
v-model="passwordForm.passwd2"
8895
name="passwd2"
8996
type="password"
9097
label="Confirm Password"
98+
test-id="passwd2-input"
9199
/>
92100

93101
<div class="tw-flex tw-justify-end tw-mt-4">
@@ -96,6 +104,7 @@
96104
value="Update Password"
97105
name="updatepassword"
98106
class="tw-btn tw-btn-sm tw-btn-primary"
107+
data-test="update-password-button"
99108
>
100109
</div>
101110
</form>

tests/Browser/Pages/ProfilePageTest.php

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,166 @@ public function tearDown(): void
4040
parent::tearDown();
4141
}
4242

43+
public function testIsProtectedByLogin(): void
44+
{
45+
$this->browse(function (Browser $browser): void {
46+
$browser->visit('/profile')
47+
->assertUrlIs(config('app.url') . '/login');
48+
});
49+
}
50+
51+
public function testCanChangeNameAndEmail(): void
52+
{
53+
$this->users['admin'] = $this->makeAdminUser(
54+
'admin',
55+
'admin',
56+
'admin@example.com',
57+
null,
58+
'testing',
59+
);
60+
61+
$this->browse(function (Browser $browser): void {
62+
$browser->loginAs($this->users['admin'])
63+
->visit('/profile')
64+
->assertInputValue('@fname-input', 'admin')
65+
->assertInputValue('@lname-input', 'admin')
66+
->assertInputValue('@email-input', 'admin@example.com')
67+
->assertInputValue('@institution-input', 'testing')
68+
69+
->clear('@fname-input')
70+
->type('@fname-input', 'first name here')
71+
->clear('@lname-input')
72+
->type('@lname-input', 'last name here')
73+
->clear('@email-input')
74+
->type('@email-input', 'emailtest@example.com')
75+
->clear('@institution-input')
76+
->type('@institution-input', 'Kitware (Test)')
77+
78+
->click('@update-profile-button')
79+
->waitForTextIn('#app', 'Your profile has been updated');
80+
});
81+
82+
$user = User::where('email', 'emailtest@example.com')->firstOrFail();
83+
84+
$this->browse(function (Browser $browser) use ($user): void {
85+
$browser->logout()
86+
->loginAs($user)
87+
->visit('/profile')
88+
89+
->assertInputValue('@fname-input', 'first name here')
90+
->clear('@fname-input')
91+
->type('@fname-input', 'admin')
92+
->assertInputValue('@lname-input', 'last name here')
93+
->clear('@lname-input')
94+
->type('@lname-input', 'admin')
95+
->assertInputValue('@email-input', 'emailtest@example.com')
96+
->clear('@email-input')
97+
->type('@email-input', 'admin@example.com')
98+
->assertInputValue('@institution-input', 'Kitware (Test)')
99+
->clear('@institution-input')
100+
->type('@institution-input', 'testing')
101+
102+
->click('@update-profile-button')
103+
->waitForTextIn('#app', 'Your profile has been updated');
104+
});
105+
106+
$user = User::where('email', 'admin@example.com')->firstOrFail();
107+
108+
$this->browse(function (Browser $browser) use ($user): void {
109+
$browser->logout()
110+
->loginAs($user)
111+
->visit('/profile')
112+
->assertInputValue('@fname-input', 'admin')
113+
->assertInputValue('@lname-input', 'admin')
114+
->assertInputValue('@email-input', 'admin@example.com')
115+
->assertInputValue('@institution-input', 'testing');
116+
});
117+
}
118+
119+
public function testIncorrectPasswordPreventsPasswordReset(): void
120+
{
121+
$this->users['admin'] = $this->makeAdminUser();
122+
123+
$this->browse(function (Browser $browser): void {
124+
$browser->loginAs($this->users['admin'])
125+
->visit('/profile')
126+
->assertInputValue('@oldpasswd-input', '')
127+
->assertInputValue('@passwd-input', '')
128+
->assertInputValue('@passwd2-input', '')
129+
130+
->type('@oldpasswd-input', 'incorrect password')
131+
->type('@passwd-input', 'new password')
132+
->type('@passwd2-input', 'new password')
133+
->click('@update-password-button')
134+
->waitForTextIn('#app', 'Your old password is incorrect');
135+
});
136+
}
137+
138+
public function testShortPasswordPreventsPasswordReset(): void
139+
{
140+
$password = Str::random(10);
141+
$this->users['admin'] = clone $this->makeAdminUser();
142+
$this->users['admin']->password = bcrypt($password);
143+
$this->users['admin']->save();
144+
145+
$this->browse(function (Browser $browser) use ($password): void {
146+
$browser->loginAs($this->users['admin'])
147+
->visit('/profile')
148+
->assertInputValue('@oldpasswd-input', '')
149+
->assertInputValue('@passwd-input', '')
150+
->assertInputValue('@passwd2-input', '')
151+
152+
->type('@oldpasswd-input', $password)
153+
->type('@passwd-input', 'a')
154+
->type('@passwd2-input', 'a')
155+
->click('@update-password-button')
156+
->waitForTextIn('#app', 'Password must be at least 5 characters');
157+
});
158+
}
159+
160+
public function testCanChangePassword(): void
161+
{
162+
$password = Str::random(10);
163+
$this->users['admin'] = clone $this->makeAdminUser();
164+
$this->users['admin']->password = bcrypt($password);
165+
$this->users['admin']->save();
166+
167+
$this->browse(function (Browser $browser) use ($password): void {
168+
$browser->loginAs($this->users['admin'])
169+
->visit('/profile')
170+
->assertInputValue('@oldpasswd-input', '')
171+
->assertInputValue('@passwd-input', '')
172+
->assertInputValue('@passwd2-input', '')
173+
174+
->type('@oldpasswd-input', $password)
175+
->type('@passwd-input', 'new password')
176+
->type('@passwd2-input', 'new password')
177+
->click('@update-password-button')
178+
->waitForTextIn('#app', 'Your password has been updated');
179+
});
180+
181+
$user = User::where('email', $this->users['admin']->email)->firstOrFail();
182+
$this->assertTrue(password_verify('new password', $user->password));
183+
184+
$this->browse(function (Browser $browser) use ($user): void {
185+
$browser->logout()
186+
->loginAs($user)
187+
->visit('/profile')
188+
->assertInputValue('@oldpasswd-input', '')
189+
->assertInputValue('@passwd-input', '')
190+
->assertInputValue('@passwd2-input', '')
191+
192+
->type('@oldpasswd-input', 'new password')
193+
->type('@passwd-input', '12345')
194+
->type('@passwd2-input', '12345')
195+
->click('@update-password-button')
196+
->waitForTextIn('#app', 'Your password has been updated');
197+
});
198+
199+
$user = User::where('email', $this->users['admin']->email)->firstOrFail();
200+
$this->assertTrue(password_verify('12345', $user->password));
201+
}
202+
43203
public function testCreateFullAccessToken(): void
44204
{
45205
$this->users['admin'] = $this->makeAdminUser();

tests/cypress/e2e/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ function(add_cypress_e2e_test TestName)
1818
endfunction()
1919

2020
# These tests have the correct dependencies set up
21-
add_cypress_e2e_test(user-profile)
22-
set_tests_properties(cypress/e2e/user-profile PROPERTIES DEPENDS install_2)
23-
2421
add_cypress_e2e_test(query-tests)
2522
set_tests_properties(cypress/e2e/query-tests PROPERTIES DEPENDS cypress/e2e/remove-build)
2623

tests/cypress/e2e/user-profile.cy.js

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)