employee = User::factory()->create(['name' => 'Eero Työntekijä']); $this->actingAs($this->employee); $this->marketing = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole(); $this->job = CustomerJobModel::factory()->create(['name' => 'Kampanja', 'status' => 'order', 'responsible_user_id' => $this->employee->id]); DB::table('customer_job_service_unit')->where('customer_job_id', $this->job->id)->update(['service_unit_id' => $this->marketing->id]); $this->graphic = WorkTypeModel::query()->where('name', 'graafinen työ')->sole(); $this->planning = WorkTypeModel::query()->where('name', 'suunnittelu')->sole(); }); it('adds a task with work types of the job and the shared ones on offer', function () { $this->get(route('jobs.tasks.create', $this->job->id)) ->assertOk() ->assertSee('graafinen työ') ->assertSee('suunnittelu') ->assertDontSee('painotyö'); Livewire::test('jobs::task-form', ['job' => $this->job->id]) ->assertSet('form.assignee_user_ids', [(string) $this->employee->id]) ->set('form.title', 'Mainoskuvat') ->set('form.work_type_id', (string) $this->graphic->id) ->set('form.due_on', '2026-05-20') ->call('save') ->assertHasNoErrors() ->assertRedirect(route('jobs.show', $this->job->id).'#tasks'); $task = TaskModel::query()->sole(); expect($task->work_type_id)->toBe($this->graphic->id) ->and(DB::table('task_assignees')->where('task_id', $task->id)->pluck('user_id')->all())->toBe([$this->employee->id]); $this->get(route('jobs.show', $this->job->id)) ->assertSee('Mainoskuvat') ->assertSee('graafinen työ') ->assertSee('Eero Työntekijä'); }); it('shows Finnish errors on the task form', function () { Livewire::test('jobs::task-form', ['job' => $this->job->id]) ->call('save') ->assertHasErrors(['form.title', 'form.work_type_id']) ->assertSee('Anna tehtävän nimi.') ->assertSee('Valitse työtehtävä.'); }); it('does not add tasks before the job is a quote request', function () { $this->job->update(['status' => 'tentative']); $this->get(route('jobs.tasks.create', $this->job->id))->assertNotFound(); $this->get(route('jobs.show', $this->job->id)) ->assertSee('Tehtäviä voi lisätä, kun työ on tarjouspyyntö-tilassa') ->assertDontSee('Lisää tehtävä'); }); it('edits, changes the status of and removes a task on the job page', function () { $task = TaskModel::factory()->create(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Mainoskuvat']); Livewire::test('jobs::task-form', ['job' => $this->job->id, 'task' => $task->id]) ->assertSet('form.title', 'Mainoskuvat') ->set('form.work_type_id', (string) $this->planning->id) ->call('save') ->assertHasNoErrors(); Livewire::test('jobs::show', ['job' => $this->job->id]) ->call('changeTaskStatus', $task->id, 'in_review') ->assertSee('Tehtävän Mainoskuvat tila on nyt Tarkastettavana.') ->call('confirmTaskRemoval', $task->id) ->assertSee('Poistetaanko tehtävä Mainoskuvat?') ->call('removeTask') ->assertSee('Tehtävä Mainoskuvat poistettu.'); expect(TaskModel::query()->count())->toBe(0); }); it('counts task assignees as members in my jobs', function () { $colleague = User::factory()->create(); TaskModel::factory()->assignedTo([$colleague->id])->create(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id]); $this->actingAs($colleague); Livewire::test('jobs::index')->assertSee('Kampanja'); }); it('lets a subcontractor change task statuses on their jobs, but not add or change tasks', function () { $subcontractor = User::factory()->subcontractor()->create(); $task = TaskModel::factory()->assignedTo([$subcontractor->id])->create(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id]); $this->actingAs($subcontractor); $this->get(route('jobs.show', $this->job->id))->assertOk()->assertDontSee('Lisää tehtävä'); $this->get(route('jobs.tasks.create', $this->job->id))->assertForbidden(); $this->get(route('jobs.tasks.edit', [$this->job->id, $task->id]))->assertForbidden(); Livewire::test('jobs::show', ['job' => $this->job->id]) ->call('changeTaskStatus', $task->id, 'done') ->assertHasNoErrors() ->call('confirmTaskRemoval', $task->id) ->assertForbidden(); expect($task->fresh()->status->value)->toBe('done'); }); it('returns 404 for a task of another job', function () { $other = TaskModel::factory()->create(); $this->get(route('jobs.tasks.edit', [$this->job->id, $other->id]))->assertNotFound(); });