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('mine', false)->call('moveJob', $this->job->id, 'done'); $completedAt = $this->job->refresh()->completed_at; expect($completedAt)->not->toBeNull(); Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, '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('mine', false)->call('moveJob', $this->job->id, 'in_production'); expect($this->job->refresh()->completed_at)->toBeNull(); });