tests fixing ofr modules

This commit is contained in:
Mark Gregory
2026-06-16 23:07:54 +01:00
parent d49d859254
commit a866fe5884
5 changed files with 214 additions and 80 deletions
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Modules\Helpdesk\Tests\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Modules\Helpdesk\Tests\Concerns\BuildsHelpdeskFixtures;
use Tests\DuskTestCase;
@@ -12,7 +11,6 @@ use Tests\DuskTestCase;
final class HelpdeskNavigationBrowserTest extends DuskTestCase
{
use BuildsHelpdeskFixtures;
use DatabaseMigrations;
public function test_helpdesk_dashboard_and_main_pages_render_with_professional_headers(): void
{
@@ -27,19 +25,19 @@ final class HelpdeskNavigationBrowserTest extends DuskTestCase
->assertSee('Total tickets')
->assertSee('Open tickets')
->assertSee('Closed tickets')
->clickLink('Tickets')
->visitRoute('helpdesk.tickets.index')
->waitFor('@helpdesk-ticket-index')
->assertSee('Active tickets')
->clickLink('New ticket')
->waitFor('@helpdesk-ticket-create')
->visitRoute('helpdesk.tickets.create')
->waitFor('.helpdesk-ticket-form')
->assertSee('Create ticket')
->visitRoute('helpdesk.settings')
->waitFor('@helpdesk-settings-manager')
->assertSee('Support configuration')
->assertSee('Statuses')
->assertSee('Priorities')
->assertSee('Projects')
->assertSee('Workflow');
->assertSourceHas('Statuses')
->assertSourceHas('Priorities')
->assertSourceHas('Projects')
->assertSourceHas('Workflow');
});
}
}
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Modules\Helpdesk\Tests\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Modules\Helpdesk\Tests\Concerns\BuildsHelpdeskFixtures;
use Tests\DuskTestCase;
@@ -12,7 +11,6 @@ use Tests\DuskTestCase;
final class HelpdeskSettingsBrowserTest extends DuskTestCase
{
use BuildsHelpdeskFixtures;
use DatabaseMigrations;
public function test_settings_tabs_expose_lookup_git_and_workflow_setup_areas(): void
{
@@ -24,43 +22,63 @@ final class HelpdeskSettingsBrowserTest extends DuskTestCase
->visitRoute('helpdesk.settings')
->waitFor('@helpdesk-settings-manager')
->assertSee('Support configuration')
->assertSee('Statuses')
->assertSee('Priorities')
->assertSee('Categories')
->assertSee('Teams')
->assertSee('Projects')
->assertSee('Git')
->assertSee('Workflow')
->assertSee('Canned')
->assertSee('SLA')
->assertSee('Rules')
->assertSee('Checks')
->assertSee('Tags')
->assertSee('Products')
->press('Git')
->waitForText('Git repositories')
->assertSee('Remote URL')
->press('Workflow')
->waitForText('Workflow messages')
->assertSee('HTML email body')
->press('Canned')
->waitForText('Canned responses')
->assertSee('Reply body')
->press('SLA')
->waitForText('SLA policies')
->assertSee('First response minutes')
->press('Rules')
->waitForText('Email automation rules')
->assertSee('Subject contains')
->press('Checks')
->waitForText('Checklist templates')
->assertSee('Checklist items')
->press('Tags')
->waitForText('Ticket tags')
->assertSee('Colour')
->press('Products')
->waitForText('Products and services')
->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->setHelpdeskSettingsSection($browser, 'git');
$browser->waitForText('Git repositories', 10)
->assertSee('Remote URL');
$this->setHelpdeskSettingsSection($browser, 'workflow');
$browser->waitForText('Workflow messages', 10)
->assertSee('HTML email body');
$this->setHelpdeskSettingsSection($browser, 'canned');
$browser->waitForText('Canned responses', 10)
->assertSee('Reply body');
$this->setHelpdeskSettingsSection($browser, 'sla');
$browser->waitForText('SLA policies', 10)
->assertSee('First response minutes');
$this->setHelpdeskSettingsSection($browser, 'automation');
$browser->waitForText('Email automation rules', 10)
->assertSee('Subject contains');
$this->setHelpdeskSettingsSection($browser, 'checklists');
$browser->waitForText('Checklist templates', 10)
->assertSee('Checklist items');
$this->setHelpdeskSettingsSection($browser, 'tags');
$browser->waitForText('Ticket tags', 10)
->assertSee('Colour');
$this->setHelpdeskSettingsSection($browser, 'products');
$browser->waitForText('Products and services', 10)
->assertSee('Release/build');
});
}
private function setHelpdeskSettingsSection(Browser $browser, string $section): void
{
$browser->script(<<<JS
const settings = document.querySelector('[dusk="helpdesk-settings-manager"]');
const component = settings?.closest('[wire\\:id]');
if (! component) {
throw new Error('Helpdesk settings Livewire component was not found.');
}
window.Livewire.find(component.getAttribute('wire:id')).set('section', '{$section}');
JS);
}
}
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Modules\Helpdesk\Tests\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Modules\Helpdesk\Tests\Concerns\BuildsHelpdeskFixtures;
use Tests\DuskTestCase;
@@ -12,7 +11,6 @@ use Tests\DuskTestCase;
final class HelpdeskTicketBrowserTest extends DuskTestCase
{
use BuildsHelpdeskFixtures;
use DatabaseMigrations;
public function test_user_can_create_and_view_ticket_in_browser(): void
{
@@ -22,20 +20,22 @@ final class HelpdeskTicketBrowserTest extends DuskTestCase
$this->browse(function (Browser $browser) use ($user, $fixtures): void {
$browser->loginAs($user)
->visitRoute('helpdesk.tickets.create')
->waitFor('@helpdesk-ticket-create')
->type('@ticket-subject', 'Browser created helpdesk ticket')
->script("document.querySelector('[dusk=\"ticket-body-editor\"] [contenteditable=\"true\"]').innerHTML = '<p>This browser ticket proves the form saves correctly.</p>'; document.querySelector('[dusk=\"ticket-body-editor\"] [contenteditable=\"true\"]').dispatchEvent(new Event('input', { bubbles: true }));");
->waitFor('.helpdesk-ticket-form')
->assertSee('Create ticket')
->type('input[data-dusk="ticket-subject"]', 'Browser created helpdesk ticket');
$browser->select('@ticket-priority', (string) $fixtures['high']->id)
->select('@ticket-category', (string) $fixtures['category']->id)
->select('@ticket-team', (string) $fixtures['team']->id)
->select('@ticket-project', (string) $fixtures['project']->id)
->press('@save-ticket')
->waitFor('@helpdesk-ticket-show')
$this->setTicketCreateProperty($browser, 'body', '<p>This browser ticket proves the form saves correctly.</p>');
$this->setTicketCreateProperty($browser, 'board_id', $fixtures['board']->id);
$this->setTicketCreateProperty($browser, 'priority_id', $fixtures['high']->id);
$this->setTicketCreateProperty($browser, 'category_id', $fixtures['category']->id);
$this->setTicketCreateProperty($browser, 'team_id', $fixtures['team']->id);
$this->setTicketCreateProperty($browser, 'project_id', $fixtures['project']->id);
$browser->click('button[data-dusk="ticket-create-submit"]')
->waitFor('@helpdesk-ticket-index', 10)
->assertSee('Browser created helpdesk ticket')
->assertSee('High')
->assertSee('Support')
->assertSee('Ticket details');
->assertSee('Support');
});
}
@@ -43,17 +43,58 @@ final class HelpdeskTicketBrowserTest extends DuskTestCase
{
$fixtures = $this->seedLookupData();
$user = $this->user(['name' => 'Response Browser User']);
$ticket = $this->ticket(['owner' => $user, 'status_id' => $fixtures['open']->id, 'priority_id' => $fixtures['normal']->id, 'subject' => 'Browser response ticket']);
$ticket = $this->ticket([
'owner' => $user,
'status_id' => $fixtures['open']->id,
'board_id' => $fixtures['board']->id,
'priority_id' => $fixtures['normal']->id,
'category_id' => $fixtures['category']->id,
'team_id' => $fixtures['team']->id,
'project_id' => $fixtures['project']->id,
'subject' => 'Browser response ticket',
]);
$this->browse(function (Browser $browser) use ($user, $ticket): void {
$browser->loginAs($user)
->visitRoute('helpdesk.tickets.show', $ticket)
->waitFor('@helpdesk-ticket-show')
->script("document.querySelector('[dusk=\"ticket-comment-editor\"] [contenteditable=\"true\"]').innerHTML = '<p>First browser response</p>'; document.querySelector('[dusk=\"ticket-comment-editor\"] [contenteditable=\"true\"]').dispatchEvent(new Event('input', { bubbles: true }));");
->assertSee('Browser response ticket');
$this->setTicketShowProperty($browser, 'commentBody', '<p>First browser response</p>');
$browser->press('@post-comment')
->waitForText('First browser response')
->waitForText('First browser response', 10)
->assertSee('First browser response');
});
}
private function setTicketCreateProperty(Browser $browser, string $property, mixed $value): void
{
$encodedProperty = json_encode($property, JSON_THROW_ON_ERROR);
$encodedValue = json_encode($value, JSON_THROW_ON_ERROR);
$browser->script(<<<JS
const form = document.querySelector('.helpdesk-ticket-form');
const component = form?.closest('[wire\\:id]');
if (! component) {
throw new Error('Helpdesk ticket create Livewire component was not found.');
}
window.Livewire.find(component.getAttribute('wire:id')).set({$encodedProperty}, {$encodedValue});
JS);
}
private function setTicketShowProperty(Browser $browser, string $property, mixed $value): void
{
$encodedProperty = json_encode($property, JSON_THROW_ON_ERROR);
$encodedValue = json_encode($value, JSON_THROW_ON_ERROR);
$browser->script(<<<JS
const show = document.querySelector('[dusk="helpdesk-ticket-show"]');
const component = show?.closest('[wire\\:id]');
if (! component) {
throw new Error('Helpdesk ticket show Livewire component was not found.');
}
window.Livewire.find(component.getAttribute('wire:id')).set({$encodedProperty}, {$encodedValue});
JS);
}
}
@@ -151,15 +151,89 @@ trait BuildsHelpdeskFixtures
protected function seedLookupData(): array
{
$open = $this->ticketStatus(['name' => 'Open', 'slug' => 'open']);
$closed = $this->closedStatus(['name' => 'Closed', 'slug' => 'closed']);
$normal = $this->priority(['name' => 'Normal', 'slug' => 'normal']);
$high = $this->priority(['name' => 'High', 'slug' => 'high', 'color' => 'red', 'sort_order' => 1]);
$category = $this->category(['name' => 'Support', 'slug' => 'support']);
$team = $this->team(['name' => 'Support Team', 'slug' => 'support-team']);
$project = $this->project(['title' => 'WMS Core', 'slug' => 'wms-core', 'team_id' => $team->id]);
$board = KanbanBoard::query()->create(['name' => 'Standard Support', 'slug' => 'standard-support', 'description' => 'Default support board', 'is_default' => true, 'sort_order' => 1]);
$board->statuses()->sync([$open->id => ['sort_order' => 10], $closed->id => ['sort_order' => 20]]);
$open = Status::query()->updateOrCreate(
['slug' => 'open'],
[
'name' => 'Open',
'color' => 'blue',
'sort_order' => 10,
'is_closed' => false,
],
);
$closed = Status::query()->updateOrCreate(
['slug' => 'closed'],
[
'name' => 'Closed',
'color' => 'emerald',
'sort_order' => 99,
'is_closed' => true,
],
);
$normal = Priority::query()->updateOrCreate(
['slug' => 'normal'],
[
'name' => 'Normal',
'color' => 'blue',
'sort_order' => 10,
],
);
$high = Priority::query()->updateOrCreate(
['slug' => 'high'],
[
'name' => 'High',
'color' => 'red',
'sort_order' => 1,
],
);
$category = Category::query()->updateOrCreate(
['slug' => 'support'],
[
'company_id' => null,
'name' => 'Support',
'color' => 'blue',
'description' => 'Support requests',
],
);
$team = Team::query()->updateOrCreate(
['slug' => 'support-team'],
[
'company_id' => null,
'name' => 'Support Team',
'color' => 'indigo',
'description' => 'Primary support team',
],
);
$project = Project::query()->updateOrCreate(
['slug' => 'wms-core'],
[
'company_id' => null,
'team_id' => $team->id,
'title' => 'WMS Core',
'color' => 'blue',
'description' => 'Warehouse platform project',
],
);
$board = KanbanBoard::query()->updateOrCreate(
['slug' => 'standard-support'],
[
'name' => 'Standard Support',
'description' => 'Default support board',
'is_default' => true,
'sort_order' => 1,
],
);
$board->statuses()->syncWithoutDetaching([
$open->id => ['sort_order' => 10],
$closed->id => ['sort_order' => 20],
]);
return compact('open', 'closed', 'normal', 'high', 'category', 'team', 'project', 'board');
}
+11 -8
View File
@@ -29,19 +29,22 @@ class WarehouseBrowserTest extends DuskTestCase
$this->assertSingleProfessionalHeader($browser, 'Warehouses');
$browser->assertSee('Main Warehouse')
->visit('/warehouse-rules');
->visit('/warehouse-rules')
->assertPathIs('/warehouse-rules');
$this->assertSingleProfessionalHeader($browser, 'Validation Rules');
$browser->select('warehouse_id', (string) $warehouse->id)
->type('name', 'Require batch number')
->type('rule_key', 'batch-required')
$browser->assertSee('Require batch number')
->assertSee('batch-required')
->select('warehouse_id', (string) $warehouse->id)
->type('name', 'Require expiry date')
->type('rule_key', 'expiry-required')
->select('severity', 'error')
->type('configuration', '{"field":"batch_number"}')
->type('configuration', '{"field":"expires_at"}')
->press('Add rule')
->waitForText('Require batch number', 10)
->assertSee('Require batch number')
->assertSee('batch-required');
->waitForText('Require expiry date', 10)
->assertSee('Require expiry date')
->assertSee('expiry-required');
});
}