- Toolbar: whose board (own, a person, a service line, all), pipeline views (daily, sales, full), urgent and late filters with a live count, normal and compact density, and the quick intake button. - Columns side by side with horizontal scrolling on desktop, stacked on phones; each user's own column colours and order, the urgent column's threshold menu, and the continuing jobs column. - Cards in customer colours: job cards with their tasks checked off inside the card (the status select is gone), continuing job cards with the next period, PIN and quick add, and pinned task cards. Dragging moves and orders cards; the keyboard opens the job editor from the card title. - Job editor dialog: every job detail, tasks with checklists and templates, quick hours (TimeTracking) and expenses (Expenses), history. - The quick intake form also adds a contact person, initial status and priority, and opens as a dialog on the board. Co-Authored-By: Claude Opus 5.5 <[email protected]>
127 lines
5.9 KiB
PHP
127 lines
5.9 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
|
use App\Modules\TimeTracking\Infrastructure\Persistence\Eloquent\TimeEntryModel;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->employee = User::factory()->employee()->create(['name' => 'Eero Työntekijä']);
|
|
$this->task = TaskModel::factory()->assignedTo([$this->employee->id])->create(['title' => 'Mainoskuvat']);
|
|
$this->monday = now()->startOfWeek()->toDateString();
|
|
$this->entry = TimeEntryModel::factory()->create(['task_id' => $this->task->id, 'user_id' => $this->employee->id, 'worked_on' => $this->monday, 'hours' => 3]);
|
|
});
|
|
|
|
it('decides who may approve whose hours', function () {
|
|
$management = User::factory()->management()->create();
|
|
$subcontractor = User::factory()->subcontractor()->create();
|
|
|
|
expect(Gate::forUser($this->employee)->allows('time.approve', $this->employee->id))->toBeTrue()
|
|
->and(Gate::forUser($this->employee)->allows('time.approve', $management->id))->toBeFalse()
|
|
->and(Gate::forUser($subcontractor)->allows('time.approve', $subcontractor->id))->toBeFalse()
|
|
->and(Gate::forUser($management)->allows('time.approve', $subcontractor->id))->toBeTrue()
|
|
->and(Gate::forUser($this->employee)->allows('time.cancel-approval'))->toBeFalse();
|
|
});
|
|
|
|
it('approves the own week in the weekly view, which locks its cells', function () {
|
|
$this->actingAs($this->employee);
|
|
|
|
Livewire::test('time::week')
|
|
->assertSee('Hyväksymättä 3 h.')
|
|
->call('approveWeek')
|
|
->assertSet('statusMessage', fn (string $message) => str_contains($message, 'hyväksytty. Hyväksytyt tunnit on lukittu.'))
|
|
->assertDontSee('id="cell-'.$this->task->id.'-'.$this->monday.'"', false)
|
|
->assertDontSee(__('time.approval.cancel'))
|
|
->call('saveCell', $this->task->id, $this->monday, '5');
|
|
|
|
$entry = $this->entry->refresh();
|
|
|
|
expect($entry->approved_by)->toBe($this->employee->id)
|
|
->and($entry->approved_at)->not->toBeNull()
|
|
->and((float) $entry->hours)->toBe(3.0);
|
|
});
|
|
|
|
it('does not let a subcontractor approve own hours', function () {
|
|
$subcontractor = User::factory()->subcontractor()->create();
|
|
$job = CustomerJobModel::factory()->withMembers([$subcontractor->id])->create(['status' => JobStatus::Order]);
|
|
$task = TaskModel::factory()->assignedTo([$subcontractor->id])->create(['customer_job_id' => $job->id]);
|
|
TimeEntryModel::factory()->create(['task_id' => $task->id, 'user_id' => $subcontractor->id, 'worked_on' => $this->monday]);
|
|
|
|
$this->actingAs($subcontractor);
|
|
|
|
Livewire::test('time::week')
|
|
->assertSee(__('time.approval.management_approves'))
|
|
->call('approveWeek')
|
|
->assertForbidden();
|
|
});
|
|
|
|
it('lets management open, approve and cancel another user\'s week read-only', function () {
|
|
$this->actingAs(User::factory()->management()->create(['name' => 'Johtaja']));
|
|
|
|
$this->get(route('time.week', ['kayttaja' => $this->employee->id]))
|
|
->assertOk()
|
|
->assertSee('Tuntikirjaus: Eero Työntekijä')
|
|
->assertDontSee('id="cell-', false)
|
|
->assertDontSee('id="task-search"', false);
|
|
|
|
Livewire::withQueryParams(['kayttaja' => (string) $this->employee->id])
|
|
->test('time::week')
|
|
->call('saveCell', $this->task->id, $this->monday, '5')
|
|
->call('approveWeek')
|
|
->assertSee('Johtaja')
|
|
->call('cancelApproval')
|
|
->assertSet('statusMessage', fn (string $message) => str_ends_with($message, 'hyväksyntä peruttu.'));
|
|
|
|
expect((float) $this->entry->refresh()->hours)->toBe(3.0)
|
|
->and($this->entry->approved_at)->toBeNull();
|
|
});
|
|
|
|
it('keeps employees out of other users\' weeks and the approval page', function () {
|
|
$this->actingAs(User::factory()->employee()->create());
|
|
|
|
$this->get(route('time.week', ['kayttaja' => $this->employee->id]))->assertForbidden();
|
|
$this->get(route('time.approvals'))->assertForbidden();
|
|
});
|
|
|
|
it('lists unapproved and approved weeks for management and approves from the list', function () {
|
|
$colleague = User::factory()->employee()->create(['name' => 'Kaisa Kollega']);
|
|
TimeEntryModel::factory()->approved()->create(['task_id' => TaskModel::factory()->assignedTo([$colleague->id])->create()->id, 'user_id' => $colleague->id, 'worked_on' => $this->monday, 'hours' => 1.5]);
|
|
|
|
$this->actingAs(User::factory()->management()->create());
|
|
|
|
Livewire::test('time::approvals')
|
|
->assertSeeInOrder(['Hyväksymättä', 'Eero Työntekijä', 'Hyväksytyt', 'Kaisa Kollega'])
|
|
->call('approve', $this->employee->id, $this->monday)
|
|
->assertSet('statusMessage', fn (string $message) => str_starts_with($message, 'Eero Työntekijä:'))
|
|
->assertSee(__('time.approvals.none_pending'));
|
|
|
|
expect($this->entry->refresh()->approved_at)->not->toBeNull();
|
|
});
|
|
|
|
it('lets only management move a done job back, which opens its lock', function () {
|
|
$job = CustomerJobModel::factory()->create(['status' => JobStatus::Done]);
|
|
|
|
$this->actingAs($this->employee);
|
|
|
|
Livewire::test('jobs::board')
|
|
->set('board', 'all')->call('setView', 'full')
|
|
->call('moveDropped', 'job-'.$job->id, 0, 'in_production')
|
|
->assertSet('statusMessage', fn (string $message) => str_contains($message, 'lukituksen voi avata vain johto'));
|
|
|
|
expect($job->refresh()->status)->toBe(JobStatus::Done);
|
|
|
|
$this->actingAs(User::factory()->management()->create());
|
|
|
|
Livewire::test('jobs::board')->set('board', 'all')->call('setView', 'full')->call('moveDropped', 'job-'.$job->id, 0, 'in_production');
|
|
|
|
expect($job->refresh()->status)->toBe(JobStatus::InProduction);
|
|
|
|
$this->get(route('jobs.show', $job->id))->assertSee(__('jobs.history.unlocked'));
|
|
});
|