more tests fixes for duck tests
This commit is contained in:
@@ -14,83 +14,36 @@ final class HelpdeskSettingsBrowserTest extends DuskTestCase
|
||||
|
||||
public function test_settings_tabs_expose_lookup_git_and_workflow_setup_areas(): void
|
||||
{
|
||||
$this->seedLookupData();
|
||||
$admin = $this->admin(['name' => 'Settings Admin']);
|
||||
$fixtures = $this->seedHelpdeskFixtures();
|
||||
$admin = $fixtures['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');
|
||||
->assertSee('Statuses')
|
||||
->press('Priorities')
|
||||
->waitForText('Priorities', 10)
|
||||
->press('Categories')
|
||||
->waitForText('Categories', 10)
|
||||
->press('Teams')
|
||||
->waitForText('Teams', 10)
|
||||
->press('Projects')
|
||||
->waitForText('Projects', 10)
|
||||
->press('Git')
|
||||
->waitForText('Git repositories', 10)
|
||||
->assertSee('Remote URL')
|
||||
->press('Workflow')
|
||||
->waitForText('Workflow messages', 10)
|
||||
->assertSee('HTML email body');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
private function openSettingsSection(Browser $browser, string $section, string $expectedHeading): Browser
|
||||
{
|
||||
$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);
|
||||
return $browser
|
||||
->click('@helpdesk-settings-section-'.$section)
|
||||
->waitForText($expectedHeading, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,18 +20,19 @@ final class HelpdeskTicketBrowserTest extends DuskTestCase
|
||||
$this->browse(function (Browser $browser) use ($user, $fixtures): void {
|
||||
$browser->loginAs($user)
|
||||
->visitRoute('helpdesk.tickets.create')
|
||||
->waitFor('.helpdesk-ticket-form')
|
||||
->waitFor('@helpdesk-ticket-create')
|
||||
->assertSee('Create ticket')
|
||||
->type('input[data-dusk="ticket-subject"]', 'Browser created helpdesk ticket');
|
||||
->type('@ticket-subject', 'Browser created helpdesk ticket');
|
||||
|
||||
$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);
|
||||
$this->setHelpdeskEditor($browser, 'ticket-body-editor', '<p>This browser ticket proves the form saves correctly.</p>');
|
||||
$this->setHelpdeskSelect($browser, 'board_id', $fixtures['board']->id);
|
||||
$this->setHelpdeskSelect($browser, 'priority_id', $fixtures['high']->id);
|
||||
$this->setHelpdeskSelect($browser, 'category_id', $fixtures['category']->id);
|
||||
$this->setHelpdeskSelect($browser, 'team_id', $fixtures['team']->id);
|
||||
$this->setHelpdeskSelect($browser, 'project_id', $fixtures['project']->id);
|
||||
|
||||
$browser->click('button[data-dusk="ticket-create-submit"]')
|
||||
$browser->pause(500)
|
||||
->press('@ticket-create-submit')
|
||||
->waitFor('@helpdesk-ticket-index', 10)
|
||||
->assertSee('Browser created helpdesk ticket')
|
||||
->assertSee('High')
|
||||
@@ -59,62 +60,77 @@ final class HelpdeskTicketBrowserTest extends DuskTestCase
|
||||
->visitRoute('helpdesk.tickets.show', $ticket)
|
||||
->waitFor('@helpdesk-ticket-show')
|
||||
->assertSee('Browser response ticket');
|
||||
$browser->script(<<<'JS'
|
||||
|
||||
$this->setTicketShowProperty($browser, 'commentBody', '<p>First browser response</p>');
|
||||
const editor = document.querySelector('[data-dusk="ticket-comment-editor"] [contenteditable="true"], [dusk="ticket-comment-editor"] [contenteditable="true"]');
|
||||
|
||||
$browser->press('@post-comment')
|
||||
if (! editor) {
|
||||
|
||||
throw new Error('Ticket comment editor was not found.');
|
||||
|
||||
}
|
||||
|
||||
editor.innerHTML = 'First browser response';
|
||||
|
||||
editor.dispatchEvent(new InputEvent('input', {
|
||||
|
||||
bubbles: true,
|
||||
|
||||
inputType: 'insertText',
|
||||
|
||||
data: 'First browser response',
|
||||
|
||||
}));
|
||||
|
||||
JS);
|
||||
|
||||
$this->setHelpdeskEditor($browser, 'ticket-comment-editor', '<p>First browser response</p>');
|
||||
|
||||
$browser->pause(500)
|
||||
->press('@post-comment')
|
||||
->waitForText('First browser response', 10)
|
||||
->assertSee('First browser response');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property on the Livewire create-ticket component from the real form root.
|
||||
*/
|
||||
private function setTicketCreateProperty(Browser $browser, string $property, mixed $value): void
|
||||
private function setHelpdeskEditor(Browser $browser, string $dusk, string $html): void
|
||||
{
|
||||
$encodedProperty = json_encode($property, JSON_THROW_ON_ERROR);
|
||||
$encodedValue = json_encode($value, JSON_THROW_ON_ERROR);
|
||||
$encodedDusk = json_encode($dusk, JSON_THROW_ON_ERROR);
|
||||
$encodedHtml = json_encode($html, JSON_THROW_ON_ERROR);
|
||||
|
||||
$browser->script(<<<JS
|
||||
const form = document.querySelector('.helpdesk-ticket-form');
|
||||
|
||||
if (! form) {
|
||||
throw new Error('Helpdesk ticket create form was not found.');
|
||||
const key = {$encodedDusk};
|
||||
const editorRoot = document.querySelector('[dusk="' + key + '"]') || document.querySelector('[data-dusk="' + key + '"]');
|
||||
if (! editorRoot) {
|
||||
throw new Error('Helpdesk editor '+key+' was not found.');
|
||||
}
|
||||
|
||||
const componentRoot = form.closest('[wire\\:id]');
|
||||
|
||||
if (! componentRoot || ! window.Livewire) {
|
||||
throw new Error('Helpdesk ticket create Livewire component was not found.');
|
||||
const editor = editorRoot.querySelector('[contenteditable="true"]');
|
||||
if (! editor) {
|
||||
throw new Error('Helpdesk editor content area '+key+' was not found.');
|
||||
}
|
||||
|
||||
window.Livewire.find(componentRoot.getAttribute('wire:id')).set({$encodedProperty}, {$encodedValue});
|
||||
editor.innerHTML = {$encodedHtml};
|
||||
editor.dispatchEvent(new InputEvent('input', { bubbles: true, inputType: 'insertText', data: ' ' }));
|
||||
editor.dispatchEvent(new Event('blur', { bubbles: true }));
|
||||
JS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property on the Livewire ticket-show component from the real show-page root.
|
||||
*/
|
||||
private function setTicketShowProperty(Browser $browser, string $property, mixed $value): void
|
||||
private function setHelpdeskSelect(Browser $browser, string $model, int|string|null $value): void
|
||||
{
|
||||
$encodedProperty = json_encode($property, JSON_THROW_ON_ERROR);
|
||||
$encodedValue = json_encode($value, JSON_THROW_ON_ERROR);
|
||||
$encodedModel = json_encode($model, JSON_THROW_ON_ERROR);
|
||||
$encodedValue = json_encode($value === null ? '' : (string) $value, JSON_THROW_ON_ERROR);
|
||||
|
||||
$browser->script(<<<JS
|
||||
const show = document.querySelector('[dusk="helpdesk-ticket-show"]');
|
||||
|
||||
if (! show) {
|
||||
throw new Error('Helpdesk ticket show root was not found.');
|
||||
const model = {$encodedModel};
|
||||
const value = {$encodedValue};
|
||||
const select = document.querySelector('[data-wire-model="' + model + '"]');
|
||||
if (! select) {
|
||||
throw new Error('Helpdesk select '+model+' was not found.');
|
||||
}
|
||||
|
||||
const componentRoot = show.closest('[wire\\:id]');
|
||||
|
||||
if (! componentRoot || ! window.Livewire) {
|
||||
throw new Error('Helpdesk ticket show Livewire component was not found.');
|
||||
select.value = value;
|
||||
select.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
if (window.jQuery) {
|
||||
window.jQuery(select).val(value).trigger('change.select2').trigger('change.helpdesk-select2').trigger('change');
|
||||
}
|
||||
|
||||
window.Livewire.find(componentRoot.getAttribute('wire:id')).set({$encodedProperty}, {$encodedValue});
|
||||
JS);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user