Files
Toiminnanohjaus/tests/Feature/Modules/Jobs/JobMoneyFieldsTest.php
T
petriandClaude Opus 5.5 6332ff0fa9 Rebuild the Kanban board after the prototype, with the job editor and quick intake dialog
- 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]>
2026-11-30 06:33:28 +02:00

123 lines
4.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\Users\Domain\Enums\MoneyPermission;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->job = CustomerJobModel::factory()->quoted(450000)->create(['name' => 'Messuvideo', 'status' => JobStatus::Order]);
});
it('lets management set the quoted amount and see it with its history', function () {
$this->actingAs(User::factory()->management()->create());
Livewire::test('jobs::form', ['job' => $this->job->id])
->assertSet('form.quoted_amount', '4500,00')
->set('form.quoted_amount', '5200,50')
->call('save')
->assertHasNoErrors();
expect($this->job->refresh()->quoted_amount_cents)->toBe(520050);
$this->get(route('jobs.show', $this->job->id))
->assertSee('Budjetti / tarjoussumma')
->assertSee("5\u{00A0}200,50\u{00A0}€", false)
->assertSee("4\u{00A0}500,00\u{00A0}€", false);
});
it('rejects an invalid quoted amount with a Finnish field error', function () {
$this->actingAs(User::factory()->management()->create());
Livewire::test('jobs::form', ['job' => $this->job->id])
->set('form.quoted_amount', '12,345')
->call('save')
->assertHasErrors(['form.quoted_amount' => [__('jobs.errors.invalid_amount')]]);
});
it('hides the quoted amount from employees without the quotes permission and keeps it when they save', function () {
$this->actingAs(User::factory()->management()->create());
Livewire::test('jobs::form', ['job' => $this->job->id])->set('form.quoted_amount', '5000')->call('save');
$this->actingAs(User::factory()->employee()->create());
$this->get(route('jobs.show', $this->job->id))
->assertOk()
->assertDontSee('Budjetti / tarjoussumma')
->assertDontSee("5\u{00A0}000,00\u{00A0}€", false);
Livewire::test('jobs::form', ['job' => $this->job->id])
->assertSet('form.quoted_amount', '')
->assertDontSee('Budjetti / tarjoussumma')
->set('form.quoted_amount', '1')
->set('form.name', 'Messuvideo 2')
->call('save')
->assertHasNoErrors();
expect($this->job->refresh()->quoted_amount_cents)->toBe(500000)
->and($this->job->name)->toBe('Messuvideo 2');
});
it('shows the quoted amount to an employee with the quotes permission', function () {
$this->actingAs(User::factory()->employee()->withMoneyPermissions(MoneyPermission::Quotes)->create());
$this->get(route('jobs.show', $this->job->id))->assertSee("4\u{00A0}500,00\u{00A0}€", false);
Livewire::test('jobs::form', ['job' => $this->job->id])
->set('form.quoted_amount', '')
->call('save')
->assertHasNoErrors();
expect($this->job->refresh()->quoted_amount_cents)->toBeNull();
});
it('records when a job is done and clears it when management opens the lock', function () {
$this->actingAs(User::factory()->management()->create());
Livewire::test('jobs::board')->set('board', 'all')->call('setView', 'full')->call('moveDropped', 'job-'.$this->job->id, 0, 'done');
$completedAt = $this->job->refresh()->completed_at;
expect($completedAt)->not->toBeNull();
Livewire::test('jobs::board')->set('board', 'all')->call('setView', 'full')->call('moveDropped', 'job-'.$this->job->id, 0, 'invoiced');
expect($this->job->refresh()->completed_at?->equalTo($completedAt))->toBeTrue();
$this->get(route('jobs.show', $this->job->id))->assertSee('Valmistunut');
Livewire::test('jobs::board')->set('board', 'all')->call('setView', 'full')->call('moveDropped', 'job-'.$this->job->id, 0, 'in_production');
expect($this->job->refresh()->completed_at)->toBeNull();
});
it('keeps the monthly fee of a monthly fee job with its history, behind the quotes permission', function () {
$this->actingAs(User::factory()->management()->create());
Livewire::test('jobs::form', ['job' => $this->job->id])
->assertDontSee('Kuukausihinta (€, ALV 0)')
->set('form.payment_basis', 'monthly_fee')
->assertSee('Kuukausihinta (€, ALV 0)')
->set('form.monthly_fee', '12,345')
->call('save')
->assertHasErrors(['form.monthly_fee' => [__('jobs.errors.invalid_amount')]])
->set('form.monthly_fee', '99,90')
->call('save')
->assertHasNoErrors();
expect($this->job->refresh()->monthly_fee_cents)->toBe(9990);
$this->get(route('jobs.show', $this->job->id))
->assertSee('Kuukausihinta')
->assertSee("99,90\u{00A0}€", false);
$this->actingAs(User::factory()->employee()->create());
$this->get(route('jobs.show', $this->job->id))->assertDontSee('Kuukausihinta');
Livewire::test('jobs::form', ['job' => $this->job->id])->set('form.name', 'Ylläpito')->call('save')->assertHasNoErrors();
expect($this->job->refresh()->monthly_fee_cents)->toBe(9990);
});