Files
WMS/Modules/Helpdesk/Tests/Browser/HelpdeskSettingsBrowserTest.php
T
2026-06-17 07:35:03 +01:00

97 lines
3.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Modules\Helpdesk\Tests\Browser;
use Laravel\Dusk\Browser;
use Modules\Helpdesk\Tests\Concerns\BuildsHelpdeskFixtures;
use Tests\DuskTestCase;
final class HelpdeskSettingsBrowserTest extends DuskTestCase
{
use BuildsHelpdeskFixtures;
public function test_settings_tabs_expose_lookup_git_and_workflow_setup_areas(): void
{
$this->seedLookupData();
$admin = $this->admin(['name' => 'Settings Admin']);
$this->browse(function (Browser $browser) use ($admin): void {
$browser->loginAs($admin)
->visitRoute('helpdesk.settings')
->waitFor('@helpdesk-settings-manager')
->assertSee('Support configuration')
->assertSourceHas('Statuses')
->assertSourceHas('Priorities')
->assertSourceHas('Categories')
->assertSourceHas('Teams')
->assertSourceHas('Projects')
->assertSourceHas('Git')
->assertSourceHas('Workflow')
->assertSourceHas('Canned')
->assertSourceHas('SLA')
->assertSourceHas('Rules')
->assertSourceHas('Checks')
->assertSourceHas('Tags')
->assertSourceHas('Products');
$this->openSettingsSection($browser, 'Git', 'Git repositories');
$browser->assertSee('Remote URL');
$this->openSettingsSection($browser, 'Workflow', 'Workflow messages');
$browser->assertSee('HTML email body');
$this->openSettingsSection($browser, 'Canned', 'Canned responses');
$browser->assertSee('Reply body');
$this->openSettingsSection($browser, 'SLA', 'SLA policies');
$browser->assertSee('First response minutes');
$this->openSettingsSection($browser, 'Rules', 'Email automation rules');
$browser->assertSee('Subject contains');
$this->openSettingsSection($browser, 'Checks', 'Checklist templates');
$browser->assertSee('Checklist items');
$this->openSettingsSection($browser, 'Tags', 'Ticket tags');
$browser->assertSee('Colour');
$this->openSettingsSection($browser, 'Products', 'Products and services');
$browser->assertSee('Release/build');
});
}
/**
* Click a visible Helpdesk settings section card by its rendered label.
*
* This intentionally exercises the real UI instead of mutating Livewire internals.
*/
private function openSettingsSection(Browser $browser, string $label, string $expectedText): void
{
$encodedLabel = json_encode($label, JSON_THROW_ON_ERROR);
$browser->script(<<<JS
const manager = document.querySelector('[dusk="helpdesk-settings-manager"]');
if (! manager) {
throw new Error('Helpdesk settings manager was not found.');
}
const button = Array.from(manager.querySelectorAll('button')).find((candidate) => {
const text = candidate.textContent.replace(/\s+/g, ' ').trim();
return text === {$encodedLabel} || text.startsWith({$encodedLabel} + ' ');
});
if (! button) {
throw new Error('Helpdesk settings section button was not found: ' + {$encodedLabel});
}
button.click();
JS);
$browser->waitForText($expectedText, 10);
}
}