From 5ec593e802578514c3dd75905f362eb7e1ae3364 Mon Sep 17 00:00:00 2001 From: Mark Gregory Date: Wed, 17 Jun 2026 07:35:03 +0100 Subject: [PATCH] more tests fixes --- .env.dusk.local | 2 +- .../Browser/HelpdeskSettingsBrowserTest.php | 70 ++++++++++--------- .../Browser/HelpdeskTicketBrowserTest.php | 28 +++++--- composer.json | 1 + tests/DuskTestCase.php | 7 +- 5 files changed, 62 insertions(+), 46 deletions(-) diff --git a/.env.dusk.local b/.env.dusk.local index 46b1e522..7609e712 100644 --- a/.env.dusk.local +++ b/.env.dusk.local @@ -1,4 +1,4 @@ -APP_URL=http://127.0.0.1:8000 +APP_URL=https://wms.vm SESSION_DRIVER=file CACHE_STORE=array diff --git a/Modules/Helpdesk/Tests/Browser/HelpdeskSettingsBrowserTest.php b/Modules/Helpdesk/Tests/Browser/HelpdeskSettingsBrowserTest.php index 587a0b2a..ef0e89c0 100644 --- a/Modules/Helpdesk/Tests/Browser/HelpdeskSettingsBrowserTest.php +++ b/Modules/Helpdesk/Tests/Browser/HelpdeskSettingsBrowserTest.php @@ -36,57 +36,61 @@ final class HelpdeskSettingsBrowserTest extends DuskTestCase ->assertSourceHas('Tags') ->assertSourceHas('Products'); - $this->setHelpdeskSettingsSection($browser, 'git'); - $browser->waitForText('Git repositories', 10) - ->assertSee('Remote URL'); + $this->openSettingsSection($browser, 'Git', 'Git repositories'); + $browser->assertSee('Remote URL'); - $this->setHelpdeskSettingsSection($browser, 'workflow'); - $browser->waitForText('Workflow messages', 10) - ->assertSee('HTML email body'); + $this->openSettingsSection($browser, 'Workflow', 'Workflow messages'); + $browser->assertSee('HTML email body'); - $this->setHelpdeskSettingsSection($browser, 'canned'); - $browser->waitForText('Canned responses', 10) - ->assertSee('Reply body'); + $this->openSettingsSection($browser, 'Canned', 'Canned responses'); + $browser->assertSee('Reply body'); - $this->setHelpdeskSettingsSection($browser, 'sla'); - $browser->waitForText('SLA policies', 10) - ->assertSee('First response minutes'); + $this->openSettingsSection($browser, 'SLA', 'SLA policies'); + $browser->assertSee('First response minutes'); - $this->setHelpdeskSettingsSection($browser, 'automation'); - $browser->waitForText('Email automation rules', 10) - ->assertSee('Subject contains'); + $this->openSettingsSection($browser, 'Rules', 'Email automation rules'); + $browser->assertSee('Subject contains'); - $this->setHelpdeskSettingsSection($browser, 'checklists'); - $browser->waitForText('Checklist templates', 10) - ->assertSee('Checklist items'); + $this->openSettingsSection($browser, 'Checks', 'Checklist templates'); + $browser->assertSee('Checklist items'); - $this->setHelpdeskSettingsSection($browser, 'tags'); - $browser->waitForText('Ticket tags', 10) - ->assertSee('Colour'); + $this->openSettingsSection($browser, 'Tags', 'Ticket tags'); + $browser->assertSee('Colour'); - $this->setHelpdeskSettingsSection($browser, 'products'); - $browser->waitForText('Products and services', 10) - ->assertSee('Release/build'); + $this->openSettingsSection($browser, 'Products', 'Products and services'); + $browser->assertSee('Release/build'); }); } - private function setHelpdeskSettingsSection(Browser $browser, string $section): void + /** + * 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 { - $encodedSection = json_encode($section, JSON_THROW_ON_ERROR); + $encodedLabel = json_encode($label, JSON_THROW_ON_ERROR); $browser->script(<< { + 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}); } -window.Livewire.find(component.getAttribute('wire:id')).set('section', {$encodedSection}); +button.click(); JS); + + $browser->waitForText($expectedText, 10); } } diff --git a/Modules/Helpdesk/Tests/Browser/HelpdeskTicketBrowserTest.php b/Modules/Helpdesk/Tests/Browser/HelpdeskTicketBrowserTest.php index 7c67717f..959d4b86 100644 --- a/Modules/Helpdesk/Tests/Browser/HelpdeskTicketBrowserTest.php +++ b/Modules/Helpdesk/Tests/Browser/HelpdeskTicketBrowserTest.php @@ -68,6 +68,9 @@ final class HelpdeskTicketBrowserTest extends DuskTestCase }); } + /** + * Set a property on the Livewire create-ticket component from the real form root. + */ private function setTicketCreateProperty(Browser $browser, string $property, mixed $value): void { $encodedProperty = json_encode($property, JSON_THROW_ON_ERROR); @@ -76,19 +79,23 @@ final class HelpdeskTicketBrowserTest extends DuskTestCase $browser->script(<<script(<<addArguments([ + $options = (new ChromeOptions())->addArguments([ '--disable-gpu', '--headless=new', '--window-size=1920,1080', '--no-sandbox', '--disable-dev-shm-usage', '--disable-search-engine-choice-screen', + '--ignore-certificate-errors', + '--allow-insecure-localhost', ]); return RemoteWebDriver::create( @@ -80,7 +82,8 @@ abstract class DuskTestCase extends BaseTestCase )); usort($candidates, static function (string $left, string $right): int { - $score = static fn (string $path): int => str_contains($path, 'mac-arm64') ? 0 + $score = static fn (string $path): int => + str_contains($path, 'mac-arm64') ? 0 : (str_contains($path, 'mac-arm') ? 1 : (str_contains($path, 'mac') ? 2 : 3));