Implement board columns and project workflow settings
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use App\Models\BoardColumn;
|
||||
use App\Models\Project;
|
||||
use Database\Seeders\BoardColumnSeeder;
|
||||
use Database\Seeders\ProjectSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BoardColumnTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Ensure the board column factory creates a position and related project.
|
||||
*/
|
||||
public function test_board_column_factory_creates_expected_defaults(): void
|
||||
{
|
||||
$boardColumn = BoardColumn::factory()->create();
|
||||
|
||||
$this->assertNotNull($boardColumn->project);
|
||||
$this->assertSame(1, $boardColumn->position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure projects expose board columns ordered by position.
|
||||
*/
|
||||
public function test_project_board_columns_are_returned_in_position_order(): void
|
||||
{
|
||||
$project = Project::factory()->create();
|
||||
|
||||
BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Done',
|
||||
'position' => 3,
|
||||
]);
|
||||
BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'In Progress',
|
||||
'position' => 2,
|
||||
]);
|
||||
|
||||
$this->assertSame(
|
||||
['Todo', 'In Progress', 'Done'],
|
||||
$project->fresh()->boardColumns->pluck('name')->all(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the board column seeder creates starter workflow columns for seeded projects.
|
||||
*/
|
||||
public function test_board_column_seeder_creates_default_columns_for_projects(): void
|
||||
{
|
||||
$this->seed([
|
||||
ProjectSeeder::class,
|
||||
BoardColumnSeeder::class,
|
||||
]);
|
||||
|
||||
$coreProject = Project::query()->where('key', 'CORE')->firstOrFail();
|
||||
|
||||
$this->assertDatabaseHas('board_columns', [
|
||||
'project_id' => $coreProject->id,
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('board_columns', [
|
||||
'project_id' => $coreProject->id,
|
||||
'name' => 'In Progress',
|
||||
'position' => 2,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('board_columns', [
|
||||
'project_id' => $coreProject->id,
|
||||
'name' => 'Done',
|
||||
'position' => 3,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use App\Models\BoardColumn;
|
||||
use App\Models\Project;
|
||||
use Database\Seeders\BoardColumnSeeder;
|
||||
use Database\Seeders\ProjectSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
@@ -45,4 +47,49 @@ class ProjectTest extends TestCase
|
||||
'key' => 'OPS',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure projects expose their board columns in the configured order.
|
||||
*/
|
||||
public function test_projects_have_an_ordered_board_columns_relationship(): void
|
||||
{
|
||||
$project = Project::factory()->create();
|
||||
|
||||
BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Done',
|
||||
'position' => 3,
|
||||
]);
|
||||
BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'In Progress',
|
||||
'position' => 2,
|
||||
]);
|
||||
|
||||
$this->assertSame(
|
||||
['Todo', 'In Progress', 'Done'],
|
||||
$project->fresh()->boardColumns->pluck('name')->all(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the default database seeding can include project board columns.
|
||||
*/
|
||||
public function test_board_column_seeder_adds_columns_to_seeded_projects(): void
|
||||
{
|
||||
$this->seed([
|
||||
ProjectSeeder::class,
|
||||
BoardColumnSeeder::class,
|
||||
]);
|
||||
|
||||
$coreProject = Project::query()->where('key', 'CORE')->firstOrFail();
|
||||
|
||||
$this->assertDatabaseHas('board_columns', [
|
||||
'project_id' => $coreProject->id,
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Projects;
|
||||
|
||||
use App\Actions\ProjectPermissions\ProjectPermissionService;
|
||||
use App\Models\BoardColumn;
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ProjectBoardSettingsControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Ensure users with edit permission can view board settings.
|
||||
*/
|
||||
public function test_users_with_edit_permission_can_view_board_settings(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create([
|
||||
'key' => 'CORE',
|
||||
]);
|
||||
BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
|
||||
app(ProjectPermissionService::class)->syncUserPermissions($project, $user, ['edit']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('projects.settings.board', $project))
|
||||
->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('projects/settings/Board')
|
||||
->where('project.id', $project->id)
|
||||
->where('boardColumns.0.name', 'Todo'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure users without edit permission cannot view board settings.
|
||||
*/
|
||||
public function test_users_without_edit_permission_cannot_view_board_settings(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('projects.settings.board', $project))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure authorized users can create board columns.
|
||||
*/
|
||||
public function test_users_with_edit_permission_can_create_board_columns(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create([
|
||||
'key' => 'CORE',
|
||||
]);
|
||||
|
||||
app(ProjectPermissionService::class)->syncUserPermissions($project, $user, ['edit']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->post(route('projects.settings.board.columns.store', $project), [
|
||||
'name' => 'In Review',
|
||||
])
|
||||
->assertRedirect(route('projects.settings.board', $project))
|
||||
->assertSessionHas('status', 'In Review was added to the board workflow.');
|
||||
|
||||
$this->assertDatabaseHas('board_columns', [
|
||||
'project_id' => $project->id,
|
||||
'name' => 'In Review',
|
||||
'position' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure authorized users can rename and reorder board columns.
|
||||
*/
|
||||
public function test_users_with_edit_permission_can_update_and_reorder_board_columns(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create();
|
||||
$firstColumn = BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
$secondColumn = BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'In Progress',
|
||||
'position' => 2,
|
||||
]);
|
||||
$thirdColumn = BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Done',
|
||||
'position' => 3,
|
||||
]);
|
||||
|
||||
app(ProjectPermissionService::class)->syncUserPermissions($project, $user, ['edit']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->patch(route('projects.settings.board.columns.update', [$project, $thirdColumn]), [
|
||||
'name' => 'Ready for QA',
|
||||
'position' => 1,
|
||||
])
|
||||
->assertRedirect(route('projects.settings.board', $project))
|
||||
->assertSessionHas('status', 'Ready for QA was updated.');
|
||||
|
||||
$firstColumn->refresh();
|
||||
$secondColumn->refresh();
|
||||
$thirdColumn->refresh();
|
||||
|
||||
$this->assertSame(2, $firstColumn->position);
|
||||
$this->assertSame(3, $secondColumn->position);
|
||||
$this->assertSame(1, $thirdColumn->position);
|
||||
$this->assertSame('Ready for QA', $thirdColumn->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure deleting a column normalizes the remaining order.
|
||||
*/
|
||||
public function test_deleting_a_board_column_normalizes_remaining_positions(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create();
|
||||
$firstColumn = BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Todo',
|
||||
'position' => 1,
|
||||
]);
|
||||
$secondColumn = BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'In Progress',
|
||||
'position' => 2,
|
||||
]);
|
||||
$thirdColumn = BoardColumn::factory()->for($project)->create([
|
||||
'name' => 'Done',
|
||||
'position' => 3,
|
||||
]);
|
||||
|
||||
app(ProjectPermissionService::class)->syncUserPermissions($project, $user, ['edit']);
|
||||
|
||||
$this->actingAs($user)
|
||||
->delete(route('projects.settings.board.columns.destroy', [$project, $secondColumn]))
|
||||
->assertRedirect(route('projects.settings.board', $project))
|
||||
->assertSessionHas('status', 'In Progress was removed from the board workflow.');
|
||||
|
||||
$firstColumn->refresh();
|
||||
$thirdColumn->refresh();
|
||||
|
||||
$this->assertSame(1, $firstColumn->position);
|
||||
$this->assertSame(2, $thirdColumn->position);
|
||||
$this->assertDatabaseMissing('board_columns', [
|
||||
'id' => $secondColumn->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user