Add the task calendar, holidays, workflow templates and customer removal
Task calendar (/jobs/calendar) replaces per-unit task Kanban columns (K34): a two-week Gantt of tasks per person. Bars move, resize and change person by dragging or through a keyboard dialog. Each task's estimate is booked evenly over working days into task_bookings, and what exceeds the daily maximum (jobs.daily_capacity_hours, 8 h) moves to the next working day. Tasks get planned_from/planned_to on the form. Holidays (/settings/holidays): Finnish public holidays calculated per year, which the admin can take out of use, plus company days off. Also includes the earlier uncommitted work: workflow templates with adding tasks from a template, and removing customers no module refers to. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Catalog\Application\Contracts\WorkflowTemplateQueries;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
|
||||
use App\Modules\Catalog\Application\UseCases\AddWorkflowTemplate;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Features\SupportLockedProperties\CannotUpdateLockedPropertyException;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->actingAs(User::factory()->management()->create());
|
||||
$this->workType = fn (string $name, string $unit = 'Mediatuotanto', ?string $service = 'Videotuotanto') => WorkTypeModel::query()
|
||||
->where('name', $name)
|
||||
->where('service_unit_id', ServiceUnitModel::query()->where('name', $unit)->sole()->id)
|
||||
->where('service_id', $service === null ? null : ServiceModel::query()->where('name', $service)->sole()->id)
|
||||
->sole();
|
||||
$this->videography = ($this->workType)('videokuvaus');
|
||||
$this->editing = ($this->workType)('editointi');
|
||||
$this->planning = ($this->workType)('suunnittelu', 'Kaikille yhteiset', null);
|
||||
|
||||
$this->addTemplate = fn (string $name, int $workTypeId, array $steps): int => app(AddWorkflowTemplate::class)->execute(new WorkflowTemplateData(
|
||||
$name,
|
||||
$workTypeId,
|
||||
array_map(fn (array $step): WorkflowStepData => new WorkflowStepData(...$step), $steps),
|
||||
));
|
||||
});
|
||||
|
||||
it('shows the template pages to admins and management only', function (string $role, int $status) {
|
||||
$this->actingAs(User::factory()->{$role}()->create());
|
||||
|
||||
$this->get(route('catalog.workflow-templates'))->assertStatus($status);
|
||||
$this->get(route('catalog.workflow-templates.create'))->assertStatus($status);
|
||||
})->with([
|
||||
'admin' => ['admin', 200],
|
||||
'management' => ['management', 200],
|
||||
'employee' => ['employee', 403],
|
||||
'subcontractor' => ['subcontractor', 403],
|
||||
]);
|
||||
|
||||
it('links the templates from the catalog page', function () {
|
||||
$this->get(route('catalog.index'))->assertSee(route('catalog.workflow-templates'));
|
||||
});
|
||||
|
||||
it('adds a template with steps added, moved and removed on the form', function () {
|
||||
Livewire::test('catalog::workflow-template-form')
|
||||
->set('form.name', 'Lyhyt video')
|
||||
->set('form.work_type_id', (string) $this->videography->id)
|
||||
->assertSee('editointi')
|
||||
->assertSee('suunnittelu')
|
||||
->set('form.steps.0.title', 'Kuvaus')
|
||||
->call('addStep')
|
||||
->assertSee('Vaihe 2 lisätty.')
|
||||
->set('form.steps.1.title', 'Suunnittelu')
|
||||
->set('form.steps.1.work_type_id', (string) $this->planning->id)
|
||||
->call('moveStep', 1, 'up')
|
||||
->assertSee('Vaihe 2 siirretty kohtaan 1.')
|
||||
->call('addStep')
|
||||
->set('form.steps.2.title', 'Turha')
|
||||
->call('removeStep', 2)
|
||||
->assertSee('Vaihe 3 poistettu.')
|
||||
->call('addStep')
|
||||
->set('form.steps.2.title', 'Editointi')
|
||||
->set('form.steps.2.work_type_id', (string) $this->editing->id)
|
||||
->set('form.steps.2.description', 'Leikkaus ja värimäärittely')
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('catalog.workflow-templates'));
|
||||
|
||||
$template = app(WorkflowTemplateQueries::class)->all()[0];
|
||||
$details = app(WorkflowTemplateQueries::class)->find($template->id);
|
||||
|
||||
expect($template->name)->toBe('Lyhyt video')
|
||||
->and($template->workTypeName)->toBe('videokuvaus')
|
||||
->and($template->serviceUnitName)->toBe('Mediatuotanto')
|
||||
->and($template->stepCount)->toBe(3)
|
||||
->and(array_map(fn ($step) => [$step->title, $step->workTypeId, $step->effectiveWorkTypeId, $step->workTypeName, $step->description], $details->steps))->toBe([
|
||||
['Suunnittelu', $this->planning->id, $this->planning->id, 'suunnittelu', null],
|
||||
['Kuvaus', null, $this->videography->id, 'videokuvaus', null],
|
||||
['Editointi', $this->editing->id, $this->editing->id, 'editointi', 'Leikkaus ja värimäärittely'],
|
||||
]);
|
||||
|
||||
$this->get(route('catalog.workflow-templates'))->assertSee('Lyhyt video')->assertSee('videokuvaus');
|
||||
});
|
||||
|
||||
it('shows Finnish errors on the right fields', function () {
|
||||
($this->addTemplate)('Lyhyt video', $this->videography->id, [['Kuvaus']]);
|
||||
|
||||
Livewire::test('catalog::workflow-template-form')
|
||||
->call('save')
|
||||
->assertHasErrors(['form.name', 'form.work_type_id', 'form.steps.0.title'])
|
||||
->assertSee('Anna nimi.')
|
||||
->assertSee('Valitse työtehtävä.')
|
||||
->assertSee('Anna tehtävän nimi.');
|
||||
|
||||
Livewire::test('catalog::workflow-template-form')
|
||||
->set('form.name', 'lyhyt video')
|
||||
->set('form.work_type_id', (string) $this->videography->id)
|
||||
->set('form.steps.0.title', 'Kuvaus')
|
||||
->call('save')
|
||||
->assertHasErrors(['form.name'])
|
||||
->assertSee('Työtehtävällä on jo tämänniminen pohja.');
|
||||
|
||||
Livewire::test('catalog::workflow-template-form')
|
||||
->set('form.name', 'Video ja grafiikka')
|
||||
->set('form.work_type_id', (string) $this->videography->id)
|
||||
->set('form.steps.0.title', 'Grafiikka')
|
||||
->set('form.steps.0.work_type_id', (string) ($this->workType)('graafinen työ', 'Markkinointi', null)->id)
|
||||
->call('save')
|
||||
->assertHasErrors(['form.steps.0.work_type_id'])
|
||||
->assertSee('Valitse käytössä oleva työtehtävä pohjan palveluyksiköstä tai kaikille yhteisistä.');
|
||||
});
|
||||
|
||||
it('edits a template and keeps tasks offered only while it is in use', function () {
|
||||
$id = ($this->addTemplate)('Lyhyt video', $this->videography->id, [['Kuvaus'], ['Editointi', null, $this->editing->id]]);
|
||||
|
||||
Livewire::test('catalog::workflow-template-form', ['template' => $id])
|
||||
->assertSet('form.name', 'Lyhyt video')
|
||||
->assertSet('form.steps.1.work_type_id', (string) $this->editing->id)
|
||||
->call('removeStep', 0)
|
||||
->set('form.name', 'Pelkkä editointi')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect(array_map(fn ($step) => $step->title, app(WorkflowTemplateQueries::class)->find($id)->steps))->toBe(['Editointi']);
|
||||
|
||||
$media = ServiceUnitModel::query()->where('name', 'Mediatuotanto')->sole()->id;
|
||||
$marketing = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole()->id;
|
||||
|
||||
expect(array_map(fn ($template) => $template->name, app(WorkflowTemplateQueries::class)->activeFor([$media])))->toBe(['Pelkkä editointi'])
|
||||
->and(app(WorkflowTemplateQueries::class)->activeFor([$marketing]))->toBe([]);
|
||||
|
||||
Livewire::test('catalog::workflow-templates')
|
||||
->call('toggleActive', $id)
|
||||
->assertSee('Pelkkä editointi poistettu käytöstä.');
|
||||
|
||||
expect(app(WorkflowTemplateQueries::class)->activeFor([$media]))->toBe([]);
|
||||
});
|
||||
|
||||
it('offers shared work type templates to every job', function () {
|
||||
($this->addTemplate)('Työpaja', $this->planning->id, [['Valmistelu'], ['Työpaja']]);
|
||||
|
||||
$marketing = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole()->id;
|
||||
|
||||
expect(array_map(fn ($template) => $template->name, app(WorkflowTemplateQueries::class)->activeFor([$marketing])))->toBe(['Työpaja']);
|
||||
});
|
||||
|
||||
it('returns 404 for an unknown template', function () {
|
||||
$this->get(route('catalog.workflow-templates.edit', 999))->assertNotFound();
|
||||
});
|
||||
|
||||
it('locks the template id', function () {
|
||||
Livewire::test('catalog::workflow-template-form')->set('templateId', 1);
|
||||
})->throws(CannotUpdateLockedPropertyException::class);
|
||||
@@ -5,6 +5,8 @@ use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\BillingUnitModel;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerContactModel;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Sales\Infrastructure\Persistence\Eloquent\QuickSaleModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Features\SupportLockedProperties\CannotUpdateLockedPropertyException;
|
||||
use Livewire\Livewire;
|
||||
@@ -184,3 +186,73 @@ it('deletes the contacts and billing units of a deleted customer', function () {
|
||||
expect(CustomerContactModel::query()->count())->toBe(0)
|
||||
->and(BillingUnitModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('removes a customer that has nothing linked to it and returns to the list', function () {
|
||||
Livewire::test('customers::show', ['customer' => $this->customer->id])
|
||||
->call('confirmRemoval', 'customer', $this->customer->id)
|
||||
->assertSee('Poistetaanko asiakas Mainos Oy?')
|
||||
->call('remove')
|
||||
->assertRedirect(route('customers.index'));
|
||||
|
||||
expect($this->customer->fresh())->toBeNull()
|
||||
->and(session('status'))->toBe('Asiakas Mainos Oy poistettu.');
|
||||
});
|
||||
|
||||
it('keeps a customer that has a contact or a customer job and tells why', function (string $link) {
|
||||
match ($link) {
|
||||
'contact' => CustomerContactModel::factory()->create(['customer_id' => $this->customer->id]),
|
||||
'customer job' => CustomerJobModel::factory()->create(['customer_id' => $this->customer->id]),
|
||||
};
|
||||
|
||||
Livewire::test('customers::show', ['customer' => $this->customer->id])
|
||||
->call('confirmRemoval', 'customer', $this->customer->id)
|
||||
->call('remove')
|
||||
->assertNoRedirect()
|
||||
->assertSee('Asiakasta Mainos Oy ei poistettu');
|
||||
|
||||
expect($this->customer->fresh())->not->toBeNull();
|
||||
})->with(['contact', 'customer job']);
|
||||
|
||||
it('has no remove button for the internal customer and does not remove it', function () {
|
||||
$internal = CustomerModel::query()->where('is_internal', true)->sole();
|
||||
|
||||
Livewire::test('customers::show', ['customer' => $internal->id])
|
||||
->assertDontSee('Poista asiakas')
|
||||
->call('confirmRemoval', 'customer', $internal->id)
|
||||
->call('remove')
|
||||
->assertSee('Sisäistä asiakasta ei voi poistaa.');
|
||||
|
||||
expect($internal->fresh())->not->toBeNull();
|
||||
});
|
||||
|
||||
it('does not remove another customer than the one on the page', function () {
|
||||
$other = CustomerModel::factory()->create();
|
||||
|
||||
Livewire::test('customers::show', ['customer' => $this->customer->id])
|
||||
->call('confirmRemoval', 'customer', $other->id)
|
||||
->assertSet('removalId', null)
|
||||
->call('remove');
|
||||
|
||||
expect($other->fresh())->not->toBeNull()
|
||||
->and($this->customer->fresh())->not->toBeNull();
|
||||
});
|
||||
|
||||
it('shows the remove customer button only when nothing is linked to the customer', function (?string $link) {
|
||||
match ($link) {
|
||||
null => null,
|
||||
'contact' => CustomerContactModel::factory()->create(['customer_id' => $this->customer->id]),
|
||||
'billing unit' => BillingUnitModel::factory()->create(['customer_id' => $this->customer->id]),
|
||||
'customer job' => CustomerJobModel::factory()->create(['customer_id' => $this->customer->id]),
|
||||
'quick sale' => QuickSaleModel::factory()->create(['customer_id' => $this->customer->id]),
|
||||
};
|
||||
|
||||
$page = Livewire::test('customers::show', ['customer' => $this->customer->id]);
|
||||
|
||||
$link === null ? $page->assertSee('Poista asiakas') : $page->assertDontSee('Poista asiakas');
|
||||
})->with([
|
||||
'nothing' => [null],
|
||||
'contact' => ['contact'],
|
||||
'billing unit' => ['billing unit'],
|
||||
'customer job' => ['customer job'],
|
||||
'quick sale' => ['quick sale'],
|
||||
]);
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
||||
use App\Modules\Customers\Application\Contracts\CustomerReferences;
|
||||
use App\Modules\Customers\Domain\Contracts\CustomerRepository;
|
||||
use App\Modules\Customers\Domain\Entities\Customer;
|
||||
use App\Modules\Customers\Domain\Enums\CustomerType;
|
||||
use App\Modules\Customers\Domain\Exceptions\CustomerInUse;
|
||||
use App\Modules\Customers\Domain\ValueObjects\CustomerName;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Sales\Infrastructure\Persistence\Eloquent\QuickSaleModel;
|
||||
use App\Modules\Shared\Domain\ValueObjects\BusinessId;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
@@ -55,3 +61,46 @@ it('returns summaries filtered by name or business id, ordered by name', functio
|
||||
->and($queries->paginate(null)->total())->toBe(4) // and the internal customer
|
||||
->and($queries->search('100%'))->toBe([]);
|
||||
});
|
||||
|
||||
it('deletes a customer that nothing refers to', function () {
|
||||
$repository = app(CustomerRepository::class);
|
||||
$customer = $repository->save(Customer::register(new CustomerName('Mainos Oy'), CustomerType::Company));
|
||||
|
||||
$repository->delete($customer);
|
||||
|
||||
expect($repository->findById((int) $customer->id()))->toBeNull();
|
||||
});
|
||||
|
||||
it('refuses to delete a customer that a customer job or a quick sale refers to', function (string $reference) {
|
||||
$customer = CustomerModel::factory()->create();
|
||||
|
||||
match ($reference) {
|
||||
'customer job' => CustomerJobModel::factory()->create(['customer_id' => $customer->id]),
|
||||
'quick sale' => QuickSaleModel::factory()->create(['customer_id' => $customer->id]),
|
||||
};
|
||||
|
||||
$repository = app(CustomerRepository::class);
|
||||
|
||||
expect(fn () => $repository->delete($repository->findById($customer->id)))->toThrow(CustomerInUse::class)
|
||||
->and($customer->fresh())->not->toBeNull();
|
||||
})->with(['customer job', 'quick sale']);
|
||||
|
||||
it('tells whether customer jobs, quick sales or invoices refer to a customer', function (string $reference) {
|
||||
$customer = CustomerModel::factory()->create();
|
||||
$references = app(CustomerReferences::class);
|
||||
|
||||
expect($references->refersTo($customer->id))->toBeFalse();
|
||||
|
||||
match ($reference) {
|
||||
'customer job' => CustomerJobModel::factory()->create(['customer_id' => $customer->id]),
|
||||
'quick sale' => QuickSaleModel::factory()->create(['customer_id' => $customer->id]),
|
||||
'invoice' => DB::table('billing_invoices')->insert([
|
||||
'billing_export_id' => DB::table('billing_exports')->insertGetId(['status' => 'draft', 'created_by' => User::factory()->create()->id, 'created_at' => now(), 'updated_at' => now()]),
|
||||
'customer_id' => $customer->id,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]),
|
||||
};
|
||||
|
||||
expect($references->refersTo($customer->id))->toBeTrue();
|
||||
})->with(['customer job', 'quick sale', 'invoice']);
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->travelTo(new DateTimeImmutable('2026-12-21 09:00'));
|
||||
|
||||
$this->employee = User::factory()->create(['name' => 'Eero Työntekijä']);
|
||||
$this->other = User::factory()->create(['name' => 'Aino Ahkera']);
|
||||
$this->actingAs($this->employee);
|
||||
$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' => $marketing->id]);
|
||||
$this->graphic = WorkTypeModel::query()->where('name', 'graafinen työ')->sole();
|
||||
});
|
||||
|
||||
function calendarTaskModel(array $attributes, array $assignees): TaskModel
|
||||
{
|
||||
return TaskModel::factory()->assignedTo($assignees)->create($attributes);
|
||||
}
|
||||
|
||||
it('shows the two weeks from today with holidays, rows and bars', function () {
|
||||
calendarTaskModel(['customer_job_id' => test()->job->id, 'work_type_id' => test()->graphic->id, 'title' => 'Mainoskuvat', 'planned_from' => '2026-12-22', 'planned_to' => '2026-12-23'], [test()->other->id]);
|
||||
calendarTaskModel(['customer_job_id' => test()->job->id, 'work_type_id' => test()->graphic->id, 'title' => 'Ilman aikataulua'], [test()->employee->id]);
|
||||
|
||||
$this->get(route('jobs.calendar'))
|
||||
->assertOk()
|
||||
->assertSee('Tehtäväkalenteri')
|
||||
->assertSee('21.12.2026–3.1.2027')
|
||||
->assertSee('Jouluaatto')
|
||||
->assertSee('Uudenvuodenpäivä')
|
||||
->assertSeeInOrder(['Eero Työntekijä', 'Aino Ahkera', 'Ei tekijää'])
|
||||
->assertSee('Mainoskuvat')
|
||||
->assertSee('Aikatauluttamattomat tehtävät')
|
||||
->assertSee('Ilman aikataulua');
|
||||
});
|
||||
|
||||
it('moves a task to another person by dropping it and books their days', function () {
|
||||
$task = calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Mainoskuvat', 'estimated_hours' => 12], [$this->employee->id]);
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('reschedule', $task->id, $this->job->id, $this->employee->id, $this->other->id, '2026-12-28', null)
|
||||
->assertSee('Tehtävä Mainoskuvat: Aino Ahkera 28.12.2026–29.12.2026.');
|
||||
|
||||
expect($task->refresh()->planned_from?->format('Y-m-d'))->toBe('2026-12-28')
|
||||
->and($task->planned_to?->format('Y-m-d'))->toBe('2026-12-29')
|
||||
->and(DB::table('task_assignees')->where('task_id', $task->id)->pluck('user_id')->all())->toBe([$this->other->id])
|
||||
->and(DB::table('task_bookings')->where('task_id', $task->id)->orderBy('day')->pluck('minutes', 'day')->all())->toBe(['2026-12-28' => 360, '2026-12-29' => 360]);
|
||||
});
|
||||
|
||||
it('continues a task on the next working day when the day is full', function () {
|
||||
calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Kuvaus', 'estimated_hours' => 6], [$this->employee->id]);
|
||||
$first = TaskModel::query()->sole();
|
||||
Livewire::test('jobs::calendar')->call('reschedule', $first->id, $this->job->id, $this->employee->id, $this->employee->id, '2026-12-23', '2026-12-23');
|
||||
$task = calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Taitto', 'estimated_hours' => 4], [$this->employee->id]);
|
||||
|
||||
// 24.–27.12. are holidays and a weekend, so the rest goes to Monday.
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('reschedule', $task->id, $this->job->id, $this->employee->id, $this->employee->id, '2026-12-23', '2026-12-23')
|
||||
->assertSee('Päivät olivat täynnä, joten tehtävä jatkuu 28.12.2026 asti.')
|
||||
->assertSee('8 / 8 h');
|
||||
|
||||
expect($task->refresh()->planned_to?->format('Y-m-d'))->toBe('2026-12-28');
|
||||
});
|
||||
|
||||
it('changes the schedule and status in the dialog and takes a task out of the calendar', function () {
|
||||
$task = calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Mainoskuvat', 'planned_from' => '2026-12-22', 'planned_to' => '2026-12-22'], [$this->employee->id]);
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('openDialog', $task->id, $this->employee->id)
|
||||
->assertSet('plannedFrom', '2026-12-22')
|
||||
->set('plannedFrom', '2026-12-29')
|
||||
->set('plannedTo', '2026-12-28')
|
||||
->call('saveDialog')
|
||||
->assertHasErrors('plannedTo')
|
||||
->set('plannedTo', '2026-12-30')
|
||||
->set('status', 'in_progress')
|
||||
->call('saveDialog')
|
||||
->assertHasNoErrors()
|
||||
->assertSee('Tehtävän Mainoskuvat tila on nyt Työn alla.')
|
||||
->call('openDialog', $task->id, $this->employee->id)
|
||||
->call('clearSchedule')
|
||||
->assertSee('Tehtävän Mainoskuvat aikataulu poistettu.');
|
||||
|
||||
expect($task->refresh()->status->value)->toBe('in_progress')
|
||||
->and($task->planned_from)->toBeNull();
|
||||
});
|
||||
|
||||
it('shows a subcontractor only their own row and lets them change only the status', function () {
|
||||
$subcontractor = User::factory()->subcontractor()->create(['name' => 'Ville Alihankkija']);
|
||||
DB::table('customer_job_members')->insert(['customer_job_id' => $this->job->id, 'user_id' => $subcontractor->id]);
|
||||
$own = calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Oma tehtävä', 'planned_from' => '2026-12-22', 'planned_to' => '2026-12-22'], [$subcontractor->id]);
|
||||
calendarTaskModel(['customer_job_id' => $this->job->id, 'work_type_id' => $this->graphic->id, 'title' => 'Toisen tehtävä', 'planned_from' => '2026-12-22', 'planned_to' => '2026-12-22'], [$this->employee->id]);
|
||||
$this->actingAs($subcontractor);
|
||||
|
||||
$this->get(route('jobs.calendar'))
|
||||
->assertOk()
|
||||
->assertSee('Oma tehtävä')
|
||||
->assertDontSee('Toisen tehtävä')
|
||||
->assertDontSee('Eero Työntekijä')
|
||||
->assertDontSee('Ei tekijää');
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('reschedule', $own->id, $this->job->id, $subcontractor->id, $subcontractor->id, '2026-12-28', null)
|
||||
->assertForbidden();
|
||||
|
||||
Livewire::test('jobs::calendar')
|
||||
->call('openDialog', $own->id, $subcontractor->id)
|
||||
->set('status', 'done')
|
||||
->call('saveDialog')
|
||||
->assertSee('Tehtävän Oma tehtävä tila on nyt Valmis.');
|
||||
|
||||
expect($own->refresh()->status->value)->toBe('done')
|
||||
->and($own->planned_from?->format('Y-m-d'))->toBe('2026-12-22');
|
||||
});
|
||||
|
||||
it('adds a schedule on the task form', function () {
|
||||
Livewire::test('jobs::task-form', ['job' => $this->job->id])
|
||||
->set('form.title', 'Mainoskuvat')
|
||||
->set('form.work_type_id', (string) $this->graphic->id)
|
||||
->set('form.estimated_hours', '4')
|
||||
->set('form.planned_from', '2026-12-28')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$task = TaskModel::query()->sole();
|
||||
|
||||
expect($task->planned_to?->format('Y-m-d'))->toBe('2026-12-28')
|
||||
->and(DB::table('task_bookings')->where('task_id', $task->id)->sum('minutes'))->toBe(240);
|
||||
});
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepData;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateData;
|
||||
use App\Modules\Catalog\Application\UseCases\AddWorkflowTemplate;
|
||||
use App\Modules\Catalog\Application\UseCases\SetWorkflowTemplateActive;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Features\SupportLockedProperties\CannotUpdateLockedPropertyException;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->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();
|
||||
$printing = WorkTypeModel::query()->where('name', 'painotyö')->sole();
|
||||
|
||||
$add = fn (string $name, int $workTypeId, array $steps): int => app(AddWorkflowTemplate::class)->execute(new WorkflowTemplateData(
|
||||
$name,
|
||||
$workTypeId,
|
||||
array_map(fn (array $step): WorkflowStepData => new WorkflowStepData(...$step), $steps),
|
||||
));
|
||||
|
||||
$this->campaign = $add('Somekampanja', $this->graphic->id, [['Suunnittelu', 'Kohderyhmä ja viestit', $this->planning->id], ['Kuvat'], ['Julkaisu']]);
|
||||
$this->print = $add('Esite', $printing->id, [['Painatus']]);
|
||||
});
|
||||
|
||||
it('adds the steps of a template as tasks of the job', function () {
|
||||
$this->get(route('jobs.show', $this->job->id))->assertSee(route('jobs.tasks.from-template', $this->job->id));
|
||||
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->assertSee('Somekampanja (graafinen työ)')
|
||||
->assertSee('Vaiheet: Suunnittelu (suunnittelu) → Kuvat → Julkaisu')
|
||||
->assertDontSee('Esite')
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->call('add')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('jobs.show', $this->job->id).'#tasks');
|
||||
|
||||
$tasks = TaskModel::query()->orderBy('id')->get();
|
||||
|
||||
expect($tasks->map(fn ($task) => [$task->title, $task->work_type_id, $task->status->value, $task->description])->all())->toBe([
|
||||
['Suunnittelu', $this->planning->id, 'waiting', 'Kohderyhmä ja viestit'],
|
||||
['Kuvat', $this->graphic->id, 'waiting', null],
|
||||
['Julkaisu', $this->graphic->id, 'waiting', null],
|
||||
])
|
||||
->and(DB::table('task_assignees')->pluck('user_id')->unique()->values()->all())->toBe([$this->employee->id]);
|
||||
|
||||
$this->get(route('jobs.show', $this->job->id))->assertSee('Lisättiin 3 tehtävää pohjasta Somekampanja (graafinen työ).');
|
||||
});
|
||||
|
||||
it('needs a template that is still available', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->call('add')
|
||||
->assertHasErrors(['templateId'])
|
||||
->assertSee('Valitse pohja.');
|
||||
|
||||
$component = Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])->set('templateId', (string) $this->campaign);
|
||||
app(SetWorkflowTemplateActive::class)->execute($this->campaign, false);
|
||||
|
||||
$component->call('add')
|
||||
->assertHasErrors(['templateId'])
|
||||
->assertSee('Pohja ei ole enää käytettävissä tälle työlle. Valitse toinen.');
|
||||
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->set('templateId', (string) $this->print)
|
||||
->call('add')
|
||||
->assertHasErrors(['templateId']);
|
||||
|
||||
expect(TaskModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('is not for subcontractors, jobs before a quote request or archived jobs', function () {
|
||||
$this->job->update(['status' => 'tentative']);
|
||||
$this->get(route('jobs.tasks.from-template', $this->job->id))->assertNotFound();
|
||||
|
||||
$this->job->update(['status' => 'archived']);
|
||||
$this->get(route('jobs.tasks.from-template', $this->job->id))->assertNotFound();
|
||||
|
||||
$this->job->update(['status' => 'order']);
|
||||
$subcontractor = User::factory()->subcontractor()->create();
|
||||
DB::table('customer_job_members')->insert(['customer_job_id' => $this->job->id, 'user_id' => $subcontractor->id]);
|
||||
|
||||
$this->actingAs($subcontractor)->get(route('jobs.tasks.from-template', $this->job->id))->assertForbidden();
|
||||
});
|
||||
|
||||
it('locks the job id', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])->set('jobId', 999);
|
||||
})->throws(CannotUpdateLockedPropertyException::class);
|
||||
|
||||
it('shows a table of the chosen template tasks and saves their due dates and estimates', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->assertDontSee('Pohjan Somekampanja tehtävät')
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->assertSet('rows', array_fill(0, 3, ['due_on' => '', 'estimated_hours' => '']))
|
||||
->assertSee('Pohjan Somekampanja tehtävät')
|
||||
->assertSee('Määräpäivä: Kuvat')
|
||||
->assertSee('Arvioitu aika (h): Julkaisu')
|
||||
->set('rows.0.due_on', '2026-06-01')
|
||||
->set('rows.0.estimated_hours', '1,5')
|
||||
->set('rows.2.estimated_hours', '2')
|
||||
->call('add')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$tasks = TaskModel::query()->orderBy('id')->get();
|
||||
|
||||
expect($tasks->map(fn ($task) => [$task->title, $task->due_on?->format('Y-m-d'), $task->estimated_hours === null ? null : (float) $task->estimated_hours])->all())->toBe([
|
||||
['Suunnittelu', '2026-06-01', 1.5],
|
||||
['Kuvat', null, null],
|
||||
['Julkaisu', null, 2.0],
|
||||
]);
|
||||
});
|
||||
|
||||
it('shows errors in the table cells and adds nothing', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->set('rows.1.due_on', '1.6.2026')
|
||||
->set('rows.2.estimated_hours', 'paljon')
|
||||
->call('add')
|
||||
->assertHasErrors(['rows.1.due_on', 'rows.2.estimated_hours'])
|
||||
->assertSee('aria-invalid="true"', escape: false);
|
||||
|
||||
expect(TaskModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('empties the rows when another template is chosen', function () {
|
||||
Livewire::test('jobs::tasks-from-template', ['job' => $this->job->id])
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->set('rows.0.estimated_hours', '3')
|
||||
->set('templateId', '')
|
||||
->assertSet('rows', [])
|
||||
->set('templateId', (string) $this->campaign)
|
||||
->assertSet('rows.0.estimated_hours', '');
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('lets only the admin open the holidays page', function () {
|
||||
$this->actingAs(User::factory()->management()->create());
|
||||
$this->get(route('settings.holidays'))->assertForbidden();
|
||||
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
$this->get(route('settings.holidays', ['year' => 2026]))
|
||||
->assertOk()
|
||||
->assertSee('Arkipyhät')
|
||||
->assertSee('Vuosi 2026')
|
||||
->assertSee('pe 3.4.2026')
|
||||
->assertSee('Pitkäperjantai')
|
||||
->assertSee('Juhannusaatto');
|
||||
});
|
||||
|
||||
it('takes a holiday out of use and adds and removes a company day off', function () {
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
|
||||
Livewire::test('shared::holidays', ['year' => 2026])
|
||||
->call('disable', '2026-12-24')
|
||||
->assertSee('Jouluaatto (to 24.12.2026) poistettu käytöstä.')
|
||||
->assertSee('Ei käytössä')
|
||||
->set('date', '2026-12-23')
|
||||
->set('name', 'Pikkujoulu')
|
||||
->call('add')
|
||||
->assertHasNoErrors()
|
||||
->assertSee('Pikkujoulu (ke 23.12.2026) lisätty.')
|
||||
->set('date', '2026-12-25')
|
||||
->set('name', 'Joulu')
|
||||
->call('add')
|
||||
->assertHasErrors('date')
|
||||
->call('remove', '2026-12-23')
|
||||
->assertSee('Pikkujoulu (ke 23.12.2026) poistettu.');
|
||||
|
||||
$this->assertDatabaseHas('holiday_overrides', ['date' => '2026-12-24', 'is_holiday' => false]);
|
||||
$this->assertDatabaseMissing('holiday_overrides', ['date' => '2026-12-23']);
|
||||
});
|
||||
Reference in New Issue
Block a user