Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/UsersTest.php
<?php | <?php | ||||
namespace Tests\Browser; | namespace Tests\Browser; | ||||
use App\Discount; | |||||
use App\Entitlement; | use App\Entitlement; | ||||
use App\Sku; | use App\Sku; | ||||
use App\User; | use App\User; | ||||
use App\UserAlias; | use App\UserAlias; | ||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Components\Dialog; | use Tests\Browser\Components\Dialog; | ||||
use Tests\Browser\Components\ListInput; | use Tests\Browser\Components\ListInput; | ||||
use Tests\Browser\Components\QuotaInput; | use Tests\Browser\Components\QuotaInput; | ||||
Show All 22 Lines | public function setUp(): void | ||||
$this->deleteTestUser('julia.roberts@kolab.org'); | $this->deleteTestUser('julia.roberts@kolab.org'); | ||||
$john = User::where('email', 'john@kolab.org')->first(); | $john = User::where('email', 'john@kolab.org')->first(); | ||||
$john->setSettings($this->profile); | $john->setSettings($this->profile); | ||||
UserAlias::where('user_id', $john->id) | UserAlias::where('user_id', $john->id) | ||||
->where('alias', 'john.test@kolab.org')->delete(); | ->where('alias', 'john.test@kolab.org')->delete(); | ||||
Entitlement::where('entitleable_id', $john->id)->whereIn('cost', [25, 100])->delete(); | Entitlement::where('entitleable_id', $john->id)->whereIn('cost', [25, 100])->delete(); | ||||
$wallet = $john->wallets()->first(); | |||||
$wallet->discount()->dissociate(); | |||||
$wallet->save(); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('julia.roberts@kolab.org'); | $this->deleteTestUser('julia.roberts@kolab.org'); | ||||
$john = User::where('email', 'john@kolab.org')->first(); | $john = User::where('email', 'john@kolab.org')->first(); | ||||
$john->setSettings($this->profile); | $john->setSettings($this->profile); | ||||
UserAlias::where('user_id', $john->id) | UserAlias::where('user_id', $john->id) | ||||
->where('alias', 'john.test@kolab.org')->delete(); | ->where('alias', 'john.test@kolab.org')->delete(); | ||||
Entitlement::where('entitleable_id', $john->id)->whereIn('cost', [25, 100])->delete(); | Entitlement::where('entitleable_id', $john->id)->whereIn('cost', [25, 100])->delete(); | ||||
$wallet = $john->wallets()->first(); | |||||
$wallet->discount()->dissociate(); | |||||
$wallet->save(); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test user info page (unauthenticated) | * Test user info page (unauthenticated) | ||||
*/ | */ | ||||
public function testInfoUnauth(): void | public function testInfoUnauth(): void | ||||
{ | { | ||||
Show All 25 Lines | public function testList(): 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-users', 'User accounts') | ->assertSeeIn('@links .link-users', 'User accounts') | ||||
->click('@links .link-users') | ->click('@links .link-users') | ||||
->on(new UserList()) | ->on(new UserList()) | ||||
->whenAvailable('@table', function (Browser $browser) { | ->whenAvailable('@table', function (Browser $browser) { | ||||
$browser->assertElementsCount('tbody tr', 3) | $browser->assertElementsCount('tbody tr', 4) | ||||
->assertSeeIn('tbody tr:nth-child(1) a', 'jack@kolab.org') | ->assertSeeIn('tbody tr:nth-child(1) a', 'jack@kolab.org') | ||||
->assertSeeIn('tbody tr:nth-child(2) a', 'john@kolab.org') | ->assertSeeIn('tbody tr:nth-child(2) a', 'john@kolab.org') | ||||
->assertSeeIn('tbody tr:nth-child(3) a', 'ned@kolab.org') | ->assertSeeIn('tbody tr:nth-child(3) a', 'ned@kolab.org') | ||||
->assertVisible('tbody tr:nth-child(1) button.button-delete') | ->assertVisible('tbody tr:nth-child(1) button.button-delete') | ||||
->assertVisible('tbody tr:nth-child(2) button.button-delete') | ->assertVisible('tbody tr:nth-child(2) button.button-delete') | ||||
->assertVisible('tbody tr:nth-child(3) button.button-delete'); | ->assertVisible('tbody tr:nth-child(3) button.button-delete'); | ||||
}); | }); | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | public function testInfo(): void | ||||
->assertNotChecked('tbody tr:nth-child(5) td.selection input') | ->assertNotChecked('tbody tr:nth-child(5) td.selection input') | ||||
->assertEnabled('tbody tr:nth-child(5) td.selection input') | ->assertEnabled('tbody tr:nth-child(5) td.selection input') | ||||
->assertTip( | ->assertTip( | ||||
'tbody tr:nth-child(5) td.buttons button', | 'tbody tr:nth-child(5) td.buttons button', | ||||
'Mobile synchronization' | 'Mobile synchronization' | ||||
) | ) | ||||
->click('tbody tr:nth-child(5) td.selection input'); | ->click('tbody tr:nth-child(5) td.selection input'); | ||||
}) | }) | ||||
->assertMissing('@skus table + .hint') | |||||
->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(); | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | public function testNewUser(): void | ||||
->assertSeeIn('div.row:nth-child(6) label', 'Confirm password') | ->assertSeeIn('div.row:nth-child(6) label', 'Confirm password') | ||||
->assertValue('div.row:nth-child(6) input[type=password]', '') | ->assertValue('div.row:nth-child(6) input[type=password]', '') | ||||
->assertSeeIn('div.row:nth-child(7) label', 'Package') | ->assertSeeIn('div.row:nth-child(7) label', 'Package') | ||||
// assert packages list widget, select "Lite Account" | // assert packages list widget, select "Lite Account" | ||||
->with('@packages', function ($browser) { | ->with('@packages', function ($browser) { | ||||
$browser->assertElementsCount('tbody tr', 2) | $browser->assertElementsCount('tbody tr', 2) | ||||
->assertSeeIn('tbody tr:nth-child(1)', 'Groupware Account') | ->assertSeeIn('tbody tr:nth-child(1)', 'Groupware Account') | ||||
->assertSeeIn('tbody tr:nth-child(2)', 'Lite Account') | ->assertSeeIn('tbody tr:nth-child(2)', 'Lite Account') | ||||
->assertSeeIn('tbody tr:nth-child(1) .price', '9,99 CHF/month') | |||||
->assertSeeIn('tbody tr:nth-child(2) .price', '4,44 CHF/month') | |||||
->assertChecked('tbody tr:nth-child(1) input') | ->assertChecked('tbody tr:nth-child(1) input') | ||||
->click('tbody tr:nth-child(2) input') | ->click('tbody tr:nth-child(2) input') | ||||
->assertNotChecked('tbody tr:nth-child(1) input') | ->assertNotChecked('tbody tr:nth-child(1) input') | ||||
->assertChecked('tbody tr:nth-child(2) input'); | ->assertChecked('tbody tr:nth-child(2) input'); | ||||
}) | }) | ||||
->assertMissing('@packages table + .hint') | |||||
->assertSeeIn('button[type=submit]', 'Submit'); | ->assertSeeIn('button[type=submit]', 'Submit'); | ||||
// Test browser-side required fields and error handling | // Test browser-side required fields and error handling | ||||
$browser->click('button[type=submit]') | $browser->click('button[type=submit]') | ||||
->assertFocused('#email') | ->assertFocused('#email') | ||||
->type('#email', 'invalid email') | ->type('#email', 'invalid email') | ||||
->click('button[type=submit]') | ->click('button[type=submit]') | ||||
->assertFocused('#password') | ->assertFocused('#password') | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | public function testDeleteUser(): void | ||||
->assertElementsCount('tbody button.button-delete', 3); | ->assertElementsCount('tbody button.button-delete', 3); | ||||
}); | }); | ||||
// TODO: Test the delete action in details | // TODO: Test the delete action in details | ||||
}); | }); | ||||
// TODO: Test what happens with the logged in user session after he's been deleted by another user | // TODO: Test what happens with the logged in user session after he's been deleted by another user | ||||
} | } | ||||
/** | |||||
* Test discounted sku/package prices in the UI | |||||
*/ | |||||
public function testDiscountedPrices(): void | |||||
{ | |||||
// Add 10% discount | |||||
$discount = Discount::where('code', 'TEST')->first(); | |||||
$john = User::where('email', 'john@kolab.org')->first(); | |||||
$wallet = $john->wallet(); | |||||
$wallet->discount()->associate($discount); | |||||
$wallet->save(); | |||||
// SKUs on user edit page | |||||
$this->browse(function (Browser $browser) { | |||||
$browser->visit('/logout') | |||||
->on(new Home()) | |||||
->submitLogon('john@kolab.org', 'simple123', true) | |||||
->visit(new UserList()) | |||||
->click('@table tr:nth-child(2) a') | |||||
->on(new UserInfo()) | |||||
->with('@form', function (Browser $browser) { | |||||
$browser->whenAvailable('@skus', function (Browser $browser) { | |||||
$quota_input = new QuotaInput('tbody tr:nth-child(2) .range-input'); | |||||
$browser->assertElementsCount('tbody tr', 5) | |||||
// Mailbox SKU | |||||
->assertSeeIn('tbody tr:nth-child(1) td.price', '3,99 CHF/month¹') | |||||
// Storage SKU | |||||
->assertSeeIn('tr:nth-child(2) td.price', '0,00 CHF/month¹') | |||||
->with($quota_input, function (Browser $browser) { | |||||
$browser->setQuotaValue(100); | |||||
}) | |||||
->assertSeeIn('tr:nth-child(2) td.price', '21,56 CHF/month¹') | |||||
// groupware SKU | |||||
->assertSeeIn('tbody tr:nth-child(3) td.price', '4,99 CHF/month¹') | |||||
// 2FA SKU | |||||
->assertSeeIn('tbody tr:nth-child(4) td.price', '0,00 CHF/month¹') | |||||
// ActiveSync SKU | |||||
->assertSeeIn('tbody tr:nth-child(5) td.price', '0,90 CHF/month¹'); | |||||
}) | |||||
->assertSeeIn('@skus table + .hint', '¹ applied discount: 10% - Test voucher'); | |||||
}); | |||||
}); | |||||
// Packages on new user page | |||||
$this->browse(function (Browser $browser) { | |||||
$browser->visit(new UserList()) | |||||
->click('button.create-user') | |||||
->on(new UserInfo()) | |||||
->with('@form', function (Browser $browser) { | |||||
$browser->whenAvailable('@packages', function (Browser $browser) { | |||||
$browser->assertElementsCount('tbody tr', 2) | |||||
->assertSeeIn('tbody tr:nth-child(1) .price', '8,99 CHF/month¹') // Groupware | |||||
->assertSeeIn('tbody tr:nth-child(2) .price', '3,99 CHF/month¹'); // Lite | |||||
}) | |||||
->assertSeeIn('@packages table + .hint', '¹ applied discount: 10% - Test voucher'); | |||||
}); | |||||
}); | |||||
} | |||||
} | } |