Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/UserProfileTest.php
Show All 25 Lines | class UserProfileTest extends DuskTestCase | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
User::where('email', 'john@kolab.org')->first()->setSettings($this->profile); | User::where('email', 'john@kolab.org')->first()->setSettings($this->profile); | ||||
$this->deleteTestUser('profile-delete@kolabnow.com'); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
User::where('email', 'john@kolab.org')->first()->setSettings($this->profile); | User::where('email', 'john@kolab.org')->first()->setSettings($this->profile); | ||||
$this->deleteTestUser('profile-delete@kolabnow.com'); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test profile page (unauthenticated) | * Test profile page (unauthenticated) | ||||
*/ | */ | ||||
public function testProfileUnauth(): void | public function testProfileUnauth(): void | ||||
Show All 11 Lines | class UserProfileTest extends DuskTestCase | ||||
{ | { | ||||
$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') | |||||
->whenAvailable('@form', function (Browser $browser) { | ->whenAvailable('@form', function (Browser $browser) { | ||||
// Assert form content | // Assert form content | ||||
$browser->assertFocused('div.row:nth-child(1) input') | $browser->assertFocused('div.row:nth-child(1) input') | ||||
->assertSeeIn('div.row:nth-child(1) label', 'First name') | ->assertSeeIn('div.row:nth-child(1) label', 'First name') | ||||
->assertValue('div.row:nth-child(1) input[type=text]', $this->profile['first_name']) | ->assertValue('div.row:nth-child(1) input[type=text]', $this->profile['first_name']) | ||||
->assertSeeIn('div.row:nth-child(2) label', 'Last name') | ->assertSeeIn('div.row:nth-child(2) label', 'Last name') | ||||
->assertValue('div.row:nth-child(2) input[type=text]', $this->profile['last_name']) | ->assertValue('div.row:nth-child(2) input[type=text]', $this->profile['last_name']) | ||||
->assertSeeIn('div.row:nth-child(3) label', 'Phone') | ->assertSeeIn('div.row:nth-child(3) label', 'Phone') | ||||
Show All 21 Lines | public function testProfile(): void | ||||
->click('button[type=submit]'); | ->click('button[type=submit]'); | ||||
}) | }) | ||||
->with(new Toast(Toast::TYPE_SUCCESS), function (Browser $browser) { | ->with(new Toast(Toast::TYPE_SUCCESS), function (Browser $browser) { | ||||
$browser->assertToastTitle('') | $browser->assertToastTitle('') | ||||
->assertToastMessage('User data updated successfully') | ->assertToastMessage('User data updated successfully') | ||||
->closeToast(); | ->closeToast(); | ||||
}); | }); | ||||
// Test error handling | // Test error handling | ||||
$browser->with('@form', function (Browser $browser) { | $browser->with('@form', function (Browser $browser) { | ||||
$browser->type('#phone', 'aaaaaa') | $browser->type('#phone', 'aaaaaa') | ||||
->type('#external_email', 'bbbbb') | ->type('#external_email', 'bbbbb') | ||||
->click('button[type=submit]') | ->click('button[type=submit]') | ||||
->waitFor('#phone + .invalid-feedback') | ->waitFor('#phone + .invalid-feedback') | ||||
->assertSeeIn('#phone + .invalid-feedback', 'The phone format is invalid.') | ->assertSeeIn('#phone + .invalid-feedback', 'The phone format is invalid.') | ||||
->assertSeeIn( | ->assertSeeIn( | ||||
'#external_email + .invalid-feedback', | '#external_email + .invalid-feedback', | ||||
'The external email must be a valid email address.' | 'The external email must be a valid email address.' | ||||
) | ) | ||||
->assertFocused('#phone'); | ->assertFocused('#phone'); | ||||
}) | }) | ||||
->with(new Toast(Toast::TYPE_ERROR), function (Browser $browser) { | ->with(new Toast(Toast::TYPE_ERROR), function (Browser $browser) { | ||||
$browser->assertToastTitle('Error') | $browser->assertToastTitle('Error') | ||||
->assertToastMessage('Form validation error') | ->assertToastMessage('Form validation error') | ||||
->closeToast(); | ->closeToast(); | ||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
/** | |||||
* Test profile of non-controller user | |||||
*/ | |||||
public function testProfileNonController(): void | |||||
{ | |||||
// Test acting as non-controller | |||||
$this->browse(function (Browser $browser) { | |||||
$browser->visit('/logout') | |||||
->visit(new Home()) | |||||
->submitLogon('jack@kolab.org', 'simple123', true) | |||||
->on(new Dashboard()) | |||||
->assertSeeIn('@links .link-profile', 'Your profile') | |||||
->click('@links .link-profile') | |||||
->on(new UserProfile()) | |||||
->assertMissing('#user-profile .button-delete') | |||||
->whenAvailable('@form', function (Browser $browser) { | |||||
// TODO: decide on what fields the non-controller user should be able | |||||
// to see/change | |||||
}); | |||||
// Test that /profile/delete page is not accessible | |||||
$browser->visit('/profile/delete') | |||||
->assertErrorPage(403); | |||||
}); | |||||
} | |||||
/** | |||||
* Test profile delete page | |||||
*/ | |||||
public function testProfileDelete(): void | |||||
{ | |||||
$user = $this->getTestUser('profile-delete@kolabnow.com', ['password' => 'simple123']); | |||||
$this->browse(function (Browser $browser) use ($user) { | |||||
$browser->visit('/logout') | |||||
->on(new Home()) | |||||
->submitLogon('profile-delete@kolabnow.com', 'simple123', true) | |||||
->on(new Dashboard()) | |||||
->clearToasts() | |||||
->assertSeeIn('@links .link-profile', 'Your profile') | |||||
->click('@links .link-profile') | |||||
->on(new UserProfile()) | |||||
->click('#user-profile .button-delete') | |||||
->waitForLocation('/profile/delete') | |||||
->assertSeeIn('#user-delete .card-title', 'Delete this account?') | |||||
->assertSeeIn('#user-delete .button-cancel', 'Cancel') | |||||
->assertSeeIn('#user-delete .card-text', 'This operation is irreversible') | |||||
->assertFocused('#user-delete .button-cancel') | |||||
->click('#user-delete .button-cancel') | |||||
->waitForLocation('/profile') | |||||
->on(new UserProfile()); | |||||
// Test deleting the user | |||||
$browser->click('#user-profile .button-delete') | |||||
->waitForLocation('/profile/delete') | |||||
->click('#user-delete .button-delete') | |||||
->waitForLocation('/login') | |||||
->with(new Toast(Toast::TYPE_SUCCESS), function (Browser $browser) { | |||||
$browser->assertToastTitle('') | |||||
->assertToastMessage('User deleted successfully.') | |||||
->closeToast(); | |||||
}); | |||||
$this->assertTrue($user->fresh()->trashed()); | |||||
}); | |||||
} | |||||
// TODO: Test that Ned (John's "delegatee") can delete himself | |||||
// TODO: Test that Ned (John's "delegatee") can/can't delete John ? | |||||
} | } |