Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/DistlistTest.php
Show First 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | public function testCreateUpdateDelete(): void | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
// Create a group | // Create a group | ||||
$browser->visit(new DistlistList()) | $browser->visit(new DistlistList()) | ||||
->assertSeeIn('button.create-list', 'Create list') | ->assertSeeIn('button.create-list', 'Create list') | ||||
->click('button.create-list') | ->click('button.create-list') | ||||
->on(new DistlistInfo()) | ->on(new DistlistInfo()) | ||||
->assertSeeIn('#distlist-info .card-title', 'New distribution list') | ->assertSeeIn('#distlist-info .card-title', 'New distribution list') | ||||
->with('@form', function (Browser $browser) { | ->assertSeeIn('@nav #tab-general', 'General') | ||||
->assertMissing('@nav #tab-settings') | |||||
->with('@general', function (Browser $browser) { | |||||
// Assert form content | // Assert form content | ||||
$browser->assertMissing('#status') | $browser->assertMissing('#status') | ||||
->assertSeeIn('div.row:nth-child(1) label', 'Email') | ->assertSeeIn('div.row:nth-child(1) label', 'Email') | ||||
->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', 'Recipients') | ->assertSeeIn('div.row:nth-child(2) label', 'Recipients') | ||||
->assertVisible('div.row:nth-child(2) .list-input') | ->assertVisible('div.row:nth-child(2) .list-input') | ||||
->with(new ListInput('#members'), function (Browser $browser) { | ->with(new ListInput('#members'), function (Browser $browser) { | ||||
$browser->assertListInputValue([]) | $browser->assertListInputValue([]) | ||||
->assertValue('@input', ''); | ->assertValue('@input', ''); | ||||
}) | }) | ||||
->assertSeeIn('button[type=submit]', 'Submit'); | ->assertSeeIn('button[type=submit]', 'Submit'); | ||||
}) | }) | ||||
// Test error conditions | // Test error conditions | ||||
->type('#email', 'group-test@kolabnow.com') | ->type('#email', 'group-test@kolabnow.com') | ||||
->click('button[type=submit]') | ->click('@general button[type=submit]') | ||||
->waitFor('#email + .invalid-feedback') | ->waitFor('#email + .invalid-feedback') | ||||
->assertSeeIn('#email + .invalid-feedback', 'The specified domain is not available.') | ->assertSeeIn('#email + .invalid-feedback', 'The specified domain is not available.') | ||||
->assertFocused('#email') | ->assertFocused('#email') | ||||
->waitFor('#members + .invalid-feedback') | ->waitFor('#members + .invalid-feedback') | ||||
->assertSeeIn('#members + .invalid-feedback', 'At least one recipient is required.') | ->assertSeeIn('#members + .invalid-feedback', 'At least one recipient is required.') | ||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ||||
// Test successful group creation | // Test successful group creation | ||||
->type('#email', 'group-test@kolab.org') | ->type('#email', 'group-test@kolab.org') | ||||
->with(new ListInput('#members'), function (Browser $browser) { | ->with(new ListInput('#members'), function (Browser $browser) { | ||||
$browser->addListEntry('test1@gmail.com') | $browser->addListEntry('test1@gmail.com') | ||||
->addListEntry('test2@gmail.com'); | ->addListEntry('test2@gmail.com'); | ||||
}) | }) | ||||
->click('button[type=submit]') | ->click('@general button[type=submit]') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'Distribution list created successfully.') | ->assertToast(Toast::TYPE_SUCCESS, 'Distribution list created successfully.') | ||||
->on(new DistlistList()) | ->on(new DistlistList()) | ||||
->assertElementsCount('@table tbody tr', 1); | ->assertElementsCount('@table tbody tr', 1); | ||||
// Test group update | // Test group update | ||||
$browser->click('@table tr:nth-child(1) a') | $browser->click('@table tr:nth-child(1) a') | ||||
->on(new DistlistInfo()) | ->on(new DistlistInfo()) | ||||
->assertSeeIn('#distlist-info .card-title', 'Distribution list') | ->assertSeeIn('#distlist-info .card-title', 'Distribution list') | ||||
->with('@form', function (Browser $browser) { | ->with('@general', function (Browser $browser) { | ||||
// Assert form content | // Assert form content | ||||
$browser->assertSeeIn('div.row:nth-child(1) label', 'Status') | $browser->assertSeeIn('div.row:nth-child(1) label', 'Status') | ||||
->assertSeeIn('div.row:nth-child(1) span.text-danger', 'Not Ready') | ->assertSeeIn('div.row:nth-child(1) span.text-danger', 'Not Ready') | ||||
->assertSeeIn('div.row:nth-child(2) label', 'Email') | ->assertSeeIn('div.row:nth-child(2) label', 'Email') | ||||
->assertValue('div.row:nth-child(2) input[type=text]:disabled', 'group-test@kolab.org') | ->assertValue('div.row:nth-child(2) input[type=text]:disabled', 'group-test@kolab.org') | ||||
->assertSeeIn('div.row:nth-child(3) label', 'Recipients') | ->assertSeeIn('div.row:nth-child(3) label', 'Recipients') | ||||
->assertVisible('div.row:nth-child(3) .list-input') | ->assertVisible('div.row:nth-child(3) .list-input') | ||||
->with(new ListInput('#members'), function (Browser $browser) { | ->with(new ListInput('#members'), function (Browser $browser) { | ||||
$browser->assertListInputValue(['test1@gmail.com', 'test2@gmail.com']) | $browser->assertListInputValue(['test1@gmail.com', 'test2@gmail.com']) | ||||
->assertValue('@input', ''); | ->assertValue('@input', ''); | ||||
}) | }) | ||||
->assertSeeIn('button[type=submit]', 'Submit'); | ->assertSeeIn('button[type=submit]', 'Submit'); | ||||
}) | }) | ||||
// Test error handling | // Test error handling | ||||
->with(new ListInput('#members'), function (Browser $browser) { | ->with(new ListInput('#members'), function (Browser $browser) { | ||||
$browser->addListEntry('invalid address'); | $browser->addListEntry('invalid address'); | ||||
}) | }) | ||||
->click('button[type=submit]') | ->click('@general button[type=submit]') | ||||
->waitFor('#members + .invalid-feedback') | ->waitFor('#members + .invalid-feedback') | ||||
->assertSeeIn('#members + .invalid-feedback', 'The specified email address is invalid.') | ->assertSeeIn('#members + .invalid-feedback', 'The specified email address is invalid.') | ||||
->assertVisible('#members .input-group:nth-child(4) input.is-invalid') | ->assertVisible('#members .input-group:nth-child(4) input.is-invalid') | ||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ->assertToast(Toast::TYPE_ERROR, 'Form validation error') | ||||
// Test successful update | // Test successful update | ||||
->with(new ListInput('#members'), function (Browser $browser) { | ->with(new ListInput('#members'), function (Browser $browser) { | ||||
$browser->removeListEntry(3)->removeListEntry(2); | $browser->removeListEntry(3)->removeListEntry(2); | ||||
}) | }) | ||||
->click('button[type=submit]') | ->click('@general button[type=submit]') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'Distribution list updated successfully.') | ->assertToast(Toast::TYPE_SUCCESS, 'Distribution list updated successfully.') | ||||
->assertMissing('.invalid-feedback') | ->assertMissing('.invalid-feedback') | ||||
->on(new DistlistList()) | ->on(new DistlistList()) | ||||
->assertElementsCount('@table tbody tr', 1); | ->assertElementsCount('@table tbody tr', 1); | ||||
$group = Group::where('email', 'group-test@kolab.org')->first(); | $group = Group::where('email', 'group-test@kolab.org')->first(); | ||||
$this->assertSame(['test1@gmail.com'], $group->members); | $this->assertSame(['test1@gmail.com'], $group->members); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | public function testStatus(): void | ||||
// Test Verify button | // Test Verify button | ||||
$browser->waitUntilMissing('@status', 10); | $browser->waitUntilMissing('@status', 10); | ||||
}); | }); | ||||
// TODO: Test all group statuses on the list | // TODO: Test all group statuses on the list | ||||
} | } | ||||
/** | |||||
* Test distribution list settings | |||||
*/ | |||||
public function testSettings(): void | |||||
{ | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$this->addDistlistEntitlement($john); | |||||
$group = $this->getTestGroup('group-test@kolab.org'); | |||||
$group->assignToWallet($john->wallets->first()); | |||||
$group->status = Group::STATUS_NEW | Group::STATUS_ACTIVE; | |||||
$group->save(); | |||||
$this->browse(function ($browser) use ($group) { | |||||
// Test auto-refresh | |||||
$browser->visit('/distlist/' . $group->id) | |||||
->on(new DistlistInfo()) | |||||
->assertSeeIn('@nav #tab-general', 'General') | |||||
->assertSeeIn('@nav #tab-settings', 'Settings') | |||||
->click('@nav #tab-settings') | |||||
->with('@settings form', function (Browser $browser) { | |||||
// Assert form content | |||||
$browser->assertSeeIn('div.row:nth-child(1) label', 'Sender Access List') | |||||
->assertVisible('div.row:nth-child(1) .list-input') | |||||
->with(new ListInput('#sender-policy'), function (Browser $browser) { | |||||
$browser->assertListInputValue([]) | |||||
->assertValue('@input', ''); | |||||
}) | |||||
->assertSeeIn('button[type=submit]', 'Submit'); | |||||
}) | |||||
// Test error handling | |||||
->with(new ListInput('#sender-policy'), function (Browser $browser) { | |||||
$browser->addListEntry('test.com'); | |||||
}) | |||||
->click('@settings button[type=submit]') | |||||
->assertToast(Toast::TYPE_SUCCESS, 'Distribution list settings updated successfully.') | |||||
->assertMissing('.invalid-feedback') | |||||
->refresh() | |||||
->on(new DistlistInfo()) | |||||
->click('@nav #tab-settings') | |||||
->with('@settings form', function (Browser $browser) { | |||||
$browser->with(new ListInput('#sender-policy'), function (Browser $browser) { | |||||
$browser->assertListInputValue(['test.com']) | |||||
->assertValue('@input', ''); | |||||
}); | |||||
}); | |||||
}); | |||||
} | |||||
/** | /** | ||||
* Register the beta + distlist entitlements for the user | * Register the beta + distlist entitlements for the user | ||||
*/ | */ | ||||
private function addDistlistEntitlement($user): void | private function addDistlistEntitlement($user): void | ||||
{ | { | ||||
// Add beta+distlist entitlements | // Add beta+distlist entitlements | ||||
$beta_sku = Sku::where('title', 'beta')->first(); | $beta_sku = Sku::where('title', 'beta')->first(); | ||||
$distlist_sku = Sku::where('title', 'distlist')->first(); | $distlist_sku = Sku::where('title', 'distlist')->first(); | ||||
$user->assignSku($beta_sku); | $user->assignSku($beta_sku); | ||||
$user->assignSku($distlist_sku); | $user->assignSku($distlist_sku); | ||||
} | } | ||||
} | } |