From 793cad7d5e30baec10c923e1098a0bf9492cd7d3 Mon Sep 17 00:00:00 2001 From: Sebastiaan Kloos Date: Wed, 26 Nov 2025 14:47:18 +0100 Subject: [PATCH 1/5] Add currentProjectId property to Header Livewire component MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds a new public property to store the current project ID, which will be used to pre-fill the project field when creating items from within a project context. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/Livewire/Header.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Livewire/Header.php b/app/Livewire/Header.php index f4da2828..f849e850 100644 --- a/app/Livewire/Header.php +++ b/app/Livewire/Header.php @@ -29,6 +29,7 @@ class Header extends Component implements HasForms, HasActions public $logo; public $projects; public $similarItems = []; + public $currentProjectId = null; public function mount() { @@ -100,7 +101,9 @@ public function submitItemAction(): Action ->modalIcon('heroicon-o-plus-circle') ->modalWidth('3xl') ->modalSubmitActionLabel('Confirm') - ->fillForm([]) + ->fillForm(function () { + return $this->currentProjectId ? ['project_id' => $this->currentProjectId] : []; + }) ->schema(function () { $inputs = []; From ac24165c5190c7aa8944a46d4e935bd20cb7ae68 Mon Sep 17 00:00:00 2001 From: Sebastiaan Kloos Date: Wed, 26 Nov 2025 14:47:34 +0100 Subject: [PATCH 2/5] Accept and store currentProjectId in App component MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates the App component to accept a currentProjectId parameter in its constructor and store it as a property. This enables the component to pass project context down to child components. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/View/Components/App.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/View/Components/App.php b/app/View/Components/App.php index 1644107f..1c6c00e3 100644 --- a/app/View/Components/App.php +++ b/app/View/Components/App.php @@ -21,9 +21,12 @@ class App extends Component public array $fontFamily; public bool $blockRobots = false; public bool $userNeedsToVerify = false; + public ?int $currentProjectId = null; - public function __construct(public array $breadcrumbs = []) + public function __construct(public array $breadcrumbs = [], ?int $currentProjectId = null) { + $this->currentProjectId = $currentProjectId; + $this->projects = Project::query() ->visibleForCurrentUser() ->when(app(GeneralSettings::class)->show_projects_sidebar_without_boards === false, function ($query) { From 6fdc560253a1c38466e2b9c0711487a8f6d64d8f Mon Sep 17 00:00:00 2001 From: Sebastiaan Kloos Date: Wed, 26 Nov 2025 14:47:41 +0100 Subject: [PATCH 3/5] Pass currentProjectId to Header component in layout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates the app layout to pass the currentProjectId property to the Header Livewire component, enabling it to pre-fill the project field when creating items. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- resources/views/components/app.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/components/app.blade.php b/resources/views/components/app.blade.php index 9ed93673..2e44aadb 100644 --- a/resources/views/components/app.blade.php +++ b/resources/views/components/app.blade.php @@ -60,7 +60,7 @@ function updateTheme() { @endif - +
@include('partials.navbar') From fa9cea95744b9422fa58bfa1fc66b9c481811bcc Mon Sep 17 00:00:00 2001 From: Sebastiaan Kloos Date: Wed, 26 Nov 2025 14:47:49 +0100 Subject: [PATCH 4/5] Pass project ID to App component in project and board views MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updates both the project and board views to pass the current project ID to the App component. This ensures that when users create items from within a project context, the project field is automatically pre-filled with the current project. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- resources/views/board.blade.php | 2 +- resources/views/project.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/board.blade.php b/resources/views/board.blade.php index b2ccaa35..64fecfcf 100644 --- a/resources/views/board.blade.php +++ b/resources/views/board.blade.php @@ -6,7 +6,7 @@ +]" :current-project-id="$project->id">
diff --git a/resources/views/project.blade.php b/resources/views/project.blade.php index 7232de5d..71f1dad6 100644 --- a/resources/views/project.blade.php +++ b/resources/views/project.blade.php @@ -5,7 +5,7 @@ +]" :current-project-id="$project->id">
Date: Wed, 26 Nov 2025 14:47:57 +0100 Subject: [PATCH 5/5] Add comprehensive tests for Header component project pre-fill functionality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a complete test suite for the Header Livewire component covering: - Basic component rendering - Project pre-fill when currentProjectId is set - No pre-fill when currentProjectId is null - Guest user login notifications - User can create items with pre-filled project - User can override pre-filled project - Project field visibility based on settings - Project field requirement validation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- tests/Feature/Livewire/HeaderTest.php | 179 ++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 tests/Feature/Livewire/HeaderTest.php diff --git a/tests/Feature/Livewire/HeaderTest.php b/tests/Feature/Livewire/HeaderTest.php new file mode 100644 index 00000000..f6cbcd9a --- /dev/null +++ b/tests/Feature/Livewire/HeaderTest.php @@ -0,0 +1,179 @@ + true, + 'select_board_when_creating_item' => true, + 'project_required_when_creating_item' => false, + 'board_required_when_creating_item' => false, + 'users_must_verify_email' => false, + ]); +}); + +test('header component renders successfully', function () { + $user = createAndLoginUser(); + + Livewire::test(Header::class) + ->assertStatus(200); +}); + +test('submit item action pre-fills project when currentProjectId is set', function () { + $user = createAndLoginUser(); + $project = Project::factory()->create(); + + // When we create an item with currentProjectId set, and we don't override the project_id, + // it should use the pre-filled project_id + Livewire::test(Header::class, ['currentProjectId' => $project->id]) + ->callAction('submitItem', data: [ + 'title' => 'Test Feature with Pre-fill', + 'content' => 'This should use the pre-filled project.', + // Not explicitly providing project_id - should use pre-filled value + ]) + ->assertHasNoFormErrors(); + + // The item should be created with the pre-filled project + $this->assertDatabaseHas('items', [ + 'title' => 'Test Feature with Pre-fill', + 'project_id' => $project->id, + 'user_id' => $user->id, + ]); +}); + +test('submit item action does not pre-fill project when currentProjectId is null', function () { + $user = createAndLoginUser(); + + $component = Livewire::test(Header::class, ['currentProjectId' => null]); + + // Mount the action + $component->mountAction('submitItem'); + + // Assert that the project_id is not set (or is null) + $component->assertFormSet([ + 'project_id' => null, + ]); +}); + +test('submit item action shows login notification for guest users', function () { + // Test without logging in + Livewire::test(Header::class) + ->callAction('submitItem') + ->assertNotified(); +}); + +test('user can create item with pre-filled project', function () { + $user = createAndLoginUser(); + $project = Project::factory()->create(); + + Livewire::test(Header::class, ['currentProjectId' => $project->id]) + ->callAction('submitItem', data: [ + 'title' => 'Test Feature Request', + 'content' => 'This is a test content for the feature request.', + 'project_id' => $project->id, + ]) + ->assertHasNoFormErrors(); + + $this->assertDatabaseHas('items', [ + 'title' => 'Test Feature Request', + 'content' => 'This is a test content for the feature request.', + 'project_id' => $project->id, + 'user_id' => $user->id, + ]); +}); + +test('user can override pre-filled project with different project', function () { + $user = createAndLoginUser(); + $project1 = Project::factory()->create(); + $project2 = Project::factory()->create(); + + Livewire::test(Header::class, ['currentProjectId' => $project1->id]) + ->callAction('submitItem', data: [ + 'title' => 'Test Feature Request', + 'content' => 'This is a test content for the feature request.', + 'project_id' => $project2->id, // Override with different project + ]) + ->assertHasNoFormErrors(); + + // Assert that the item was created with project2, not project1 + $this->assertDatabaseHas('items', [ + 'title' => 'Test Feature Request', + 'project_id' => $project2->id, + 'user_id' => $user->id, + ]); + + $this->assertDatabaseMissing('items', [ + 'title' => 'Test Feature Request', + 'project_id' => $project1->id, + ]); +}); + +test('project field is shown when select_project_when_creating_item setting is enabled', function () { + GeneralSettings::fake([ + 'select_project_when_creating_item' => true, + ]); + + $user = createAndLoginUser(); + + $component = Livewire::test(Header::class); + + $component->mountAction('submitItem'); + + // Assert that the form has the project_id field + $component->assertFormFieldExists('project_id'); +}); + +test('project field is hidden when select_project_when_creating_item setting is disabled', function () { + GeneralSettings::fake([ + 'select_project_when_creating_item' => false, + ]); + + $user = createAndLoginUser(); + + $component = Livewire::test(Header::class); + + $component->mountAction('submitItem'); + + // Assert that the form does not have the project_id field + $component->assertFormFieldDoesNotExist('project_id'); +}); + +test('project field is required when project_required_when_creating_item is true', function () { + GeneralSettings::fake([ + 'select_project_when_creating_item' => true, + 'project_required_when_creating_item' => true, + ]); + + $user = createAndLoginUser(); + + Livewire::test(Header::class) + ->callAction('submitItem', data: [ + 'title' => 'Test Feature Request', + 'content' => 'This is a test content for the feature request.', + // Intentionally not providing project_id + ]) + ->assertHasFormErrors(['project_id']); +}); + +test('project field is optional when project_required_when_creating_item is false', function () { + GeneralSettings::fake([ + 'select_project_when_creating_item' => true, + 'project_required_when_creating_item' => false, + ]); + + $user = createAndLoginUser(); + + Livewire::test(Header::class) + ->callAction('submitItem', data: [ + 'title' => 'Test Feature Request', + 'content' => 'This is a test content for the feature request.', + // Not providing project_id - should be valid + ]) + ->assertHasNoFormErrors(); +});