Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/DomainTest.php
Show All 10 Lines | |||||
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\TestCaseDusk; | use Tests\TestCaseDusk; | ||||
use Illuminate\Foundation\Testing\DatabaseMigrations; | use Illuminate\Foundation\Testing\DatabaseMigrations; | ||||
class DomainTest extends TestCaseDusk | class DomainTest extends TestCaseDusk | ||||
{ | { | ||||
/** | |||||
* {@inheritDoc} | |||||
*/ | |||||
public function setUp(): void | |||||
{ | |||||
parent::setUp(); | |||||
$this->deleteTestDomain('testdomain.com'); | |||||
} | |||||
/** | |||||
* {@inheritDoc} | |||||
*/ | |||||
public function tearDown(): void | |||||
{ | |||||
$this->deleteTestDomain('testdomain.com'); | |||||
parent::tearDown(); | |||||
} | |||||
/** | /** | ||||
* Test domain info page (unauthenticated) | * Test domain info page (unauthenticated) | ||||
*/ | */ | ||||
public function testDomainInfoUnauth(): void | public function testDomainInfoUnauth(): void | ||||
{ | { | ||||
// Test that the page requires authentication | // Test that the page requires authentication | ||||
$this->browse(function ($browser) { | $this->browse(function ($browser) { | ||||
Show All 32 Lines | public function testDomainInfo(): void | ||||
$domain->status ^= Domain::STATUS_CONFIRMED; | $domain->status ^= Domain::STATUS_CONFIRMED; | ||||
$domain->save(); | $domain->save(); | ||||
} | } | ||||
$domain->setSetting('spf_whitelist', \json_encode(['.test.com'])); | $domain->setSetting('spf_whitelist', \json_encode(['.test.com'])); | ||||
$browser->visit('/domain/' . $domain->id) | $browser->visit('/domain/' . $domain->id) | ||||
->on(new DomainInfo()) | ->on(new DomainInfo()) | ||||
->assertSeeIn('.card-title', 'Domain') | |||||
->whenAvailable('@general', function ($browser) use ($domain) { | |||||
$browser->assertSeeIn('form div:nth-child(1) label', 'Status') | |||||
->assertSeeIn('form div:nth-child(1) #status.text-danger', 'Not Ready') | |||||
->assertSeeIn('form div:nth-child(2) label', 'Name') | |||||
->assertValue('form div:nth-child(2) input:disabled', $domain->namespace) | |||||
->assertSeeIn('form div:nth-child(3) label', 'Subscriptions'); | |||||
}) | |||||
->whenAvailable('@general form div:nth-child(3) table', function ($browser) { | |||||
$browser->assertElementsCount('tbody tr', 1) | |||||
->assertVisible('tbody tr td.selection input:checked:disabled') | |||||
->assertSeeIn('tbody tr td.name', 'External Domain') | |||||
->assertSeeIn('tbody tr td.price', '0,00 CHF/month') | |||||
->assertTip( | |||||
'tbody tr td.buttons button', | |||||
'Host a domain that is externally registered' | |||||
); | |||||
}) | |||||
->whenAvailable('@verify', function ($browser) use ($domain) { | ->whenAvailable('@verify', function ($browser) use ($domain) { | ||||
$browser->assertSeeIn('pre', $domain->namespace) | $browser->assertSeeIn('pre', $domain->namespace) | ||||
->assertSeeIn('pre', $domain->hash()) | ->assertSeeIn('pre', $domain->hash()) | ||||
->click('button') | ->click('button') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'Domain verified successfully.'); | ->assertToast(Toast::TYPE_SUCCESS, 'Domain verified successfully.'); | ||||
// TODO: Test scenario when a domain confirmation failed | // TODO: Test scenario when a domain confirmation failed | ||||
}) | }) | ||||
->whenAvailable('@config', function ($browser) use ($domain) { | ->whenAvailable('@config', function ($browser) use ($domain) { | ||||
$browser->assertSeeIn('pre', $domain->namespace); | $browser->assertSeeIn('pre', $domain->namespace); | ||||
}) | }) | ||||
->assertMissing('@general button[type=submit]') | |||||
->assertMissing('@verify'); | ->assertMissing('@verify'); | ||||
// Check that confirmed domain page contains only the config box | // Check that confirmed domain page contains only the config box | ||||
$browser->visit('/domain/' . $domain->id) | $browser->visit('/domain/' . $domain->id) | ||||
->on(new DomainInfo()) | ->on(new DomainInfo()) | ||||
->assertMissing('@verify') | ->assertMissing('@verify') | ||||
->assertPresent('@config'); | ->assertPresent('@config'); | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test domain settings | * Test domain settings | ||||
*/ | */ | ||||
public function testDomainSettings(): void | public function testDomainSettings(): void | ||||
{ | { | ||||
$this->browse(function ($browser) { | $this->browse(function ($browser) { | ||||
$domain = Domain::where('namespace', 'kolab.org')->first(); | $domain = Domain::where('namespace', 'kolab.org')->first(); | ||||
$domain->setSetting('spf_whitelist', \json_encode(['.test.com'])); | $domain->setSetting('spf_whitelist', \json_encode(['.test.com'])); | ||||
$browser->visit('/domain/' . $domain->id) | $browser->visit('/domain/' . $domain->id) | ||||
->on(new DomainInfo()) | ->on(new DomainInfo()) | ||||
->assertElementsCount('@nav a', 2) | ->assertElementsCount('@nav a', 2) | ||||
->assertSeeIn('@nav #tab-general', 'Domain configuration') | ->assertSeeIn('@nav #tab-general', 'General') | ||||
->assertSeeIn('@nav #tab-settings', 'Settings') | ->assertSeeIn('@nav #tab-settings', 'Settings') | ||||
->click('@nav #tab-settings') | ->click('@nav #tab-settings') | ||||
->with('#settings form', function (Browser $browser) { | ->with('#settings form', function (Browser $browser) { | ||||
// Test whitelist widget | // Test whitelist widget | ||||
$widget = new ListInput('#spf_whitelist'); | $widget = new ListInput('#spf_whitelist'); | ||||
$browser->assertSeeIn('div.row:nth-child(1) label', 'SPF Whitelist') | $browser->assertSeeIn('div.row:nth-child(1) label', 'SPF Whitelist') | ||||
->assertVisible('div.row:nth-child(1) .list-input') | ->assertVisible('div.row:nth-child(1) .list-input') | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | /* | ||||
->click('@links a.link-domains') | ->click('@links a.link-domains') | ||||
// On Domains List page click the domain entry | // On Domains List page click the domain entry | ||||
->on(new DomainList()) | ->on(new DomainList()) | ||||
->assertMissing('@table tbody') | ->assertMissing('@table tbody') | ||||
->assertSeeIn('tfoot td', 'There are no domains in this account.'); | ->assertSeeIn('tfoot td', 'There are no domains in this account.'); | ||||
*/ | */ | ||||
}); | }); | ||||
} | } | ||||
/** | |||||
* Test domain creation page | |||||
*/ | |||||
public function testDomainCreate(): void | |||||
{ | |||||
$this->browse(function ($browser) { | |||||
$browser->visit('/login') | |||||
->on(new Home()) | |||||
->submitLogon('john@kolab.org', 'simple123') | |||||
->visit('/domains') | |||||
->on(new DomainList()) | |||||
->assertSeeIn('.card-title button.btn-success', 'Create domain') | |||||
->click('.card-title button.btn-success') | |||||
->on(new DomainInfo()) | |||||
->assertSeeIn('.card-title', 'New domain') | |||||
->assertElementsCount('@nav li', 1) | |||||
->assertSeeIn('@nav li:first-child', 'General') | |||||
->whenAvailable('@general', function ($browser) { | |||||
$browser->assertSeeIn('form div:nth-child(1) label', 'Name') | |||||
->assertValue('form div:nth-child(1) input:not(:disabled)', '') | |||||
->assertFocused('form div:nth-child(1) input') | |||||
->assertSeeIn('form div:nth-child(2) label', 'Package') | |||||
->assertMissing('form div:nth-child(3)'); | |||||
}) | |||||
->whenAvailable('@general form div:nth-child(2) table', function ($browser) { | |||||
$browser->assertElementsCount('tbody tr', 1) | |||||
->assertVisible('tbody tr td.selection input:checked[readonly]') | |||||
->assertSeeIn('tbody tr td.name', 'Domain Hosting') | |||||
->assertSeeIn('tbody tr td.price', '0,00 CHF/month') | |||||
->assertTip( | |||||
'tbody tr td.buttons button', | |||||
'Use your own, existing domain.' | |||||
); | |||||
}) | |||||
->assertSeeIn('@general button.btn-primary[type=submit]', 'Submit') | |||||
->assertMissing('@config') | |||||
->assertMissing('@verify') | |||||
->assertMissing('@settings') | |||||
->assertMissing('@status') | |||||
// Test error handling | |||||
->click('button[type=submit]') | |||||
->waitFor('#namespace + .invalid-feedback') | |||||
->assertSeeIn('#namespace + .invalid-feedback', 'The namespace field is required.') | |||||
->assertFocused('#namespace') | |||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | |||||
->type('@general form div:nth-child(1) input', 'testdomain..com') | |||||
->click('button[type=submit]') | |||||
->waitFor('#namespace + .invalid-feedback') | |||||
->assertSeeIn('#namespace + .invalid-feedback', 'The specified domain is invalid.') | |||||
->assertFocused('#namespace') | |||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | |||||
// Test success | |||||
->type('@general form div:nth-child(1) input', 'testdomain.com') | |||||
->click('button[type=submit]') | |||||
->assertToast(Toast::TYPE_SUCCESS, 'Domain created successfully.') | |||||
->on(new DomainList()) | |||||
->assertSeeIn('@table tr:nth-child(2) a', 'testdomain.com'); | |||||
}); | |||||
} | |||||
} | } |