Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/StatusTest.php
<?php | <?php | ||||
namespace Tests\Browser; | namespace Tests\Browser; | ||||
use App\Domain; | use App\Domain; | ||||
use App\User; | use App\User; | ||||
use Carbon\Carbon; | |||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Components\Status; | |||||
use Tests\Browser\Components\Toast; | |||||
use Tests\Browser\Pages\Dashboard; | use Tests\Browser\Pages\Dashboard; | ||||
use Tests\Browser\Pages\DomainInfo; | use Tests\Browser\Pages\DomainInfo; | ||||
use Tests\Browser\Pages\DomainList; | use Tests\Browser\Pages\DomainList; | ||||
use Tests\Browser\Pages\Home; | use Tests\Browser\Pages\Home; | ||||
use Tests\Browser\Pages\UserInfo; | use Tests\Browser\Pages\UserInfo; | ||||
use Tests\Browser\Pages\UserList; | use Tests\Browser\Pages\UserList; | ||||
use Tests\TestCaseDusk; | use Tests\TestCaseDusk; | ||||
use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
class StatusTest extends TestCaseDusk | class StatusTest extends TestCaseDusk | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
DB::statement("UPDATE domains SET status = (status | " . Domain::STATUS_CONFIRMED . ")" | $domain_status = Domain::STATUS_CONFIRMED | Domain::STATUS_VERIFIED; | ||||
DB::statement("UPDATE domains SET status = (status | {$domain_status})" | |||||
. " WHERE namespace = 'kolab.org'"); | . " WHERE namespace = 'kolab.org'"); | ||||
DB::statement("UPDATE users SET status = (status | " . User::STATUS_IMAP_READY . ")" | DB::statement("UPDATE users SET status = (status | " . User::STATUS_IMAP_READY . ")" | ||||
. " WHERE email = 'john@kolab.org'"); | . " WHERE email = 'john@kolab.org'"); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
DB::statement("UPDATE domains SET status = (status | " . Domain::STATUS_CONFIRMED . ")" | $domain_status = Domain::STATUS_CONFIRMED | Domain::STATUS_VERIFIED; | ||||
DB::statement("UPDATE domains SET status = (status | {$domain_status})" | |||||
. " WHERE namespace = 'kolab.org'"); | . " WHERE namespace = 'kolab.org'"); | ||||
DB::statement("UPDATE users SET status = (status | " . User::STATUS_IMAP_READY . ")" | DB::statement("UPDATE users SET status = (status | " . User::STATUS_IMAP_READY . ")" | ||||
. " WHERE email = 'john@kolab.org'"); | . " WHERE email = 'john@kolab.org'"); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test account status in the Dashboard | * Test account status in the Dashboard | ||||
*/ | */ | ||||
public function testDashboard(): void | public function testDashboard(): void | ||||
{ | { | ||||
// Unconfirmed domain | // Unconfirmed domain and user | ||||
$domain = Domain::where('namespace', 'kolab.org')->first(); | $domain = Domain::where('namespace', 'kolab.org')->first(); | ||||
$domain->status ^= Domain::STATUS_CONFIRMED; | $domain->status ^= Domain::STATUS_CONFIRMED; | ||||
$domain->save(); | $domain->save(); | ||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$john->created_at = Carbon::now(); | |||||
$john->status ^= User::STATUS_IMAP_READY; | |||||
$john->save(); | |||||
$this->browse(function ($browser) use ($domain) { | $this->browse(function ($browser) use ($john, $domain) { | ||||
$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()) | ||||
->whenAvailable('@status', function ($browser) { | ->with(new Status(), function ($browser) use ($john) { | ||||
$browser->assertSeeIn('.card-title', 'Account status:') | $browser->assertSeeIn('@body', 'We are preparing your account') | ||||
->assertSeeIn('.card-title span.text-danger', 'Not ready') | ->assertProgress(28, 'Creating a mailbox...', 'pending') | ||||
->with('ul.status-list', function ($browser) { | ->assertMissing('#status-verify') | ||||
$browser->assertElementsCount('li', 7) | ->assertMissing('#status-link') | ||||
->assertVisible('li:nth-child(1) svg.fa-check-square') | ->assertMissing('@refresh-button') | ||||
->assertSeeIn('li:nth-child(1) span', 'User registered') | ->assertMissing('@refresh-text'); | ||||
->assertVisible('li:nth-child(2) svg.fa-check-square') | |||||
->assertSeeIn('li:nth-child(2) span', 'User created') | $john->created_at = Carbon::now(); | ||||
->assertVisible('li:nth-child(3) svg.fa-check-square') | $john->status ^= User::STATUS_IMAP_READY; | ||||
->assertSeeIn('li:nth-child(3) span', 'User mailbox created') | $john->save(); | ||||
->assertVisible('li:nth-child(4) svg.fa-check-square') | |||||
->assertSeeIn('li:nth-child(4) span', 'Custom domain registered') | // Wait for auto-refresh, expect domain-confirmed step | ||||
->assertVisible('li:nth-child(5) svg.fa-check-square') | $browser->pause(6000) | ||||
->assertSeeIn('li:nth-child(5) span', 'Custom domain created') | ->assertSeeIn('@body', 'Your account is almost ready') | ||||
->assertVisible('li:nth-child(6) svg.fa-check-square') | ->assertProgress(85, 'Verifying an ownership of a custom domain...', 'failed') | ||||
->assertSeeIn('li:nth-child(6) span', 'Custom domain verified') | ->assertMissing('@refresh-button') | ||||
->assertVisible('li:nth-child(7) svg.fa-square') | ->assertMissing('@refresh-text') | ||||
->assertSeeIn('li:nth-child(7) a', 'Custom domain ownership verified'); | ->assertMissing('#status-verify') | ||||
}); | ->assertVisible('#status-link'); | ||||
}) | |||||
// check if the link to domain info page works | |||||
->click('#status-link') | |||||
->on(new DomainInfo()) | |||||
->back() | |||||
->on(new Dashboard()) | |||||
->with(new Status(), function ($browser) use ($john) { | |||||
$browser->assertMissing('@refresh-button') | |||||
->assertProgress(85, 'Verifying an ownership of a custom domain...', 'failed'); | |||||
}); | }); | ||||
// Confirm the domain and wait until the whole status box disappears | // Confirm the domain and wait until the whole status box disappears | ||||
$domain->status |= Domain::STATUS_CONFIRMED; | $domain->status |= Domain::STATUS_CONFIRMED; | ||||
$domain->save(); | $domain->save(); | ||||
// At the moment, this may take about 10 seconds | // This should take less than 10 seconds | ||||
$browser->waitUntilMissing('@status', 15); | $browser->waitUntilMissing('@status', 10); | ||||
}); | |||||
// Test the Refresh button | |||||
$domain->status ^= Domain::STATUS_CONFIRMED; | |||||
$domain->save(); | |||||
$john->created_at = Carbon::now()->subSeconds(3600); | |||||
$john->status ^= User::STATUS_IMAP_READY; | |||||
$john->save(); | |||||
$this->browse(function ($browser) use ($john, $domain) { | |||||
$browser->visit(new Dashboard()) | |||||
->with(new Status(), function ($browser) use ($john, $domain) { | |||||
$browser->assertSeeIn('@body', 'We are preparing your account') | |||||
->assertProgress(28, 'Creating a mailbox...', 'failed') | |||||
->assertVisible('@refresh-button') | |||||
->assertVisible('@refresh-text'); | |||||
$john->status ^= User::STATUS_IMAP_READY; | |||||
$john->save(); | |||||
$domain->status |= Domain::STATUS_CONFIRMED; | |||||
$domain->save(); | |||||
$browser->click('@refresh-button') | |||||
->assertToast(Toast::TYPE_SUCCESS, 'Setup process finished successfully.'); | |||||
}) | |||||
->assertMissing('@status'); | |||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test domain status on domains list and domain info page | * Test domain status on domains list and domain info page | ||||
* | * | ||||
* @depends testDashboard | * @depends testDashboard | ||||
*/ | */ | ||||
public function testDomainStatus(): void | public function testDomainStatus(): void | ||||
{ | { | ||||
$domain = Domain::where('namespace', 'kolab.org')->first(); | $domain = Domain::where('namespace', 'kolab.org')->first(); | ||||
$domain->status ^= Domain::STATUS_CONFIRMED; | $domain->created_at = Carbon::now(); | ||||
$domain->status ^= Domain::STATUS_CONFIRMED | Domain::STATUS_VERIFIED; | |||||
$domain->save(); | $domain->save(); | ||||
$this->browse(function ($browser) use ($domain) { | $this->browse(function ($browser) use ($domain) { | ||||
// Test auto-refresh | |||||
$browser->on(new Dashboard()) | $browser->on(new Dashboard()) | ||||
->click('@links a.link-domains') | ->click('@links a.link-domains') | ||||
->on(new DomainList()) | ->on(new DomainList()) | ||||
// Assert domain status icon | // Assert domain status icon | ||||
->assertVisible('@table tbody tr:first-child td:first-child svg.fa-globe.text-danger') | ->assertVisible('@table tbody tr:first-child td:first-child svg.fa-globe.text-danger') | ||||
->assertText('@table tbody tr:first-child td:first-child svg title', 'Not Ready') | ->assertText('@table tbody tr:first-child td:first-child svg title', 'Not Ready') | ||||
->click('@table tbody tr:first-child td:first-child a') | ->click('@table tbody tr:first-child td:first-child a') | ||||
->on(new DomainInfo()) | ->on(new DomainInfo()) | ||||
->whenAvailable('@status', function ($browser) { | ->with(new Status(), function ($browser) { | ||||
$browser->assertSeeIn('.card-title', 'Domain status:') | $browser->assertSeeIn('@body', 'We are preparing the domain') | ||||
->assertSeeIn('.card-title span.text-danger', 'Not ready') | ->assertProgress(50, 'Verifying a custom domain...', 'pending') | ||||
->with('ul.status-list', function ($browser) { | ->assertMissing('@refresh-button') | ||||
$browser->assertElementsCount('li', 4) | ->assertMissing('@refresh-text') | ||||
->assertVisible('li:nth-child(1) svg.fa-check-square') | ->assertMissing('#status-link') | ||||
->assertSeeIn('li:nth-child(1) span', 'Custom domain registered') | ->assertMissing('#status-verify'); | ||||
->assertVisible('li:nth-child(2) svg.fa-check-square') | |||||
->assertSeeIn('li:nth-child(2) span', 'Custom domain created') | |||||
->assertVisible('li:nth-child(3) svg.fa-check-square') | |||||
->assertSeeIn('li:nth-child(3) span', 'Custom domain verified') | |||||
->assertVisible('li:nth-child(4) svg.fa-square') | |||||
->assertSeeIn('li:nth-child(4) span', 'Custom domain ownership verified'); | |||||
}); | }); | ||||
$domain->status |= Domain::STATUS_VERIFIED; | |||||
$domain->save(); | |||||
// This should take less than 10 seconds | |||||
$browser->waitFor('@status.process-failed') | |||||
->with(new Status(), function ($browser) { | |||||
$browser->assertSeeIn('@body', 'The domain is almost ready') | |||||
->assertProgress(75, 'Verifying an ownership of a custom domain...', 'failed') | |||||
->assertMissing('@refresh-button') | |||||
->assertMissing('@refresh-text') | |||||
->assertMissing('#status-link') | |||||
->assertVisible('#status-verify'); | |||||
}); | }); | ||||
// Confirm the domain and wait until the whole status box disappears | |||||
$domain->status |= Domain::STATUS_CONFIRMED; | $domain->status |= Domain::STATUS_CONFIRMED; | ||||
$domain->save(); | $domain->save(); | ||||
// At the moment, this may take about 10 seconds | // Test Verify button | ||||
$browser->waitUntilMissing('@status', 15); | $browser->click('@status #status-verify') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'Domain verified successfully.') | |||||
->waitUntilMissing('@status') | |||||
->assertMissing('@verify') | |||||
->assertVisible('@config'); | |||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test user status on users list | * Test user status on users list and user info page | ||||
* | * | ||||
* @depends testDashboard | * @depends testDashboard | ||||
*/ | */ | ||||
public function testUserStatus(): void | public function testUserStatus(): void | ||||
{ | { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$john->created_at = Carbon::now(); | |||||
$john->status ^= User::STATUS_IMAP_READY; | $john->status ^= User::STATUS_IMAP_READY; | ||||
$john->save(); | $john->save(); | ||||
$this->browse(function ($browser) { | $domain = Domain::where('namespace', 'kolab.org')->first(); | ||||
$domain->status ^= Domain::STATUS_CONFIRMED; | |||||
$domain->save(); | |||||
$this->browse(function ($browser) use ($john, $domain) { | |||||
$browser->visit(new Dashboard()) | $browser->visit(new Dashboard()) | ||||
->click('@links a.link-users') | ->click('@links a.link-users') | ||||
->on(new UserList()) | ->on(new UserList()) | ||||
// Assert user status icons | // Assert user status icons | ||||
->assertVisible('@table tbody tr:first-child td:first-child svg.fa-user.text-success') | ->assertVisible('@table tbody tr:first-child td:first-child svg.fa-user.text-success') | ||||
->assertText('@table tbody tr:first-child td:first-child svg title', 'Active') | ->assertText('@table tbody tr:first-child td:first-child svg title', 'Active') | ||||
->assertVisible('@table tbody tr:nth-child(3) td:first-child svg.fa-user.text-danger') | ->assertVisible('@table tbody tr:nth-child(3) td:first-child svg.fa-user.text-danger') | ||||
->assertText('@table tbody tr:nth-child(3) td:first-child svg title', 'Not Ready') | ->assertText('@table tbody tr:nth-child(3) td:first-child svg title', 'Not Ready') | ||||
->click('@table tbody tr:nth-child(3) td:first-child a') | ->click('@table tbody tr:nth-child(3) td:first-child a') | ||||
->on(new UserInfo()) | ->on(new UserInfo()) | ||||
->with('@form', function (Browser $browser) { | ->with('@form', function (Browser $browser) { | ||||
// Assert stet in the user edit form | // Assert state in the user edit form | ||||
$browser->assertSeeIn('div.row:nth-child(1) label', 'Status') | $browser->assertSeeIn('div.row:nth-child(1) label', 'Status') | ||||
->assertSeeIn('div.row:nth-child(1) #status', 'Not Ready'); | ->assertSeeIn('div.row:nth-child(1) #status', 'Not Ready'); | ||||
}); | }) | ||||
->with(new Status(), function ($browser) use ($john) { | |||||
$browser->assertSeeIn('@body', 'We are preparing the user account') | |||||
->assertProgress(28, 'Creating a mailbox...', 'pending') | |||||
->assertMissing('#status-verify') | |||||
->assertMissing('#status-link') | |||||
->assertMissing('@refresh-button') | |||||
->assertMissing('@refresh-text'); | |||||
$john->status ^= User::STATUS_IMAP_READY; | |||||
$john->save(); | |||||
// Wait for auto-refresh, expect domain-confirmed step | |||||
$browser->pause(6000) | |||||
->assertSeeIn('@body', 'The user account is almost ready') | |||||
->assertProgress(85, 'Verifying an ownership of a custom domain...', 'failed') | |||||
->assertMissing('@refresh-button') | |||||
->assertMissing('@refresh-text') | |||||
->assertMissing('#status-verify') | |||||
->assertVisible('#status-link'); | |||||
}) | |||||
->assertSeeIn('#status', 'Active'); | |||||
// Confirm the domain and wait until the whole status box disappears | |||||
$domain->status |= Domain::STATUS_CONFIRMED; | |||||
$domain->save(); | |||||
// TODO: The status should also be live-updated here | // This should take less than 10 seconds | ||||
// Maybe when we have proper websocket communication | $browser->waitUntilMissing('@status', 10); | ||||
}); | }); | ||||
} | } | ||||
} | } |