Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/UserProfileTest.php
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | public function testProfile(): void | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->visit(new Home()) | $browser->visit(new Home()) | ||||
->submitLogon('john@kolab.org', 'simple123', true) | ->submitLogon('john@kolab.org', 'simple123', true) | ||||
->on(new Dashboard()) | ->on(new Dashboard()) | ||||
->assertSeeIn('@links .link-profile', 'Your profile') | ->assertSeeIn('@links .link-profile', 'Your profile') | ||||
->click('@links .link-profile') | ->click('@links .link-profile') | ||||
->on(new UserProfile()) | ->on(new UserProfile()) | ||||
->assertSeeIn('#user-profile .button-delete', 'Delete account') | ->assertSeeIn('#user-profile .profile-delete', 'Delete account') | ||||
->whenAvailable('@form', function (Browser $browser) { | ->whenAvailable('@form', function (Browser $browser) { | ||||
$user = User::where('email', 'john@kolab.org')->first(); | $user = User::where('email', 'john@kolab.org')->first(); | ||||
// Assert form content | // Assert form content | ||||
$browser->assertFocused('div.row:nth-child(2) input') | $browser->assertFocused('div.row:nth-child(2) input') | ||||
->assertSeeIn('div.row:nth-child(1) label', 'Customer No.') | ->assertSeeIn('div.row:nth-child(1) label', 'Customer No.') | ||||
->assertSeeIn('div.row:nth-child(1) .form-control-plaintext', $user->id) | ->assertSeeIn('div.row:nth-child(1) .form-control-plaintext', $user->id) | ||||
->assertSeeIn('div.row:nth-child(2) label', 'First Name') | ->assertSeeIn('div.row:nth-child(2) label', 'First Name') | ||||
->assertValue('div.row:nth-child(2) input[type=text]', $this->profile['first_name']) | ->assertValue('div.row:nth-child(2) input[type=text]', $this->profile['first_name']) | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | public function testProfileNonController(): void | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->visit('/logout') | $browser->visit('/logout') | ||||
->visit(new Home()) | ->visit(new Home()) | ||||
->submitLogon('jack@kolab.org', 'simple123', true) | ->submitLogon('jack@kolab.org', 'simple123', true) | ||||
->on(new Dashboard()) | ->on(new Dashboard()) | ||||
->assertSeeIn('@links .link-profile', 'Your profile') | ->assertSeeIn('@links .link-profile', 'Your profile') | ||||
->click('@links .link-profile') | ->click('@links .link-profile') | ||||
->on(new UserProfile()) | ->on(new UserProfile()) | ||||
->assertMissing('#user-profile .button-delete') | ->assertMissing('#user-profile .profile-delete') | ||||
->whenAvailable('@form', function (Browser $browser) { | ->whenAvailable('@form', function (Browser $browser) { | ||||
// TODO: decide on what fields the non-controller user should be able | // TODO: decide on what fields the non-controller user should be able | ||||
// to see/change | // to see/change | ||||
}) | }) | ||||
// Check that the account policy is used | // Check that the account policy is used | ||||
->whenAvailable('#password_policy', function (Browser $browser) { | ->whenAvailable('#password_policy', function (Browser $browser) { | ||||
$browser->assertElementsCount('li', 3) | $browser->assertElementsCount('li', 3) | ||||
->assertMissing('li:nth-child(1) svg.text-success') | ->assertMissing('li:nth-child(1) svg.text-success') | ||||
Show All 20 Lines | public function testProfileDelete(): void | ||||
$this->browse(function (Browser $browser) use ($user) { | $this->browse(function (Browser $browser) use ($user) { | ||||
$browser->visit('/logout') | $browser->visit('/logout') | ||||
->on(new Home()) | ->on(new Home()) | ||||
->submitLogon('profile-delete@kolabnow.com', 'simple123', true) | ->submitLogon('profile-delete@kolabnow.com', 'simple123', true) | ||||
->on(new Dashboard()) | ->on(new Dashboard()) | ||||
->assertSeeIn('@links .link-profile', 'Your profile') | ->assertSeeIn('@links .link-profile', 'Your profile') | ||||
->click('@links .link-profile') | ->click('@links .link-profile') | ||||
->on(new UserProfile()) | ->on(new UserProfile()) | ||||
->click('#user-profile .button-delete') | ->click('#user-profile .profile-delete') | ||||
->waitForLocation('/profile/delete') | ->waitForLocation('/profile/delete') | ||||
->assertSeeIn('#user-delete .card-title', 'Delete this account?') | ->assertSeeIn('#user-delete .card-title', 'Delete this account?') | ||||
->assertSeeIn('#user-delete .button-cancel', 'Cancel') | ->assertSeeIn('#user-delete .button-cancel', 'Cancel') | ||||
->assertSeeIn('#user-delete .card-text', 'This operation is irreversible') | ->assertSeeIn('#user-delete .card-text', 'This operation is irreversible') | ||||
->assertFocused('#user-delete .button-cancel') | ->assertFocused('#user-delete .button-cancel') | ||||
->click('#user-delete .button-cancel') | ->click('#user-delete .button-cancel') | ||||
->waitForLocation('/profile') | ->waitForLocation('/profile') | ||||
->on(new UserProfile()); | ->on(new UserProfile()); | ||||
// Test deleting the user | // Test deleting the user | ||||
$browser->click('#user-profile .button-delete') | $browser->click('#user-profile .profile-delete') | ||||
->waitForLocation('/profile/delete') | ->waitForLocation('/profile/delete') | ||||
->click('#user-delete .button-delete') | ->click('#user-delete .button-delete') | ||||
->waitForLocation('/login') | ->waitForLocation('/login') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'User deleted successfully.'); | ->assertToast(Toast::TYPE_SUCCESS, 'User deleted successfully.'); | ||||
$this->assertTrue($user->fresh()->trashed()); | $this->assertTrue($user->fresh()->trashed()); | ||||
}); | }); | ||||
} | } | ||||
// TODO: Test that Ned (John's "delegatee") can delete himself | // TODO: Test that Ned (John's "delegatee") can delete himself | ||||
// TODO: Test that Ned (John's "delegatee") can/can't delete John ? | // TODO: Test that Ned (John's "delegatee") can/can't delete John ? | ||||
} | } |