Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/DomainTest.php
<?php | <?php | ||||
namespace Tests\Browser; | namespace Tests\Browser; | ||||
use App\Domain; | use App\Domain; | ||||
use App\User; | use App\User; | ||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Components\Dialog; | |||||
use Tests\Browser\Components\ListInput; | use Tests\Browser\Components\ListInput; | ||||
use Tests\Browser\Components\Toast; | 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\TestCaseDusk; | use Tests\TestCaseDusk; | ||||
use Illuminate\Foundation\Testing\DatabaseMigrations; | use Illuminate\Foundation\Testing\DatabaseMigrations; | ||||
▲ Show 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | public function testDomainCreate(): void | ||||
// Test success | // Test success | ||||
->type('@general form div:nth-child(1) input', 'testdomain.com') | ->type('@general form div:nth-child(1) input', 'testdomain.com') | ||||
->click('button[type=submit]') | ->click('button[type=submit]') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'Domain created successfully.') | ->assertToast(Toast::TYPE_SUCCESS, 'Domain created successfully.') | ||||
->on(new DomainList()) | ->on(new DomainList()) | ||||
->assertSeeIn('@table tr:nth-child(2) a', 'testdomain.com'); | ->assertSeeIn('@table tr:nth-child(2) a', 'testdomain.com'); | ||||
}); | }); | ||||
} | } | ||||
/** | |||||
* Test domain deletion | |||||
*/ | |||||
public function testDomainDelete(): void | |||||
{ | |||||
// Create the domain to delete | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$domain = $this->getTestDomain('testdomain.com', ['type' => Domain::TYPE_EXTERNAL]); | |||||
$packageDomain = \App\Package::withEnvTenantContext()->where('title', 'domain-hosting')->first(); | |||||
$domain->assignPackage($packageDomain, $john); | |||||
$this->browse(function ($browser) { | |||||
$browser->visit('/login') | |||||
->on(new Home()) | |||||
->submitLogon('john@kolab.org', 'simple123') | |||||
->visit('/domains') | |||||
->on(new DomainList()) | |||||
->assertElementsCount('@table tbody tr', 2) | |||||
->assertSeeIn('@table tr:nth-child(2) a', 'testdomain.com') | |||||
->click('@table tbody tr:nth-child(2) a') | |||||
->on(new DomainInfo()) | |||||
->waitFor('button.button-delete') | |||||
->assertSeeIn('button.button-delete', 'Delete domain') | |||||
->click('button.button-delete') | |||||
->with(new Dialog('#delete-warning'), function ($browser) { | |||||
$browser->assertSeeIn('@title', 'Delete testdomain.com') | |||||
->assertFocused('@button-cancel') | |||||
->assertSeeIn('@button-cancel', 'Cancel') | |||||
->assertSeeIn('@button-action', 'Delete') | |||||
->click('@button-cancel'); | |||||
}) | |||||
->waitUntilMissing('#delete-warning') | |||||
->click('button.button-delete') | |||||
->with(new Dialog('#delete-warning'), function (Browser $browser) { | |||||
$browser->click('@button-action'); | |||||
}) | |||||
->waitUntilMissing('#delete-warning') | |||||
->assertToast(Toast::TYPE_SUCCESS, 'Domain deleted successfully.') | |||||
->on(new DomainList()) | |||||
->assertElementsCount('@table tbody tr', 1); | |||||
// Test error handling on deleting a non-empty domain | |||||
$err = 'Unable to delete a domain with assigned users or other objects.'; | |||||
$browser->click('@table tbody tr:nth-child(1) a') | |||||
->on(new DomainInfo()) | |||||
->waitFor('button.button-delete') | |||||
->click('button.button-delete') | |||||
->with(new Dialog('#delete-warning'), function ($browser) { | |||||
$browser->click('@button-action'); | |||||
}) | |||||
->assertToast(Toast::TYPE_ERROR, $err); | |||||
}); | |||||
} | |||||
} | } |