Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/ResourceTest.php
Show All 15 Lines | |||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
Resource::whereNotIn('email', ['resource-test1@kolab.org', 'resource-test2@kolab.org'])->delete(); | |||||
$this->clearBetaEntitlements(); | $this->clearBetaEntitlements(); | ||||
Resource::whereNotIn('email', ['resource-test1@kolab.org', 'resource-test2@kolab.org'])->delete(); | |||||
// Remove leftover entitlements that might interfere with the tests | |||||
\App\Entitlement::where('entitleable_type', 'App\\Resource') | |||||
->whereRaw('entitleable_id not in (select id from resources where deleted_at is null)') | |||||
->forceDelete(); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
\App\Sku::withEnvTenantContext()->where('title', 'resource')->update(['units_free' => 0]); | |||||
Resource::whereNotIn('email', ['resource-test1@kolab.org', 'resource-test2@kolab.org'])->delete(); | Resource::whereNotIn('email', ['resource-test1@kolab.org', 'resource-test2@kolab.org'])->delete(); | ||||
$this->clearBetaEntitlements(); | $this->clearBetaEntitlements(); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test resource info page (unauthenticated) | * Test resource info page (unauthenticated) | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | class ResourceTest extends TestCaseDusk | ||||
public function testCreateUpdateDelete(): void | public function testCreateUpdateDelete(): void | ||||
{ | { | ||||
// Test that the page is not available accessible without the 'beta' entitlement | // Test that the page is not available accessible without the 'beta' entitlement | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->visit('/resource/new') | $browser->visit('/resource/new') | ||||
->assertErrorPage(403); | ->assertErrorPage(403); | ||||
}); | }); | ||||
// Add beta entitlements | // Add beta entitlement | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$this->addBetaEntitlement($john); | $this->addBetaEntitlement($john); | ||||
\App\Sku::withEnvTenantContext()->where('title', 'resource')->update(['units_free' => 3]); | |||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
// Create a resource | // Create a resource | ||||
$browser->visit(new ResourceList()) | $browser->visit(new ResourceList()) | ||||
->assertSeeIn('button.resource-new', 'Create resource') | ->assertSeeIn('button.resource-new', 'Create resource') | ||||
->click('button.resource-new') | ->click('button.resource-new') | ||||
->on(new ResourceInfo()) | ->on(new ResourceInfo()) | ||||
->assertSeeIn('#resource-info .card-title', 'New resource') | ->assertSeeIn('#resource-info .card-title', 'New resource') | ||||
->assertSeeIn('@nav #tab-general', 'General') | ->assertSeeIn('@nav #tab-general', 'General') | ||||
->assertMissing('@nav #tab-settings') | ->assertMissing('@nav #tab-settings') | ||||
->with('@general', function (Browser $browser) { | ->with('@general', function (Browser $browser) { | ||||
// Assert form content | // Assert form content | ||||
$browser->assertMissing('#status') | $browser->assertMissing('#status') | ||||
->assertFocused('#name') | ->assertFocused('#name') | ||||
->assertSeeIn('div.row:nth-child(1) label', 'Name') | ->assertSeeIn('div.row:nth-child(1) label', 'Name') | ||||
->assertValue('div.row:nth-child(1) input[type=text]', '') | ->assertValue('div.row:nth-child(1) input[type=text]', '') | ||||
->assertSeeIn('div.row:nth-child(2) label', 'Domain') | ->assertSeeIn('div.row:nth-child(2) label', 'Domain') | ||||
->assertSelectHasOptions('div.row:nth-child(2) select', ['kolab.org']) | ->assertSelectHasOptions('div.row:nth-child(2) select', ['kolab.org']) | ||||
->assertValue('div.row:nth-child(2) select', 'kolab.org') | ->assertValue('div.row:nth-child(2) select', 'kolab.org') | ||||
->assertSeeIn('div.row:nth-child(3) label', 'Subscriptions') | |||||
->with('@skus', function ($browser) { | |||||
$browser->assertElementsCount('tbody tr', 1) | |||||
->assertSeeIn('tbody tr:nth-child(1) td.name', 'Resource') | |||||
->assertSeeIn('tbody tr:nth-child(1) td.price', '0,00 CHF/month') // one free unit left | |||||
->assertChecked('tbody tr:nth-child(1) td.selection input') | |||||
->assertDisabled('tbody tr:nth-child(1) td.selection input') | |||||
->assertTip( | |||||
'tbody tr:nth-child(1) td.buttons button', | |||||
'Reservation taker' | |||||
); | |||||
}) | |||||
->assertSeeIn('button[type=submit]', 'Submit'); | ->assertSeeIn('button[type=submit]', 'Submit'); | ||||
}) | }) | ||||
// Test error conditions | // Test error conditions | ||||
->type('#name', str_repeat('A', 192)) | ->type('#name', str_repeat('A', 192)) | ||||
->click('@general button[type=submit]') | ->click('@general button[type=submit]') | ||||
->waitFor('#name + .invalid-feedback') | ->waitFor('#name + .invalid-feedback') | ||||
->assertSeeIn('#name + .invalid-feedback', 'The name may not be greater than 191 characters.') | ->assertSeeIn('#name + .invalid-feedback', 'The name may not be greater than 191 characters.') | ||||
->assertFocused('#name') | ->assertFocused('#name') | ||||
Show All 17 Lines | public function testCreateUpdateDelete(): void | ||||
->assertSeeIn('div.row:nth-child(2) label', 'Name') | ->assertSeeIn('div.row:nth-child(2) label', 'Name') | ||||
->assertValue('div.row:nth-child(2) input[type=text]', 'Test Resource') | ->assertValue('div.row:nth-child(2) input[type=text]', 'Test Resource') | ||||
->assertSeeIn('div.row:nth-child(3) label', 'Email') | ->assertSeeIn('div.row:nth-child(3) label', 'Email') | ||||
->assertAttributeRegExp( | ->assertAttributeRegExp( | ||||
'div.row:nth-child(3) input[type=text]:disabled', | 'div.row:nth-child(3) input[type=text]:disabled', | ||||
'value', | 'value', | ||||
'/^resource-[0-9]+@kolab\.org$/' | '/^resource-[0-9]+@kolab\.org$/' | ||||
) | ) | ||||
->with('@skus', function ($browser) { | |||||
$browser->assertElementsCount('tbody tr', 1) | |||||
->assertSeeIn('tbody tr:nth-child(1) td.name', 'Resource') | |||||
->assertSeeIn('tbody tr:nth-child(1) td.price', '0,00 CHF/month') | |||||
->assertChecked('tbody tr:nth-child(1) td.selection input') | |||||
->assertDisabled('tbody tr:nth-child(1) td.selection input') | |||||
->assertTip( | |||||
'tbody tr:nth-child(1) td.buttons button', | |||||
'Reservation taker' | |||||
); | |||||
}) | |||||
->assertSeeIn('button[type=submit]', 'Submit'); | ->assertSeeIn('button[type=submit]', 'Submit'); | ||||
}) | }) | ||||
// Test error handling | // Test error handling | ||||
->type('#name', str_repeat('A', 192)) | ->type('#name', str_repeat('A', 192)) | ||||
->click('@general button[type=submit]') | ->click('@general button[type=submit]') | ||||
->waitFor('#name + .invalid-feedback') | ->waitFor('#name + .invalid-feedback') | ||||
->assertSeeIn('#name + .invalid-feedback', 'The name may not be greater than 191 characters.') | ->assertSeeIn('#name + .invalid-feedback', 'The name may not be greater than 191 characters.') | ||||
->assertVisible('#name.is-invalid') | ->assertVisible('#name.is-invalid') | ||||
Show All 15 Lines | public function testCreateUpdateDelete(): void | ||||
->assertSeeIn('button.button-delete', 'Delete resource') | ->assertSeeIn('button.button-delete', 'Delete resource') | ||||
->click('button.button-delete') | ->click('button.button-delete') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'Resource deleted successfully.') | ->assertToast(Toast::TYPE_SUCCESS, 'Resource deleted successfully.') | ||||
->on(new ResourceList()) | ->on(new ResourceList()) | ||||
->assertElementsCount('@table tbody tr', 2); | ->assertElementsCount('@table tbody tr', 2); | ||||
$this->assertNull(Resource::where('name', 'Test Resource Update')->first()); | $this->assertNull(Resource::where('name', 'Test Resource Update')->first()); | ||||
}); | }); | ||||
// Assert Subscription price for the case when there's no free units | |||||
\App\Sku::withEnvTenantContext()->where('title', 'resource')->update(['units_free' => 2]); | |||||
$this->browse(function (Browser $browser) { | |||||
$browser->visit('/resource/new') | |||||
->on(new ResourceInfo()) | |||||
->with('@skus', function ($browser) { | |||||
$browser->assertElementsCount('tbody tr', 1) | |||||
->assertSeeIn('tbody tr:nth-child(1) td.name', 'Resource') | |||||
->assertSeeIn('tbody tr:nth-child(1) td.price', '1,01 CHF/month') | |||||
->assertChecked('tbody tr:nth-child(1) td.selection input') | |||||
->assertDisabled('tbody tr:nth-child(1) td.selection input'); | |||||
}); | |||||
}); | |||||
} | } | ||||
/** | /** | ||||
* Test resource status | * Test resource status | ||||
* | * | ||||
* @depends testList | * @depends testList | ||||
*/ | */ | ||||
public function testStatus(): void | public function testStatus(): void | ||||
▲ Show 20 Lines • Show All 87 Lines • Show Last 20 Lines |