Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/Admin/UserTest.php
Show All 19 Lines | class UserTest extends TestCaseDusk | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
self::useAdminUrl(); | self::useAdminUrl(); | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$john->setSettings([ | $john->setSettings([ | ||||
'phone' => '+48123123123', | 'phone' => '+48123123123', | ||||
'external_email' => 'john.doe.external@gmail.com', | |||||
]); | ]); | ||||
$wallet = $john->wallets()->first(); | $wallet = $john->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->balance = 0; | $wallet->balance = 0; | ||||
$wallet->save(); | $wallet->save(); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$john->setSettings([ | $john->setSettings([ | ||||
'phone' => null, | 'phone' => null, | ||||
'external_email' => 'john.doe.external@gmail.com', | |||||
]); | ]); | ||||
$wallet = $john->wallets()->first(); | $wallet = $john->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->balance = 0; | $wallet->balance = 0; | ||||
$wallet->save(); | $wallet->save(); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
▲ Show 20 Lines • Show All 285 Lines • ▼ Show 20 Lines | public function testUserInfo2(): void | ||||
->with('@user-users', function (Browser $browser) { | ->with('@user-users', function (Browser $browser) { | ||||
$browser->assertElementsCount('table tbody tr', 0) | $browser->assertElementsCount('table tbody tr', 0) | ||||
->assertSeeIn('table tfoot tr td', 'There are no users in this account.'); | ->assertSeeIn('table tfoot tr td', 'There are no users in this account.'); | ||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test editing an external email | |||||
* | |||||
* @depends testUserInfo2 | |||||
*/ | |||||
public function testExternalEmail(): void | |||||
{ | |||||
$this->browse(function (Browser $browser) { | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$browser->visit(new UserPage($john->id)) | |||||
->waitFor('@user-info #external_email button') | |||||
->click('@user-info #external_email button') | |||||
// Test dialog content, and closing it with Cancel button | |||||
->with(new Dialog('#email-dialog'), function (Browser $browser) { | |||||
$browser->assertSeeIn('@title', 'External email') | |||||
->assertFocused('@body input') | |||||
->assertValue('@body input', 'john.doe.external@gmail.com') | |||||
->assertSeeIn('@button-cancel', 'Cancel') | |||||
->assertSeeIn('@button-action', 'Submit') | |||||
->click('@button-cancel'); | |||||
}) | |||||
->assertMissing('#email-dialog') | |||||
->click('@user-info #external_email button') | |||||
// Test email validation error handling, and email update | |||||
->with(new Dialog('#email-dialog'), function (Browser $browser) { | |||||
$browser->type('@body input', 'test') | |||||
->click('@button-action') | |||||
->waitFor('@body input.is-invalid') | |||||
->assertSeeIn( | |||||
'@body input + .invalid-feedback', | |||||
'The external email must be a valid email address.' | |||||
) | |||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | |||||
->type('@body input', 'test@test.com') | |||||
->click('@button-action'); | |||||
}) | |||||
->assertToast(Toast::TYPE_SUCCESS, 'User data updated successfully.') | |||||
->assertSeeIn('@user-info #external_email a', 'test@test.com') | |||||
->click('@user-info #external_email button') | |||||
->with(new Dialog('#email-dialog'), function (Browser $browser) { | |||||
$browser->assertValue('@body input', 'test@test.com') | |||||
->assertMissing('@body input.is-invalid') | |||||
->assertMissing('@body input + .invalid-feedback') | |||||
->click('@button-cancel'); | |||||
}) | |||||
->assertSeeIn('@user-info #external_email a', 'test@test.com'); | |||||
// $john->getSetting() may not work here as it uses internal cache | |||||
// read the value form database | |||||
$current_ext_email = $john->settings()->where('key', 'external_email')->first()->value; | |||||
$this->assertSame('test@test.com', $current_ext_email); | |||||
}); | |||||
} | |||||
/** | |||||
* Test editing wallet discount | * Test editing wallet discount | ||||
* | * | ||||
* @depends testUserInfo2 | * @depends testUserInfo2 | ||||
*/ | */ | ||||
public function testWalletDiscount(): void | public function testWalletDiscount(): void | ||||
{ | { | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |