Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/UsersTest.php
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | public function testList(): void | ||||
->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') | ||||
->assertSeeIn('tbody tr:nth-child(2) a', 'joe@kolab.org') | ->assertSeeIn('tbody tr:nth-child(2) a', 'joe@kolab.org') | ||||
->assertSeeIn('tbody tr:nth-child(3) a', 'john@kolab.org') | ->assertSeeIn('tbody tr:nth-child(3) a', 'john@kolab.org') | ||||
->assertSeeIn('tbody tr:nth-child(4) a', 'ned@kolab.org') | ->assertSeeIn('tbody tr:nth-child(4) a', 'ned@kolab.org') | ||||
->assertVisible('tbody tr:nth-child(1) 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(4) button.button-delete') | |||||
->assertMissing('tfoot'); | ->assertMissing('tfoot'); | ||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test user account editing page (not profile page) | * Test user account editing page (not profile page) | ||||
* | * | ||||
▲ Show 20 Lines • Show All 334 Lines • ▼ Show 20 Lines | class UsersTest extends TestCaseDusk | ||||
{ | { | ||||
// First create a new user | // First create a new user | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$julia = $this->getTestUser('julia.roberts@kolab.org'); | $julia = $this->getTestUser('julia.roberts@kolab.org'); | ||||
$package_kolab = \App\Package::where('title', 'kolab')->first(); | $package_kolab = \App\Package::where('title', 'kolab')->first(); | ||||
$john->assignPackage($package_kolab, $julia); | $john->assignPackage($package_kolab, $julia); | ||||
// Test deleting non-controller user | // Test deleting non-controller user | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) use ($julia) { | ||||
$browser->visit(new UserList()) | $browser->visit('/user/' . $julia->id) | ||||
->whenAvailable('@table', function (Browser $browser) { | ->on(new UserInfo()) | ||||
$browser->assertElementsCount('tbody tr', 5) | ->assertSeeIn('button.button-delete', 'Delete user') | ||||
->assertSeeIn('tbody tr:nth-child(4) a', 'julia.roberts@kolab.org') | ->click('button.button-delete') | ||||
->click('tbody tr:nth-child(4) button.button-delete'); | |||||
}) | |||||
->with(new Dialog('#delete-warning'), function (Browser $browser) { | ->with(new Dialog('#delete-warning'), function (Browser $browser) { | ||||
$browser->assertSeeIn('@title', 'Delete julia.roberts@kolab.org') | $browser->assertSeeIn('@title', 'Delete julia.roberts@kolab.org') | ||||
->assertFocused('@button-cancel') | ->assertFocused('@button-cancel') | ||||
->assertSeeIn('@button-cancel', 'Cancel') | ->assertSeeIn('@button-cancel', 'Cancel') | ||||
->assertSeeIn('@button-action', 'Delete') | ->assertSeeIn('@button-action', 'Delete') | ||||
->click('@button-cancel'); | ->click('@button-cancel'); | ||||
}) | }) | ||||
->whenAvailable('@table', function (Browser $browser) { | ->waitUntilMissing('#delete-warning') | ||||
$browser->click('tbody tr:nth-child(4) button.button-delete'); | ->click('button.button-delete') | ||||
}) | |||||
->with(new Dialog('#delete-warning'), function (Browser $browser) { | ->with(new Dialog('#delete-warning'), function (Browser $browser) { | ||||
$browser->click('@button-action'); | $browser->click('@button-action'); | ||||
}) | }) | ||||
->waitUntilMissing('#delete-warning') | |||||
->assertToast(Toast::TYPE_SUCCESS, 'User deleted successfully.') | ->assertToast(Toast::TYPE_SUCCESS, 'User deleted successfully.') | ||||
->on(new UserList()) | |||||
->with('@table', function (Browser $browser) { | ->with('@table', function (Browser $browser) { | ||||
$browser->assertElementsCount('tbody tr', 4) | $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', 'joe@kolab.org') | ->assertSeeIn('tbody tr:nth-child(2) a', 'joe@kolab.org') | ||||
->assertSeeIn('tbody tr:nth-child(3) a', 'john@kolab.org') | ->assertSeeIn('tbody tr:nth-child(3) a', 'john@kolab.org') | ||||
->assertSeeIn('tbody tr:nth-child(4) a', 'ned@kolab.org'); | ->assertSeeIn('tbody tr:nth-child(4) a', 'ned@kolab.org'); | ||||
}); | }); | ||||
$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 clicking Delete on the controller record redirects to /profile/delete | |||||
$browser | |||||
->with('@table', function (Browser $browser) { | |||||
$browser->click('tbody tr:nth-child(3) button.button-delete'); | |||||
}) | |||||
->waitForLocation('/profile/delete'); | |||||
}); | }); | ||||
// 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 | ||||
// Note: Access to /profile/delete page is tested in UserProfileTest.php | |||||
$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', 'simple123', true) | ||||
->visit(new UserList()) | ->visit(new UserList()) | ||||
->whenAvailable('@table', function (Browser $browser) { | ->whenAvailable('@table', function (Browser $browser) { | ||||
$browser->assertElementsCount('tbody tr', 0) | $browser->assertElementsCount('tbody tr', 0) | ||||
->assertSeeIn('tfoot td', 'There are no users in this account.'); | ->assertSeeIn('tfoot td', 'There are no users in this account.'); | ||||
}); | }); | ||||
}); | }); | ||||
// Test that controller user (Ned) can see/delete 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', 'simple123', 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); | ||||
->assertElementsCount('tbody button.button-delete', 4); | |||||
}); | }); | ||||
// 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 | ||||
} | } | ||||
▲ Show 20 Lines • Show All 127 Lines • Show Last 20 Lines |