Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/Admin/UserTest.php
<?php | <?php | ||||
namespace Tests\Browser\Admin; | namespace Tests\Browser\Admin; | ||||
use App\Auth\SecondFactor; | |||||
use App\Discount; | use App\Discount; | ||||
use App\Sku; | |||||
use App\User; | use App\User; | ||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Components\Dialog; | use Tests\Browser\Components\Dialog; | ||||
use Tests\Browser\Components\Toast; | use Tests\Browser\Components\Toast; | ||||
use Tests\Browser\Pages\Admin\User as UserPage; | use Tests\Browser\Pages\Admin\User as UserPage; | ||||
use Tests\Browser\Pages\Dashboard; | use Tests\Browser\Pages\Dashboard; | ||||
use Tests\Browser\Pages\Home; | use Tests\Browser\Pages\Home; | ||||
use Tests\TestCaseDusk; | use Tests\TestCaseDusk; | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | public function testUserInfo(): void | ||||
->with('@user-subscriptions', function (Browser $browser) { | ->with('@user-subscriptions', function (Browser $browser) { | ||||
$browser->assertElementsCount('table tbody tr', 3) | $browser->assertElementsCount('table tbody tr', 3) | ||||
->assertSeeIn('table tbody tr:nth-child(1) td:first-child', 'User Mailbox') | ->assertSeeIn('table tbody tr:nth-child(1) td:first-child', 'User Mailbox') | ||||
->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '4,44 CHF') | ->assertSeeIn('table tbody tr:nth-child(1) td:last-child', '4,44 CHF') | ||||
->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 2 GB') | ->assertSeeIn('table tbody tr:nth-child(2) td:first-child', 'Storage Quota 2 GB') | ||||
->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF') | ->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF') | ||||
->assertSeeIn('table tbody tr:nth-child(3) td:first-child', 'Groupware Features') | ->assertSeeIn('table tbody tr:nth-child(3) td:first-child', 'Groupware Features') | ||||
->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '5,55 CHF') | ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '5,55 CHF') | ||||
->assertMissing('table tfoot'); | ->assertMissing('table tfoot') | ||||
->assertMissing('#reset2fa'); | |||||
}); | }); | ||||
// Assert Domains tab | // Assert Domains tab | ||||
$browser->assertSeeIn('@nav #tab-domains', 'Domains (0)') | $browser->assertSeeIn('@nav #tab-domains', 'Domains (0)') | ||||
->click('@nav #tab-domains') | ->click('@nav #tab-domains') | ||||
->with('@user-domains', function (Browser $browser) { | ->with('@user-domains', function (Browser $browser) { | ||||
$browser->assertElementsCount('table tbody tr', 0) | $browser->assertElementsCount('table tbody tr', 0) | ||||
->assertSeeIn('table tfoot tr td', 'There are no domains in this account.'); | ->assertSeeIn('table tfoot tr td', 'There are no domains in this account.'); | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | public function testUserInfo2(): void | ||||
->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF/month¹') | ->assertSeeIn('table tbody tr:nth-child(2) td:last-child', '0,00 CHF/month¹') | ||||
->assertSeeIn('table tbody tr:nth-child(3) td:first-child', 'Groupware Features') | ->assertSeeIn('table tbody tr:nth-child(3) td:first-child', 'Groupware Features') | ||||
->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,99 CHF/month¹') | ->assertSeeIn('table tbody tr:nth-child(3) td:last-child', '4,99 CHF/month¹') | ||||
->assertSeeIn('table tbody tr:nth-child(4) td:first-child', 'Activesync') | ->assertSeeIn('table tbody tr:nth-child(4) td:first-child', 'Activesync') | ||||
->assertSeeIn('table tbody tr:nth-child(4) td:last-child', '0,90 CHF/month¹') | ->assertSeeIn('table tbody tr:nth-child(4) td:last-child', '0,90 CHF/month¹') | ||||
->assertSeeIn('table tbody tr:nth-child(5) td:first-child', '2-Factor Authentication') | ->assertSeeIn('table tbody tr:nth-child(5) td:first-child', '2-Factor Authentication') | ||||
->assertSeeIn('table tbody tr:nth-child(5) td:last-child', '0,00 CHF/month¹') | ->assertSeeIn('table tbody tr:nth-child(5) td:last-child', '0,00 CHF/month¹') | ||||
->assertMissing('table tfoot') | ->assertMissing('table tfoot') | ||||
->assertSeeIn('table + .hint', '¹ applied discount: 10% - Test voucher'); | ->assertSeeIn('table + .hint', '¹ applied discount: 10% - Test voucher') | ||||
->assertSeeIn('#reset2fa', 'Reset 2-Factor Auth'); | |||||
}); | }); | ||||
// We don't expect John's domains here | // We don't expect John's domains here | ||||
$browser->assertSeeIn('@nav #tab-domains', 'Domains (0)') | $browser->assertSeeIn('@nav #tab-domains', 'Domains (0)') | ||||
->click('@nav #tab-domains') | ->click('@nav #tab-domains') | ||||
->with('@user-domains', function (Browser $browser) { | ->with('@user-domains', function (Browser $browser) { | ||||
$browser->assertElementsCount('table tbody tr', 0) | $browser->assertElementsCount('table tbody tr', 0) | ||||
->assertSeeIn('table tfoot tr td', 'There are no domains in this account.'); | ->assertSeeIn('table tfoot tr td', 'There are no domains in this account.'); | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | public function testSuspendAndUnsuspend(): void | ||||
->assertMissing('@user-info #button-suspend') | ->assertMissing('@user-info #button-suspend') | ||||
->click('@user-info #button-unsuspend') | ->click('@user-info #button-unsuspend') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'User unsuspended successfully.') | ->assertToast(Toast::TYPE_SUCCESS, 'User unsuspended successfully.') | ||||
->assertSeeIn('@user-info #status span.text-success', 'Active') | ->assertSeeIn('@user-info #status span.text-success', 'Active') | ||||
->assertVisible('@user-info #button-suspend') | ->assertVisible('@user-info #button-suspend') | ||||
->assertMissing('@user-info #button-unsuspend'); | ->assertMissing('@user-info #button-unsuspend'); | ||||
}); | }); | ||||
} | } | ||||
/** | |||||
* Test resetting 2FA for the user | |||||
*/ | |||||
public function testReset2FA(): void | |||||
{ | |||||
$this->browse(function (Browser $browser) { | |||||
$this->deleteTestUser('userstest1@kolabnow.com'); | |||||
$user = $this->getTestUser('userstest1@kolabnow.com'); | |||||
$sku2fa = Sku::firstOrCreate(['title' => '2fa']); | |||||
$user->assignSku($sku2fa); | |||||
SecondFactor::seed('userstest1@kolabnow.com'); | |||||
$browser->visit(new UserPage($user->id)) | |||||
->click('@nav #tab-subscriptions') | |||||
->with('@user-subscriptions', function (Browser $browser) use ($sku2fa) { | |||||
$browser->waitFor('#reset2fa') | |||||
->assertVisible('#sku' . $sku2fa->id); | |||||
}) | |||||
->assertSeeIn('@nav #tab-subscriptions', 'Subscriptions (1)') | |||||
->click('#reset2fa') | |||||
->with(new Dialog('#reset-2fa-dialog'), function (Browser $browser) { | |||||
$browser->assertSeeIn('@title', '2-Factor Authentication Reset') | |||||
->assertSeeIn('@button-cancel', 'Cancel') | |||||
->assertSeeIn('@button-action', 'Reset') | |||||
->click('@button-action'); | |||||
}) | |||||
->assertToast(Toast::TYPE_SUCCESS, '2-Factor authentication reset successfully.') | |||||
->assertMissing('#sku' . $sku2fa->id) | |||||
->assertSeeIn('@nav #tab-subscriptions', 'Subscriptions (0)'); | |||||
}); | |||||
} | |||||
} | } |