Files
2026-09-21 10:14:57 +01:00

209 lines
6.3 KiB
PHP
Executable File

<?php
declare(strict_types=1);
namespace Modules\Helpdesk\Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Modules\Helpdesk\Livewire\KanbanBoard;
use Modules\Helpdesk\Models\KanbanBoard as KanbanBoardModel;
use Modules\Helpdesk\Tests\Concerns\BuildsHelpdeskFixtures;
use Tests\TestCase;
final class KanbanBoardTest extends TestCase
{
use BuildsHelpdeskFixtures;
use RefreshDatabase;
public function test_helpdesk_kanban_board_page_renders(): void
{
$this->seedLookupData();
$user = $this->user(['name' => 'Kanban Test User']);
$this->actingAs($user)
->get(route('helpdesk.kanban'))
->assertOk();
}
/** @test */
public function kanban_board_renders_visible_tickets_by_status(): void
{
$lookups = $this->seedLookupData();
$user = $this->admin();
$ticket = $this->ticket([
'owner' => $user,
'status_id' => $lookups['open']->id,
'priority_id' => $lookups['high']->id,
'board_id' => $lookups['board']->id,
'subject' => 'Kanban visible ticket',
]);
$this->actingAs($user);
Livewire::test(KanbanBoard::class)
->assertSee('Kanban board')
->assertSee($ticket->reference)
->assertSee('Kanban visible ticket')
->assertSee('High');
}
/** @test */
public function test_ticket_can_be_moved_to_another_board(): void
{
$lookups = $this->seedLookupData();
$user = $this->admin();
$boardA = $lookups['board'];
$boardB = KanbanBoardModel::query()->create([
'name' => 'Regression Target Board',
'slug' => 'regression-target-board',
'is_default' => false,
'sort_order' => 50,
]);
$boardB->statuses()->sync([
$lookups['open']->id => ['sort_order' => 10],
]);
$ticket = $this->ticket([
'owner' => $user,
'status_id' => $lookups['open']->id,
'priority_id' => $lookups['normal']->id,
'board_id' => $boardA->id,
]);
$this->actingAs($user);
Livewire::test(KanbanBoard::class)
->call('moveTicketToBoard', $ticket->id, $boardB->id)
->assertHasNoErrors();
$ticket->refresh();
$this->assertSame($boardB->id, $ticket->board_id);
$this->assertSame($lookups['open']->id, $ticket->status_id);
}
/** @test */
public function kanban_board_can_move_ticket_to_closed_status(): void
{
$lookups = $this->seedLookupData();
$user = $this->admin();
$ticket = $this->ticket([
'owner' => $user,
'status_id' => $lookups['open']->id,
'priority_id' => $lookups['normal']->id,
'board_id' => $lookups['board']->id,
]);
$this->actingAs($user);
Livewire::test(KanbanBoard::class)
->call('moveTicket', $ticket->id, $lookups['closed']->id)
->assertHasNoErrors();
$ticket->refresh();
$this->assertSame($lookups['closed']->id, $ticket->status_id);
$this->assertSame($lookups['board']->id, $ticket->board_id);
$this->assertNotNull($ticket->completed_at);
}
/** @test */
public function kanban_ticket_can_be_moved_to_another_board_and_only_has_one_board(): void
{
$lookups = $this->seedLookupData();
$user = $this->admin();
$targetBoard = KanbanBoardModel::query()->create([
'name' => 'Development Board',
'slug' => 'development-board',
'is_default' => false,
'sort_order' => 20,
]);
$targetBoard->statuses()->sync([$lookups['open']->id => ['sort_order' => 10]]);
$ticket = $this->ticket([
'owner' => $user,
'status_id' => $lookups['open']->id,
'priority_id' => $lookups['normal']->id,
'board_id' => $lookups['board']->id,
]);
$this->actingAs($user);
Livewire::test(KanbanBoard::class)
->call('moveTicketToBoard', $ticket->id, $targetBoard->id)
->assertHasNoErrors();
$ticket->refresh();
$this->assertSame($targetBoard->id, $ticket->board_id);
}
/** @test */
public function kanban_board_filters_tickets_to_the_selected_board_only(): void
{
$lookups = $this->seedLookupData();
$user = $this->admin();
$otherBoard = KanbanBoardModel::query()->create([
'name' => 'Escalation Board',
'slug' => 'escalation-board',
'is_default' => false,
'sort_order' => 30,
]);
$otherBoard->statuses()->sync([$lookups['open']->id => ['sort_order' => 10]]);
$this->ticket([
'owner' => $user,
'status_id' => $lookups['open']->id,
'priority_id' => $lookups['normal']->id,
'board_id' => $lookups['board']->id,
'subject' => 'Default board ticket',
]);
$this->ticket([
'owner' => $user,
'status_id' => $lookups['open']->id,
'priority_id' => $lookups['normal']->id,
'board_id' => $otherBoard->id,
'subject' => 'Escalation board ticket',
]);
$this->actingAs($user);
Livewire::test(KanbanBoard::class)
->set('board_id', $lookups['board']->id)
->assertSee('Default board ticket')
->assertDontSee('Escalation board ticket')
->set('board_id', $otherBoard->id)
->assertSee('Escalation board ticket')
->assertDontSee('Default board ticket');
}
/** @test */
public function kanban_board_increments_refresh_nonce_after_ticket_move(): void
{
$lookups = $this->seedLookupData();
$user = $this->admin();
$ticket = $this->ticket([
'owner' => $user,
'status_id' => $lookups['open']->id,
'priority_id' => $lookups['normal']->id,
'board_id' => $lookups['board']->id,
]);
$this->actingAs($user);
Livewire::test(KanbanBoard::class)
->assertSet('refreshNonce', 0)
->call('moveTicket', $ticket->id, $lookups['closed']->id)
->assertSet('refreshNonce', 1)
->assertHasNoErrors();
}
}