Add machines with day-by-day work lists for job tasks
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?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 App\Modules\Machines\Application\UseCases\MachineWorkList;
|
||||
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MachineModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->management()->create(['name' => 'Johtaja']);
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$print = ServiceUnitModel::query()->where('name', 'Painotuotanto')->sole();
|
||||
$print->update(['uses_stock' => true]);
|
||||
$this->machine = MachineModel::factory()->inUnits([$print->id])->create(['name' => 'Suurkuvatulostin']);
|
||||
MachineModel::factory()->inUnits([$print->id])->create(['name' => 'Tarraleikkuri', 'type' => 'cutter']);
|
||||
|
||||
$this->job = CustomerJobModel::factory()->create(['name' => 'Messut', 'status' => 'order', 'instructions' => 'Kiiltävä laminointi']);
|
||||
DB::table('customer_job_service_unit')->where('customer_job_id', $this->job->id)->update(['service_unit_id' => $print->id]);
|
||||
$this->task = TaskModel::factory()->create([
|
||||
'customer_job_id' => $this->job->id,
|
||||
'work_type_id' => WorkTypeModel::query()->where('name', 'painotyö')->value('id'),
|
||||
'title' => 'Banderolli',
|
||||
'description' => 'Kaksi kappaletta',
|
||||
]);
|
||||
app(MachineWorkList::class)->planTask($this->task->id, $this->machine->id, null);
|
||||
});
|
||||
|
||||
it('has no accessibility issues on the machine pages', function (string $page, string $device, string $colorScheme) {
|
||||
$url = match ($page) {
|
||||
'index' => route('machines.index'),
|
||||
'show' => route('machines.show', $this->machine->id),
|
||||
'form' => route('machines.edit', $this->machine->id),
|
||||
'job' => route('jobs.show', $this->job->id).'#task-'.$this->task->id,
|
||||
};
|
||||
|
||||
$visit = visit($url);
|
||||
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
|
||||
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
|
||||
|
||||
$visit->assertSee($page === 'form' ? __('machines.form.edit_title') : 'Suurkuvatulostin')
|
||||
->assertNoJavaScriptErrors()
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
})->with(['index', 'show', 'form', 'job'])->with([
|
||||
'desktop, light' => ['desktop', 'light'],
|
||||
'desktop, dark' => ['desktop', 'dark'],
|
||||
'mobile, light' => ['mobile', 'light'],
|
||||
'mobile, dark' => ['mobile', 'dark'],
|
||||
]);
|
||||
|
||||
it('moves a task to another machine with the keyboard from the work list', function () {
|
||||
visit(route('machines.show', $this->machine->id))
|
||||
->assertSee('Banderolli')
|
||||
->click(__('machines.show.reschedule'))
|
||||
->assertNoAccessibilityIssues(level: 2)
|
||||
->select('#edit-machine', 'Tarraleikkuri')
|
||||
->click(__('machines.task.save'))
|
||||
->assertSee('Tehtävä siirretty koneen Tarraleikkuri työlistalle')
|
||||
->assertDontSee('Kiiltävä laminointi');
|
||||
});
|
||||
@@ -0,0 +1,143 @@
|
||||
<?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 App\Modules\Machines\Infrastructure\Persistence\Eloquent\MachineCounterModel;
|
||||
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MachineModel;
|
||||
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MachineQueueEntryModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->travelTo(now()->setTimezone(config('app.business_timezone'))->setTime(10, 0));
|
||||
$this->today = now(config('app.business_timezone'))->toDateString();
|
||||
$this->manager = User::factory()->management()->create(['name' => 'Maija Johto']);
|
||||
$this->employee = User::factory()->employee()->create(['name' => 'Eero Työntekijä']);
|
||||
|
||||
$this->print = ServiceUnitModel::query()->where('name', 'Painotuotanto')->sole();
|
||||
$this->print->update(['uses_stock' => true]);
|
||||
$this->printing = WorkTypeModel::query()->where('name', 'painotyö')->sole();
|
||||
|
||||
$this->printer = MachineModel::factory()->inUnits([$this->print->id])->create(['name' => 'Suurkuvatulostin']);
|
||||
$this->cutter = MachineModel::factory()->inUnits([$this->print->id])->create(['name' => 'Tarraleikkuri', 'type' => 'cutter']);
|
||||
|
||||
$this->job = CustomerJobModel::factory()->create(['name' => 'Messut', 'status' => 'order', 'priority' => 'normal', 'instructions' => 'Kiiltävä laminointi']);
|
||||
DB::table('customer_job_service_unit')->where('customer_job_id', $this->job->id)->update(['service_unit_id' => $this->print->id]);
|
||||
$this->urgentJob = CustomerJobModel::factory()->create(['name' => 'Kiire', 'status' => 'order', 'priority' => 'urgent']);
|
||||
DB::table('customer_job_service_unit')->where('customer_job_id', $this->urgentJob->id)->update(['service_unit_id' => $this->print->id]);
|
||||
|
||||
$this->banner = TaskModel::factory()->create(['customer_job_id' => $this->job->id, 'work_type_id' => $this->printing->id, 'title' => 'Banderolli']);
|
||||
$this->poster = TaskModel::factory()->create(['customer_job_id' => $this->urgentJob->id, 'work_type_id' => $this->printing->id, 'title' => 'Juliste']);
|
||||
});
|
||||
|
||||
function taskMachine(object $test, TaskModel $task): mixed
|
||||
{
|
||||
return Livewire::test('machines::task-machine', ['jobId' => $task->customer_job_id, 'taskId' => $task->id, 'taskTitle' => $task->title]);
|
||||
}
|
||||
|
||||
it('adds a machine with the suggested counters of its type in units that use stock', function () {
|
||||
$this->actingAs($this->manager);
|
||||
$video = ServiceUnitModel::query()->where('name', 'Mediatuotanto')->sole();
|
||||
|
||||
Livewire::test('machines::form')
|
||||
->assertSet('counters', fn (array $counters) => array_column($counters, 'name') === ['Tulosteet', 'Tulostettu pinta-ala'])
|
||||
->set('name', 'Valokuvatulostin')
|
||||
->set('serviceUnitIds', [(string) $this->print->id, (string) $video->id])
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$machine = MachineModel::query()->where('name', 'Valokuvatulostin')->sole();
|
||||
|
||||
expect(DB::table('machine_service_units')->where('machine_id', $machine->id)->pluck('service_unit_id')->all())->toBe([$this->print->id])
|
||||
->and(MachineCounterModel::query()->where('machine_id', $machine->id)->pluck('unit')->map->value->all())->toBe(['piece', 'square_metre']);
|
||||
|
||||
Livewire::test('machines::form')->set('name', 'Toinen')->set('serviceUnitIds', [])->call('save')->assertHasErrors('serviceUnitIds');
|
||||
Livewire::test('machines::form')->set('name', 'suurkuvatulostin')->set('serviceUnitIds', [(string) $this->print->id])->call('save')->assertHasErrors('name');
|
||||
|
||||
$this->actingAs($this->employee);
|
||||
$this->get(route('machines.create'))->assertForbidden();
|
||||
$this->get(route('machines.index'))->assertOk()->assertSee('Suurkuvatulostin');
|
||||
});
|
||||
|
||||
it('moves a task to a machine for a day and orders the day by priority', function () {
|
||||
$this->actingAs($this->employee);
|
||||
|
||||
taskMachine($this, $this->banner)
|
||||
->assertSee(__('machines.task.not_on_machine'))
|
||||
->call('startEdit')
|
||||
->assertSet('day', $this->today)
|
||||
->set('machineId', (string) $this->printer->id)
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertSee('Suurkuvatulostin');
|
||||
|
||||
taskMachine($this, $this->poster)->call('startEdit')->set('machineId', (string) $this->printer->id)->call('save');
|
||||
|
||||
Livewire::test('machines::show', ['machine' => $this->printer->id])
|
||||
->assertSeeInOrder(['Juliste', 'Banderolli'])
|
||||
->assertSee('Kiiltävä laminointi')
|
||||
->assertSee('2 riviä.');
|
||||
|
||||
$banner = MachineQueueEntryModel::query()->where('task_id', $this->banner->id)->sole();
|
||||
|
||||
Livewire::test('machines::show', ['machine' => $this->printer->id])
|
||||
->call('move', $banner->id, 'up')
|
||||
->assertSet('message', 'Banderolli siirretty ylöspäin.')
|
||||
->assertSeeInOrder(['Banderolli', 'Juliste'])
|
||||
->call('move', $banner->id, 'up')
|
||||
->assertSet('message', 'Banderolli on jo ensimmäisenä.');
|
||||
});
|
||||
|
||||
it('moves a row to another day and machine, shows it late afterwards, and takes it off', function () {
|
||||
$this->actingAs($this->employee);
|
||||
$tomorrow = now(config('app.business_timezone'))->addDay()->toDateString();
|
||||
|
||||
taskMachine($this, $this->banner)->call('startEdit')->set('machineId', (string) $this->printer->id)->set('day', $tomorrow)->call('save');
|
||||
|
||||
Livewire::test('machines::show', ['machine' => $this->printer->id])
|
||||
->assertDontSee('Banderolli')
|
||||
->call('showDay', 'next')
|
||||
->assertSee('Banderolli');
|
||||
|
||||
$entry = MachineQueueEntryModel::query()->sole();
|
||||
$this->travel(2)->days();
|
||||
|
||||
Livewire::test('machines::show', ['machine' => $this->printer->id])
|
||||
->assertSee('Banderolli')
|
||||
->assertSee('Myöhässä (ajoitettu '.now()->subDay()->format('j.n.').')')
|
||||
->call('startEdit', $entry->id)
|
||||
->set('editMachineId', (string) $this->cutter->id)
|
||||
->call('reschedule')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($entry->fresh()->machine_id)->toBe($this->cutter->id)
|
||||
->and(substr($entry->fresh()->planned_on, 0, 10))->toBe(now(config('app.business_timezone'))->toDateString());
|
||||
|
||||
Livewire::test('machines::show', ['machine' => $this->cutter->id])->call('remove', $entry->id)->assertSee(__('machines.task.removed'));
|
||||
|
||||
expect(MachineQueueEntryModel::query()->count())->toBe(0);
|
||||
});
|
||||
|
||||
it('takes a task that is marked done off the work list', function () {
|
||||
$this->actingAs($this->employee);
|
||||
taskMachine($this, $this->banner)->call('startEdit')->set('machineId', (string) $this->printer->id)->call('save');
|
||||
|
||||
Livewire::test('jobs::show', ['job' => $this->job->id])->call('changeTaskStatus', $this->banner->id, 'done');
|
||||
|
||||
expect(MachineQueueEntryModel::query()->sole()->completed_at)->not->toBeNull();
|
||||
Livewire::test('machines::show', ['machine' => $this->printer->id])->assertDontSee('Banderolli');
|
||||
});
|
||||
|
||||
it('does not offer machines for tasks of units without stock', function () {
|
||||
$this->actingAs($this->employee);
|
||||
$graphic = WorkTypeModel::query()->where('name', 'graafinen työ')->sole();
|
||||
$task = TaskModel::factory()->create(['customer_job_id' => $this->job->id, 'work_type_id' => $graphic->id, 'title' => 'Taitto']);
|
||||
|
||||
taskMachine($this, $task)->assertDontSee(__('machines.task.title'))->call('startEdit')->assertForbidden();
|
||||
});
|
||||
@@ -70,7 +70,7 @@ beforeEach(function () {
|
||||
$this->updateTask = new UpdateTask($this->jobs, $this->tasks, $checker, $this->planner, $transactions, $this->events);
|
||||
$this->scheduleTask = new ScheduleTask($this->jobs, $this->tasks, $checker, $this->planner, $transactions, $this->events);
|
||||
$this->clearSchedule = new ClearTaskSchedule($this->tasks, $this->planner, $transactions);
|
||||
$this->changeTaskStatus = new ChangeTaskStatus($this->tasks, $transactions);
|
||||
$this->changeTaskStatus = new ChangeTaskStatus($this->tasks, $transactions, $this->events);
|
||||
$this->usage = new FakeTaskUsage;
|
||||
$this->removeTask = new RemoveTask($this->tasks, $this->usage, $transactions, new InMemoryTaskImageRepository, new FakeTaskImageFiles);
|
||||
$this->changeJobStatus = new ChangeJobStatus($this->jobs, $transactions, new FakeClock(new DateTimeImmutable('2026-05-01')));
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Machines\Domain\Enums\MachineType;
|
||||
use App\Modules\Machines\Domain\Services\QueueOrder;
|
||||
|
||||
it('puts a task after quick sale orders, by priority and then due date', function () {
|
||||
$rows = [
|
||||
['isOrder' => true, 'rank' => 0, 'dueOn' => null],
|
||||
['isOrder' => false, 'rank' => 3, 'dueOn' => '2026-12-01'],
|
||||
['isOrder' => false, 'rank' => 1, 'dueOn' => '2026-11-30'],
|
||||
['isOrder' => false, 'rank' => 1, 'dueOn' => null],
|
||||
];
|
||||
|
||||
expect(QueueOrder::insertionIndex($rows, 4, null))->toBe(1)
|
||||
->and(QueueOrder::insertionIndex($rows, 1, '2026-11-28'))->toBe(2)
|
||||
->and(QueueOrder::insertionIndex($rows, 1, '2026-12-05'))->toBe(3)
|
||||
->and(QueueOrder::insertionIndex($rows, 1, null))->toBe(4)
|
||||
->and(QueueOrder::insertionIndex([], 1, null))->toBe(0);
|
||||
});
|
||||
|
||||
it('suggests the usual counters by machine type', function () {
|
||||
expect(array_column(MachineType::Printer->suggestedCounters(), 'name'))->toBe(['prints', 'printed_area'])
|
||||
->and(array_column(MachineType::Cutter->suggestedCounters(), 'name'))->toBe(['cut_length'])
|
||||
->and(MachineType::Other->suggestedCounters())->toBe([]);
|
||||
});
|
||||
Reference in New Issue
Block a user