- 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]>
128 lines
5.4 KiB
PHP
128 lines
5.4 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
|
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->employee = User::factory()->create(['name' => 'Eero Työntekijä']);
|
|
$this->actingAs($this->employee);
|
|
$this->customer = CustomerModel::factory()->create(['name' => 'Mainos Oy']);
|
|
$this->unit = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole();
|
|
});
|
|
|
|
it('opens a job with the required fields and the defaults, then clears the form', function () {
|
|
$this->get(route('jobs.quick'))->assertOk()->assertSee('Pikavastaanotto');
|
|
|
|
Livewire::test('jobs::quick')
|
|
->assertSet('form.responsible_user_id', (string) $this->employee->id)
|
|
->call('selectCustomer', $this->customer->id)
|
|
->set('form.name', 'Kevätkampanja')
|
|
->set('form.description', 'Some-mainokset huhtikuulle.')
|
|
->set('form.service_unit_id', (string) $this->unit->id)
|
|
->set('form.status', 'prospect')
|
|
->call('save')
|
|
->assertHasNoErrors()
|
|
->assertSee('Asiakastyö '.now()->year.'-0001 Kevätkampanja luotu.')
|
|
->assertSee('Avaa työ '.now()->year.'-0001')
|
|
->assertSee('Täydennä tietoja')
|
|
->assertSet('form.name', '')
|
|
->assertSet('form.customer_id', '')
|
|
->assertSet('form.status', 'prospect')
|
|
->assertSet('form.responsible_user_id', (string) $this->employee->id);
|
|
|
|
$job = CustomerJobModel::query()->sole();
|
|
|
|
expect($job->status->value)->toBe('prospect')
|
|
->and($job->priority->value)->toBe('normal')
|
|
->and($job->kind->value)->toBe('one_off')
|
|
->and($job->customer_id)->toBe($this->customer->id)
|
|
->and(DB::table('customer_job_service_unit')->where('customer_job_id', $job->id)->pluck('service_unit_id')->all())->toBe([$this->unit->id])
|
|
->and(DB::table('customer_job_changes')->where('customer_job_id', $job->id)->value('field'))->toBe('created');
|
|
});
|
|
|
|
it('adds a new customer during intake', function () {
|
|
Livewire::test('jobs::quick')
|
|
->set('customerSearch', 'Kahvila Kulma')
|
|
->call('createCustomer')
|
|
->assertSee('Asiakas Kahvila Kulma lisätty ja valittu.')
|
|
->set('form.name', 'Ruokalistan kuvaus')
|
|
->set('form.service_unit_id', (string) $this->unit->id)
|
|
->call('save')
|
|
->assertHasNoErrors();
|
|
|
|
expect(CustomerJobModel::query()->sole()->customer_id)
|
|
->toBe(CustomerModel::query()->where('name', 'Kahvila Kulma')->sole()->id);
|
|
});
|
|
|
|
it('shows Finnish errors for missing fields and does not accept other statuses', function () {
|
|
Livewire::test('jobs::quick')
|
|
->set('form.responsible_user_id', '')
|
|
->call('save')
|
|
->assertHasErrors(['form.customer_id', 'form.name', 'form.service_unit_id', 'form.responsible_user_id'])
|
|
->assertSee('Valitse asiakas tai lisää uusi.')
|
|
->assertSee('Valitse palveluyksikkö.');
|
|
|
|
Livewire::test('jobs::quick')
|
|
->call('selectCustomer', $this->customer->id)
|
|
->set('form.name', 'Työ')
|
|
->set('form.service_unit_id', (string) $this->unit->id)
|
|
->set('form.status', 'billed')
|
|
->call('save')
|
|
->assertHasErrors(['form.status']);
|
|
|
|
expect(CustomerJobModel::query()->count())->toBe(0);
|
|
});
|
|
|
|
it('keeps subcontractors out and shows the menu link only to those who may open jobs', function () {
|
|
$this->get(route('jobs.index'))->assertSee('Pikavastaanotto');
|
|
|
|
$this->actingAs(User::factory()->subcontractor()->create());
|
|
|
|
$this->get(route('jobs.quick'))->assertForbidden();
|
|
$this->get(route('jobs.index'))->assertDontSee('Pikavastaanotto');
|
|
});
|
|
|
|
it('opens a job from the board\'s dialog with a new contact person, status and priority', function () {
|
|
Livewire::test('jobs::quick', ['inDialog' => true])
|
|
->call('selectCustomer', $this->customer->id)
|
|
->set('form.adding_contact', true)
|
|
->set('form.name', 'Pakettiauton kylkiteippaukset')
|
|
->set('form.service_unit_id', (string) $this->unit->id)
|
|
->call('save')
|
|
->assertHasErrors('form.new_contact_name')
|
|
->set('form.new_contact_name', 'Ville Virtanen')
|
|
->set('form.new_contact_phone', '040 123 4567')
|
|
->set('form.status', 'in_production')
|
|
->set('form.priority', 'urgent')
|
|
->call('save')
|
|
->assertHasNoErrors()
|
|
->assertDispatched('quick-job-created', status: 'in_production')
|
|
->assertDispatched('job-editor-saved');
|
|
|
|
$job = CustomerJobModel::query()->sole();
|
|
$contactId = DB::table('customer_contacts')->where('customer_id', $this->customer->id)->where('name', 'Ville Virtanen')->value('id');
|
|
|
|
expect($job->status->value)->toBe('in_production')
|
|
->and($job->priority->value)->toBe('urgent')
|
|
->and($job->customer_contact_id)->toBe($contactId);
|
|
});
|
|
|
|
it('refuses initial statuses past production', function () {
|
|
Livewire::test('jobs::quick')
|
|
->call('selectCustomer', $this->customer->id)
|
|
->set('form.name', 'Valmis jo')
|
|
->set('form.service_unit_id', (string) $this->unit->id)
|
|
->set('form.status', 'done')
|
|
->call('save')
|
|
->assertHasErrors('form.status');
|
|
|
|
expect(CustomerJobModel::query()->count())->toBe(0);
|
|
});
|