Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/UsersTest.php
Show First 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | class UsersTest extends TestCaseDusk | ||||
/** | /** | ||||
* Test users list page | * Test users list page | ||||
*/ | */ | ||||
public function testList(): void | public function testList(): void | ||||
{ | { | ||||
// Test that the page requires authentication | // Test that the page requires authentication | ||||
$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', \App\Utils::generatePassphrase(), 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->waitFor('tbody tr') | $browser->waitFor('tbody tr') | ||||
->assertElementsCount('tbody tr', 4) | ->assertElementsCount('tbody tr', 4) | ||||
->assertSeeIn('tbody tr:nth-child(1) a', 'jack@kolab.org') | ->assertSeeIn('tbody tr:nth-child(1) a', 'jack@kolab.org') | ||||
▲ Show 20 Lines • Show All 284 Lines • ▼ Show 20 Lines | public function testNewUser(): void | ||||
->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') | ||||
->type('#password', 'simple123') | ->type('#password', \App\Utils::generatePassphrase()) | ||||
->click('button[type=submit]') | ->click('button[type=submit]') | ||||
->assertFocused('#password_confirmation') | ->assertFocused('#password_confirmation') | ||||
->type('#password_confirmation', 'simple') | ->type('#password_confirmation', 'simple') | ||||
->click('button[type=submit]') | ->click('button[type=submit]') | ||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ||||
->assertSeeIn('#email + .invalid-feedback', 'The specified email is invalid.') | ->assertSeeIn('#email + .invalid-feedback', 'The specified email is invalid.') | ||||
->assertSeeIn('#password + .invalid-feedback', 'The password confirmation does not match.'); | ->assertSeeIn('#password + .invalid-feedback', 'The password confirmation does not match.'); | ||||
}); | }); | ||||
// Test form error handling (aliases) | // Test form error handling (aliases) | ||||
$browser->with('@general', function (Browser $browser) { | $browser->with('@general', function (Browser $browser) { | ||||
$browser->type('#email', 'julia.roberts@kolab.org') | $browser->type('#email', 'julia.roberts@kolab.org') | ||||
->type('#password_confirmation', 'simple123') | ->type('#password_confirmation', \App\Utils::generatePassphrase()) | ||||
->with(new ListInput('#aliases'), function (Browser $browser) { | ->with(new ListInput('#aliases'), function (Browser $browser) { | ||||
$browser->addListEntry('invalid address'); | $browser->addListEntry('invalid address'); | ||||
}) | }) | ||||
->click('button[type=submit]') | ->click('button[type=submit]') | ||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ||||
->with(new ListInput('#aliases'), function (Browser $browser) { | ->with(new ListInput('#aliases'), function (Browser $browser) { | ||||
$browser->assertFormError(1, 'The specified alias is invalid.', false); | $browser->assertFormError(1, 'The specified alias is invalid.', false); | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | public function testDeleteUser(): void | ||||
$julia = User::where('email', 'julia.roberts@kolab.org')->first(); | $julia = User::where('email', 'julia.roberts@kolab.org')->first(); | ||||
$this->assertTrue(empty($julia)); | $this->assertTrue(empty($julia)); | ||||
}); | }); | ||||
// Test that non-controller user cannot see/delete himself on the users list | // Test that non-controller user cannot see/delete himself on the users list | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->visit('/logout') | $browser->visit('/logout') | ||||
->on(new Home()) | ->on(new Home()) | ||||
->submitLogon('jack@kolab.org', 'simple123', true) | ->submitLogon('jack@kolab.org', \App\Utils::generatePassphrase(), true) | ||||
->visit('/users') | ->visit('/users') | ||||
->assertErrorPage(403); | ->assertErrorPage(403); | ||||
}); | }); | ||||
// Test that controller user (Ned) can see all the users | // Test that controller user (Ned) can see all the users | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->visit('/logout') | $browser->visit('/logout') | ||||
->on(new Home()) | ->on(new Home()) | ||||
->submitLogon('ned@kolab.org', 'simple123', true) | ->submitLogon('ned@kolab.org', \App\Utils::generatePassphrase(), true) | ||||
->visit(new UserList()) | ->visit(new UserList()) | ||||
->whenAvailable('@table', function (Browser $browser) { | ->whenAvailable('@table', function (Browser $browser) { | ||||
$browser->assertElementsCount('tbody tr', 4); | $browser->assertElementsCount('tbody tr', 4); | ||||
}); | }); | ||||
// TODO: Test the delete action in details | // TODO: Test the delete action in details | ||||
}); | }); | ||||
Show All 11 Lines | public function testDiscountedPrices(): void | ||||
$wallet = $john->wallet(); | $wallet = $john->wallet(); | ||||
$wallet->discount()->associate($discount); | $wallet->discount()->associate($discount); | ||||
$wallet->save(); | $wallet->save(); | ||||
// SKUs on user edit page | // SKUs on user edit page | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->visit('/logout') | $browser->visit('/logout') | ||||
->on(new Home()) | ->on(new Home()) | ||||
->submitLogon('john@kolab.org', 'simple123', true) | ->submitLogon('john@kolab.org', \App\Utils::generatePassphrase(), true) | ||||
->visit(new UserList()) | ->visit(new UserList()) | ||||
->waitFor('@table tr:nth-child(2)') | ->waitFor('@table tr:nth-child(2)') | ||||
->click('@table tr:nth-child(2) a') // joe@kolab.org | ->click('@table tr:nth-child(2) a') // joe@kolab.org | ||||
->on(new UserInfo()) | ->on(new UserInfo()) | ||||
->with('@general', function (Browser $browser) { | ->with('@general', function (Browser $browser) { | ||||
$browser->whenAvailable('@skus', function (Browser $browser) { | $browser->whenAvailable('@skus', function (Browser $browser) { | ||||
$quota_input = new QuotaInput('tbody tr:nth-child(2) .range-input'); | $quota_input = new QuotaInput('tbody tr:nth-child(2) .range-input'); | ||||
$browser->waitFor('tbody tr') | $browser->waitFor('tbody tr') | ||||
▲ Show 20 Lines • Show All 171 Lines • Show Last 20 Lines |