create issues with attachmens
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Helpdesk\Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
final class TicketCreateAttachmentBrowserSafetyTest extends TestCase
|
||||
{
|
||||
public function test_ticket_create_view_does_not_reinject_application_assets_inside_livewire_component(): void
|
||||
{
|
||||
$view = file_get_contents(dirname(__DIR__, 2) . '/Resources/views/livewire/ticket-create.blade.php');
|
||||
|
||||
self::assertIsString($view);
|
||||
self::assertStringNotContainsString("@vite(['resources/css/app.css', 'resources/js/app.js'])", $view);
|
||||
self::assertStringContainsString('wire:submit.prevent="save"', $view);
|
||||
}
|
||||
|
||||
public function test_ticket_create_attachment_input_is_owned_by_livewire_and_has_a_stable_key(): void
|
||||
{
|
||||
$view = file_get_contents(dirname(__DIR__, 2) . '/Resources/views/livewire/ticket-create.blade.php');
|
||||
|
||||
self::assertIsString($view);
|
||||
self::assertStringContainsString('wire:key="ticket-create-attachments-uploader"', $view);
|
||||
self::assertStringContainsString('wire:key="ticket-create-attachments-input"', $view);
|
||||
self::assertStringContainsString('type="file" wire:model="attachments" multiple', $view);
|
||||
self::assertStringNotContainsString('$wire.uploadMultiple', $view);
|
||||
self::assertStringNotContainsString("new CustomEvent('livewire-upload-start'", $view);
|
||||
self::assertStringNotContainsString("new CustomEvent('livewire-upload-finish'", $view);
|
||||
}
|
||||
|
||||
public function test_ticket_create_attachment_script_registers_global_listeners_once(): void
|
||||
{
|
||||
$view = file_get_contents(dirname(__DIR__, 2) . '/Resources/views/livewire/ticket-create.blade.php');
|
||||
|
||||
self::assertIsString($view);
|
||||
self::assertStringContainsString('window.__helpdeskTicketCreateAttachmentListenersRegistered', $view);
|
||||
self::assertStringContainsString('window.__helpdeskTicketCreateLivewireClearListenerRegistered', $view);
|
||||
self::assertStringContainsString("window.dispatchEvent(new CustomEvent('helpdesk-attachments-reset'))", $view);
|
||||
}
|
||||
|
||||
public function test_create_attachment_browser_test_does_not_use_livewire_internal_dom_selectors(): void
|
||||
{
|
||||
$test = file_get_contents(dirname(__DIR__, 1) . '/Browser/HelpdeskCreateTicketAttachmentBrowserTest.php');
|
||||
|
||||
self::assertIsString($test);
|
||||
self::assertStringNotContainsString('closest(', $test);
|
||||
self::assertStringNotContainsString('Livewire.find', $test);
|
||||
self::assertStringContainsString("attach('#attachments'", $test);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Helpdesk\Tests\Feature;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Modules\Helpdesk\Livewire\TicketCreate;
|
||||
use Modules\Helpdesk\Models\Attachment;
|
||||
use Modules\Helpdesk\Models\Ticket;
|
||||
use Modules\Helpdesk\Tests\Concerns\BuildsHelpdeskFixtures;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class TicketCreateAttachmentPipelineTest extends TestCase
|
||||
{
|
||||
use BuildsHelpdeskFixtures;
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_ticket_create_persists_a_single_attachment_through_livewire(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
config()->set('helpdesk.disk', 'local');
|
||||
|
||||
$fixtures = $this->seedLookupData();
|
||||
$user = $this->user(['name' => 'Attachment Create User']);
|
||||
$file = UploadedFile::fake()->create('warehouse-error.log', 12, 'text/plain');
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(TicketCreate::class)
|
||||
->set('subject', 'Create ticket with one attachment')
|
||||
->set('body', '<p>This ticket must persist a Livewire upload attachment.</p>')
|
||||
->set('board_id', $fixtures['board']->id)
|
||||
->set('priority_id', $fixtures['high']->id)
|
||||
->set('category_id', $fixtures['category']->id)
|
||||
->set('team_id', $fixtures['team']->id)
|
||||
->set('project_id', $fixtures['project']->id)
|
||||
->set('attachments', [$file])
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('helpdesk.tickets.index'));
|
||||
|
||||
$ticket = Ticket::query()
|
||||
->where('subject', 'Create ticket with one attachment')
|
||||
->firstOrFail();
|
||||
|
||||
$attachment = Attachment::query()
|
||||
->where('ticket_id', $ticket->id)
|
||||
->whereNull('comment_id')
|
||||
->firstOrFail();
|
||||
|
||||
self::assertSame($user->id, (int) $attachment->user_id);
|
||||
self::assertSame('local', $attachment->disk);
|
||||
self::assertSame('warehouse-error.log', $attachment->original_name);
|
||||
self::assertSame('log', $attachment->extension());
|
||||
Storage::disk('local')->assertExists($attachment->path);
|
||||
}
|
||||
|
||||
public function test_ticket_create_persists_multiple_attachments_through_livewire(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
config()->set('helpdesk.disk', 'local');
|
||||
|
||||
$fixtures = $this->seedLookupData();
|
||||
$user = $this->user(['name' => 'Multiple Attachment User']);
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(TicketCreate::class)
|
||||
->set('subject', 'Create ticket with multiple attachments')
|
||||
->set('body', '<p>This ticket must persist every selected Livewire upload.</p>')
|
||||
->set('board_id', $fixtures['board']->id)
|
||||
->set('priority_id', $fixtures['normal']->id)
|
||||
->set('category_id', $fixtures['category']->id)
|
||||
->set('team_id', $fixtures['team']->id)
|
||||
->set('project_id', $fixtures['project']->id)
|
||||
->set('attachments', [
|
||||
UploadedFile::fake()->create('first-proof.pdf', 20, 'application/pdf'),
|
||||
UploadedFile::fake()->create('second-proof.txt', 8, 'text/plain'),
|
||||
UploadedFile::fake()->create('third-proof.csv', 6, 'text/csv'),
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('helpdesk.tickets.index'));
|
||||
|
||||
$ticket = Ticket::query()
|
||||
->where('subject', 'Create ticket with multiple attachments')
|
||||
->firstOrFail();
|
||||
|
||||
self::assertSame(3, Attachment::query()->where('ticket_id', $ticket->id)->whereNull('comment_id')->count());
|
||||
|
||||
foreach (['first-proof.pdf', 'second-proof.txt', 'third-proof.csv'] as $name) {
|
||||
$attachment = Attachment::query()
|
||||
->where('ticket_id', $ticket->id)
|
||||
->where('original_name', $name)
|
||||
->firstOrFail();
|
||||
|
||||
Storage::disk('local')->assertExists($attachment->path);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_ticket_create_accepts_source_code_attachments_through_livewire(): void
|
||||
{
|
||||
Storage::fake('local');
|
||||
config()->set('helpdesk.disk', 'local');
|
||||
|
||||
$fixtures = $this->seedLookupData();
|
||||
$user = $this->user(['name' => 'Source Attachment User']);
|
||||
|
||||
Livewire::actingAs($user)
|
||||
->test(TicketCreate::class)
|
||||
->set('subject', 'Create ticket with source attachments')
|
||||
->set('body', '<p>This ticket must accept source files by extension.</p>')
|
||||
->set('board_id', $fixtures['board']->id)
|
||||
->set('priority_id', $fixtures['normal']->id)
|
||||
->set('category_id', $fixtures['category']->id)
|
||||
->set('team_id', $fixtures['team']->id)
|
||||
->set('project_id', $fixtures['project']->id)
|
||||
->set('attachments', [
|
||||
UploadedFile::fake()->create('TicketCreate.php', 10, 'text/plain'),
|
||||
UploadedFile::fake()->create('upload-widget.js', 10, 'text/plain'),
|
||||
UploadedFile::fake()->create('warehouse-sync.rpgle', 10, 'text/plain'),
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('helpdesk.tickets.index'));
|
||||
|
||||
$ticket = Ticket::query()
|
||||
->where('subject', 'Create ticket with source attachments')
|
||||
->firstOrFail();
|
||||
|
||||
foreach (['TicketCreate.php', 'upload-widget.js', 'warehouse-sync.rpgle'] as $name) {
|
||||
$attachment = Attachment::query()
|
||||
->where('ticket_id', $ticket->id)
|
||||
->where('original_name', $name)
|
||||
->firstOrFail();
|
||||
|
||||
self::assertTrue($attachment->isSourceCode(), $name . ' should be categorised as source code.');
|
||||
Storage::disk('local')->assertExists($attachment->path);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user