Skip to content

Commit f29ba73

Browse files
committed
Adding test cases for Login and Profile pages
1 parent b8627e2 commit f29ba73

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

tests/LoginPageTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function test_blank_username_and_password_validation_is_done()
4343
public function test_wrong_password_fails_login()
4444
{
4545
$this->browse(function (Browser $browser) {
46-
$browser->visit($this->path)
46+
$browser->visit('/login')
4747
->type('email', 'admin@admin.com')
4848
->type('password', 'wrongpassword')
4949
->click($this->loginBtn)
@@ -55,7 +55,7 @@ public function test_wrong_password_fails_login()
5555
public function test_logged_in_user_should_not_see_login_page()
5656
{
5757
$this->browse(function (Browser $browser) {
58-
$user = User::where('email', 'admin@admin.com')->first();
58+
$user = User::where('email', 'admin@admin.com')->first();
5959
$browser->loginAs(User::find($user->id))
6060
->visit($this->path)
6161
->assertPathIs('/home');

tests/ProfilePageTest.php

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,72 @@ public function __construct()
2222
public function test_change_password_without_data_validation_error()
2323
{
2424
$this->browse(function (Browser $browser) {
25-
// $browser->visit($this->path)->;
25+
$user = User::where('email', 'admin@admin.com')->first();
26+
$browser->loginAs(User::find($user->id))
27+
->visit($this->path)
28+
->type('current_password', '')
29+
->type('new_password', '')
30+
->type('confirm_password', '')
31+
->click($this->changePasswordBtn)
32+
->assertPathIs($this->path)
33+
->assertSee('The current password field is required.')
34+
->assertSee('The new password field is required.')
35+
->assertSee('The confirm password field is required.');
36+
});
37+
}
38+
39+
public function test_without_current_password_show_validations()
40+
{
41+
$this->browse(function (Browser $browser) {
42+
$user = User::where('email', 'admin@admin.com')->first();
43+
$browser->loginAs(User::find($user->id))
44+
->visit($this->path)
45+
->type('new_password', 'Password1')
46+
->type('confirm_password', 'Password1')
47+
->click($this->changePasswordBtn)
48+
->assertPathIs($this->path)
49+
->assertSee('The current password field is required.');
50+
});
51+
}
52+
53+
public function test_wrong_password_does_not_allow_password_change()
54+
{
55+
$this->browse(function (Browser $browser) {
56+
$user = User::where('email', 'admin@admin.com')->first();
57+
$browser->loginAs(User::find($user->id))
58+
->visit($this->path)
59+
->type('current_password', 'wrongpassword')
60+
->type('new_password', 'Password1')
61+
->type('confirm_password', 'Password1')
62+
->click($this->changePasswordBtn)
63+
->assertSee('Check if your current password is correct.');
64+
});
65+
}
66+
67+
public function test_user_can_change_password_correctly_and_login_back()
68+
{
69+
$this->browse(function (Browser $browser) {
70+
$user = User::where('email', 'admin@admin.com')->first();
71+
$browser->loginAs(User::find($user->id))
72+
->visit($this->path)
73+
->type('current_password', 'password')
74+
->type('new_password', 'Password1')
75+
->type('confirm_password', 'Password1')
76+
->click($this->changePasswordBtn)
77+
->assertPathIs($this->path)
78+
->click('#user-dropdown-menu')
79+
->click('#logout-button')
80+
->assertPathIs('/')
81+
->visit('/login')
82+
->type('email', 'admin@admin.com')
83+
->type('password', 'Password1')
84+
->click('.btn.btn-primary.btn-block.btn-flat')
85+
->assertPathIs('/home')
86+
->visit($this->path)
87+
->type('current_password', 'Password1')
88+
->type('new_password', 'password')
89+
->type('confirm_password', 'password')
90+
->click($this->changePasswordBtn);
2691
});
2792
}
2893
}

0 commit comments

Comments
 (0)