Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/Admin/DashboardTest.php
<?php | <?php | ||||
namespace Tests\Browser\Admin; | namespace Tests\Browser\Admin; | ||||
use Illuminate\Support\Facades\Queue; | |||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Components\Toast; | use Tests\Browser\Components\Toast; | ||||
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; | ||||
use Illuminate\Foundation\Testing\DatabaseMigrations; | |||||
class DashboardTest extends TestCaseDusk | class DashboardTest extends TestCaseDusk | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
self::useAdminUrl(); | self::useAdminUrl(); | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$jack->setSetting('external_email', null); | $jack->setSetting('external_email', null); | ||||
$this->deleteTestUser('test@testsearch.com'); | |||||
$this->deleteTestDomain('testsearch.com'); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$jack->setSetting('external_email', null); | $jack->setSetting('external_email', null); | ||||
$this->deleteTestUser('test@testsearch.com'); | |||||
$this->deleteTestDomain('testsearch.com'); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test user search | * Test user search | ||||
*/ | */ | ||||
public function testSearch(): void | public function testSearch(): void | ||||
{ | { | ||||
Show All 13 Lines | public function testSearch(): void | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$jack->setSetting('external_email', 'john.doe.external@gmail.com'); | $jack->setSetting('external_email', 'john.doe.external@gmail.com'); | ||||
// Test search with multiple results | // Test search with multiple results | ||||
$browser->type('@search input', 'john.doe.external@gmail.com') | $browser->type('@search input', 'john.doe.external@gmail.com') | ||||
->click('@search form button') | ->click('@search form button') | ||||
->assertToast(Toast::TYPE_INFO, '2 user accounts have been found.') | ->assertToast(Toast::TYPE_INFO, '2 user accounts have been found.') | ||||
->whenAvailable('@search table', function (Browser $browser) { | ->whenAvailable('@search table', function (Browser $browser) use ($john, $jack) { | ||||
$browser->assertElementsCount('tbody tr', 2); | $browser->assertElementsCount('tbody tr', 2) | ||||
// TODO: Assert table content | ->with('tbody tr:first-child', function (Browser $browser) use ($jack) { | ||||
$browser->assertSeeIn('td:nth-child(1) a', $jack->email) | |||||
->assertSeeIn('td:nth-child(2) a', $jack->id) | |||||
->assertVisible('td:nth-child(3)') | |||||
->assertTextRegExp('td:nth-child(3)', '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/') | |||||
->assertVisible('td:nth-child(4)') | |||||
->assertText('td:nth-child(4)', ''); | |||||
}) | |||||
->with('tbody tr:last-child', function (Browser $browser) use ($john) { | |||||
$browser->assertSeeIn('td:nth-child(1) a', $john->email) | |||||
->assertSeeIn('td:nth-child(2) a', $john->id) | |||||
->assertVisible('td:nth-child(3)') | |||||
->assertTextRegExp('td:nth-child(3)', '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/') | |||||
->assertVisible('td:nth-child(4)') | |||||
->assertText('td:nth-child(4)', ''); | |||||
}); | |||||
}); | }); | ||||
// Test search with single record result -> redirect to user page | // Test search with single record result -> redirect to user page | ||||
$browser->type('@search input', 'kolab.org') | $browser->type('@search input', 'kolab.org') | ||||
->click('@search form button') | ->click('@search form button') | ||||
->assertMissing('@search table') | ->assertMissing('@search table') | ||||
->waitForLocation('/user/' . $john->id) | ->waitForLocation('/user/' . $john->id) | ||||
->waitUntilMissing('.app-loader') | ->waitUntilMissing('.app-loader') | ||||
->whenAvailable('#user-info', function (Browser $browser) use ($john) { | ->whenAvailable('#user-info', function (Browser $browser) use ($john) { | ||||
$browser->assertSeeIn('.card-title', $john->email); | $browser->assertSeeIn('.card-title', $john->email); | ||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
/** | |||||
* Test user search deleted user/domain | |||||
*/ | |||||
public function testSearchDeleted(): void | |||||
{ | |||||
$this->browse(function (Browser $browser) { | |||||
$browser->visit(new Home()) | |||||
->submitLogon('jeroen@jeroen.jeroen', 'jeroen', true) | |||||
->on(new Dashboard()) | |||||
->assertFocused('@search input') | |||||
->assertMissing('@search table'); | |||||
// Deleted users/domains | |||||
$domain = $this->getTestDomain('testsearch.com', ['type' => \App\Domain::TYPE_EXTERNAL]); | |||||
$user = $this->getTestUser('test@testsearch.com'); | |||||
$plan = \App\Plan::where('title', 'group')->first(); | |||||
$user->assignPlan($plan, $domain); | |||||
$user->setAliases(['alias@testsearch.com']); | |||||
Queue::fake(); | |||||
$user->delete(); | |||||
// Test search with multiple results | |||||
$browser->type('@search input', 'testsearch.com') | |||||
->click('@search form button') | |||||
->assertToast(Toast::TYPE_INFO, '1 user accounts have been found.') | |||||
->whenAvailable('@search table', function (Browser $browser) use ($user) { | |||||
$browser->assertElementsCount('tbody tr', 1) | |||||
->assertVisible('tbody tr:first-child.text-secondary') | |||||
->with('tbody tr:first-child', function (Browser $browser) use ($user) { | |||||
$browser->assertSeeIn('td:nth-child(1) span', $user->email) | |||||
->assertSeeIn('td:nth-child(2) span', $user->id) | |||||
->assertVisible('td:nth-child(3)') | |||||
->assertTextRegExp('td:nth-child(3)', '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/') | |||||
->assertVisible('td:nth-child(4)') | |||||
->assertTextRegExp('td:nth-child(4)', '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/'); | |||||
}); | |||||
}); | |||||
}); | |||||
} | |||||
} | } |