Add images to tasks
Everyone who may comment on a task sends images to it, e.g. photos taken with a phone. The server stores an upright, at most 2560 px JPEG without EXIF data (no location) and a 400 px thumbnail on the private disk, served only to those who see the job. Uploaders change captions (also the alt text) and remove their own images; admin and management may remove anyone's (jobs.remove-any-task-image). Removing a task also removes its image files. Livewire's temporary upload limit is raised to PHP's 40 MB so that the page's own 12 MB limit gives a translated message. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -7,12 +7,15 @@ use App\Modules\Catalog\Application\UseCases\AddWorkflowTemplate;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
||||
use App\Modules\Jobs\Application\Contracts\TaskImageFiles;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\ChecklistItemModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskCommentModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskImageModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
@@ -164,6 +167,9 @@ it('has no accessibility issues on a job with tasks and on the task form', funct
|
||||
ChecklistItemModel::query()->create(['task_id' => $task->id, 'text' => 'Mikit', 'sort_order' => 2]);
|
||||
TaskCommentModel::query()->create(['task_id' => $task->id, 'user_id' => $this->user->id, 'body' => 'Valot ok.
|
||||
Mikit puuttuu.', 'edited_at' => now()]);
|
||||
Storage::fake('local');
|
||||
$stored = app(TaskImageFiles::class)->store(browserTestImage(), $task->id);
|
||||
TaskImageModel::query()->create(['task_id' => $task->id, 'user_id' => $this->user->id, 'path' => $stored->path, 'thumbnail_path' => $stored->thumbnailPath, 'original_name' => 'valot.png', 'caption' => 'Valot paikallaan', 'width' => $stored->width, 'height' => $stored->height]);
|
||||
|
||||
$url = match ($page) {
|
||||
'job page' => route('jobs.show', $this->job->id),
|
||||
@@ -315,6 +321,56 @@ it('adds, edits and removes a task comment with the keyboard', function () {
|
||||
expect(TaskCommentModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
/**
|
||||
* A small PNG file for sending as a task image.
|
||||
*/
|
||||
function browserTestImage(): string
|
||||
{
|
||||
$image = imagecreatetruecolor(120, 80);
|
||||
imagefill($image, 0, 0, (int) imagecolorallocate($image, 30, 120, 200));
|
||||
$path = tempnam(sys_get_temp_dir(), 'img').'.png';
|
||||
imagepng($image, $path);
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
it('recaptions and removes a task image with the keyboard', function () {
|
||||
Storage::fake('local');
|
||||
$this->job->update(['status' => 'order']);
|
||||
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();
|
||||
$task = TaskModel::factory()
|
||||
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä']);
|
||||
|
||||
// Sending is covered by the feature tests: the browser plugin's test server keeps a
|
||||
// multipart field named files[] under that literal key, so Livewire receives no upload.
|
||||
$stored = app(TaskImageFiles::class)->store(browserTestImage(), $task->id);
|
||||
TaskImageModel::query()->create(['task_id' => $task->id, 'user_id' => $this->user->id, 'path' => $stored->path, 'thumbnail_path' => $stored->thumbnailPath, 'original_name' => 'valot.png', 'caption' => 'Valot paikallaan', 'width' => $stored->width, 'height' => $stored->height]);
|
||||
|
||||
$page = visit(route('jobs.show', $this->job->id))
|
||||
->click('#task-toggle-'.$task->id)
|
||||
->assertVisible('img[alt="Valot paikallaan"]')
|
||||
->assertScript("document.querySelector('img[alt=\"Valot paikallaan\"]').naturalWidth > 0", true)
|
||||
->assertSeeIn('#task-'.$task->id.'-title + dl', 'Kuvat:');
|
||||
|
||||
$imageId = TaskImageModel::query()->sole()->id;
|
||||
|
||||
$page->keys('#image-edit-button-'.$imageId, 'Enter')
|
||||
->assertScript('document.activeElement.id', 'image-caption-edit-'.$imageId)
|
||||
->type('#image-caption-edit-'.$imageId, 'Lavasteet')
|
||||
->keys('#image-caption-edit-'.$imageId, 'Enter')
|
||||
->assertSee('Kuvateksti tallennettu.')
|
||||
->assertScript('document.activeElement.id', 'image-edit-button-'.$imageId)
|
||||
->keys('[aria-label="Poista kuva: Lavasteet"]', 'Enter')
|
||||
->assertScript("document.getElementById('remove-image-dialog-{$task->id}').open", true)
|
||||
->assertNoAccessibilityIssues(level: 2)
|
||||
->click('#remove-image-confirm-'.$task->id)
|
||||
->assertSee('Kuva poistettu.')
|
||||
->assertScript('document.activeElement.id', 'image-new-'.$task->id)
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
|
||||
expect(TaskImageModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('adds tasks from a workflow template with the keyboard, without accessibility issues', function (string $device, string $colorScheme) {
|
||||
$this->job->update(['status' => 'order']);
|
||||
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();
|
||||
|
||||
Reference in New Issue
Block a user