generated from filamentphp/plugin-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 44
fix: support standalone Filament usage without panel dependency #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
96d4aa3
fix: support standalone Filament usage without panel dependency
ManukMinasyan ca011c6
test: add standalone board tests without Filament panel
ManukMinasyan 8897177
Fix styling
ManukMinasyan 3f0375d
refactor: apply code review fixes
ManukMinasyan e95b899
test: add missing assertDispatched in between-cards movement test
ManukMinasyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Relaticle\Flowforge\Tests\Fixtures; | ||
|
|
||
| use Filament\Actions\Concerns\InteractsWithActions; | ||
| use Filament\Actions\Contracts\HasActions; | ||
| use Filament\Forms\Concerns\InteractsWithForms; | ||
| use Filament\Forms\Contracts\HasForms; | ||
| use Livewire\Component; | ||
| use Relaticle\Flowforge\Board; | ||
| use Relaticle\Flowforge\Column; | ||
| use Relaticle\Flowforge\Concerns\InteractsWithBoard; | ||
| use Relaticle\Flowforge\Contracts\HasBoard; | ||
|
|
||
| /** | ||
| * Standalone Livewire component for testing without Filament Panel. | ||
| */ | ||
| class TestStandaloneBoard extends Component implements HasActions, HasBoard, HasForms | ||
| { | ||
| use InteractsWithActions; | ||
| use InteractsWithBoard { | ||
| InteractsWithBoard::getDefaultActionRecord insteadof InteractsWithActions; | ||
| } | ||
| use InteractsWithForms; | ||
|
|
||
| public function board(Board $board): Board | ||
| { | ||
| return $board | ||
| ->query(Task::query()) | ||
| ->recordTitleAttribute('title') | ||
| ->columnIdentifier('status') | ||
| ->positionIdentifier('order_position') | ||
| ->columns([ | ||
| Column::make('todo')->label('To Do')->color('gray'), | ||
| Column::make('in_progress')->label('In Progress')->color('blue'), | ||
| Column::make('completed')->label('Completed')->color('green'), | ||
| ]); | ||
| } | ||
|
|
||
| public function render() | ||
| { | ||
| return <<<'BLADE' | ||
| <div> | ||
| {{ $this->board }} | ||
| </div> | ||
| BLADE; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <?php | ||
|
|
||
| use Relaticle\Flowforge\Tests\StandaloneTestCase; | ||
| use Relaticle\Flowforge\Tests\TestCase; | ||
|
|
||
| pest()->extends(TestCase::class)->in(__DIR__); | ||
| pest()->extends(TestCase::class)->in('Feature', 'Unit'); | ||
| pest()->extends(StandaloneTestCase::class)->in('Standalone'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Livewire\Livewire; | ||
| use Relaticle\Flowforge\Services\DecimalPosition; | ||
| use Relaticle\Flowforge\Tests\Fixtures\Task; | ||
| use Relaticle\Flowforge\Tests\Fixtures\TestStandaloneBoard; | ||
|
|
||
| /** | ||
| * @see https://github.com/relaticle/flowforge/issues/84 | ||
| */ | ||
| describe('standalone board rendering', function () { | ||
| test('renders board with all columns', function () { | ||
| Livewire::test(TestStandaloneBoard::class) | ||
| ->assertStatus(200) | ||
| ->assertSee('To Do') | ||
| ->assertSee('In Progress') | ||
| ->assertSee('Completed'); | ||
| }); | ||
|
|
||
| test('displays cards in correct columns', function () { | ||
| Task::factory()->todo()->create(['title' => 'Standalone Todo']); | ||
| Task::factory()->inProgress()->create(['title' => 'Standalone In Progress']); | ||
| Task::factory()->completed()->create(['title' => 'Standalone Completed']); | ||
|
|
||
| Livewire::test(TestStandaloneBoard::class) | ||
| ->assertSee('Standalone Todo') | ||
| ->assertSee('Standalone In Progress') | ||
| ->assertSee('Standalone Completed'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('standalone card movement', function () { | ||
| test('moves card to different column', function () { | ||
| $task = Task::factory()->todo()->withPosition('65535.0000000000')->create(); | ||
|
|
||
| Livewire::test(TestStandaloneBoard::class) | ||
| ->call('moveCard', (string) $task->id, 'in_progress', null, null) | ||
| ->assertDispatched('kanban-card-moved'); | ||
|
|
||
| expect($task->fresh()->status)->toBe('in_progress'); | ||
| }); | ||
|
|
||
| test('moves card between two cards', function () { | ||
| $task1 = Task::factory()->inProgress()->withPosition('65535.0000000000')->create(); | ||
| $task2 = Task::factory()->inProgress()->withPosition('131070.0000000000')->create(); | ||
| $taskToMove = Task::factory()->todo()->withPosition('65535.0000000000')->create(); | ||
|
|
||
| Livewire::test(TestStandaloneBoard::class) | ||
| ->call('moveCard', (string) $taskToMove->id, 'in_progress', (string) $task1->id, (string) $task2->id) | ||
| ->assertDispatched('kanban-card-moved'); | ||
|
|
||
| $movedTask = $taskToMove->fresh(); | ||
| expect($movedTask->status)->toBe('in_progress') | ||
| ->and((float) $movedTask->order_position)->toBeGreaterThan(65535) | ||
| ->and((float) $movedTask->order_position)->toBeLessThan(131070); | ||
| }); | ||
|
|
||
| test('moves card to empty column', function () { | ||
| $task = Task::factory()->todo()->withPosition('65535.0000000000')->create(); | ||
|
|
||
| Livewire::test(TestStandaloneBoard::class) | ||
| ->call('moveCard', (string) $task->id, 'completed', null, null) | ||
| ->assertDispatched('kanban-card-moved'); | ||
|
|
||
| $movedTask = $task->fresh(); | ||
| expect($movedTask->status)->toBe('completed') | ||
| ->and((float) $movedTask->order_position)->toBe((float) DecimalPosition::DEFAULT_GAP); | ||
| }); | ||
| }); | ||
|
|
||
| describe('standalone pagination', function () { | ||
| test('loads more items on demand', function () { | ||
| Task::factory(30)->todo()->create(); | ||
|
|
||
| Livewire::test(TestStandaloneBoard::class) | ||
| ->call('loadMoreItems', 'todo', 20) | ||
| ->assertDispatched('kanban-items-loaded'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Relaticle\Flowforge\Tests; | ||
|
|
||
| use BladeUI\Heroicons\BladeHeroiconsServiceProvider; | ||
| use BladeUI\Icons\BladeIconsServiceProvider; | ||
| use Filament\Actions\ActionsServiceProvider; | ||
| use Filament\FilamentManager; | ||
| use Filament\Forms\FormsServiceProvider; | ||
| use Filament\Infolists\InfolistsServiceProvider; | ||
| use Filament\Notifications\NotificationsServiceProvider; | ||
| use Filament\Support\SupportServiceProvider; | ||
| use Filament\Tables\TablesServiceProvider; | ||
| use Illuminate\Database\Eloquent\Factories\Factory; | ||
| use Illuminate\Foundation\Testing\LazilyRefreshDatabase; | ||
| use Livewire\LivewireServiceProvider; | ||
| use Orchestra\Testbench\Concerns\WithWorkbench; | ||
| use Orchestra\Testbench\TestCase as Orchestra; | ||
| use Relaticle\Flowforge\FlowforgeServiceProvider; | ||
| use RyanChandler\BladeCaptureDirective\BladeCaptureDirectiveServiceProvider; | ||
|
|
||
| /** | ||
| * Test case for standalone Livewire usage WITHOUT the Filament Panel Builder. | ||
| * | ||
| * Excludes FilamentServiceProvider and TestPanelProvider to verify the package | ||
| * works without a panel registered. | ||
| * | ||
| * Note: In a real standalone install (without filament/filament), the Filament | ||
| * facade class won't exist and class_exists() guards in filament/tables skip | ||
| * panel-dependent calls entirely. In our test environment, filament/filament IS | ||
| * installed as a dev dependency, so we register a minimal FilamentManager binding | ||
| * to satisfy those guards without configuring any panel. | ||
| */ | ||
| class StandaloneTestCase extends Orchestra | ||
| { | ||
| use LazilyRefreshDatabase; | ||
| use WithWorkbench; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| Factory::guessFactoryNamesUsing( | ||
| fn (string $modelName) => 'Relaticle\\Flowforge\\Database\\Factories\\' . class_basename($modelName) . 'Factory' | ||
| ); | ||
|
|
||
| // Register minimal FilamentManager binding. This is only needed because | ||
| // filament/filament is a dev dependency (for panel tests), making the | ||
| // Filament facade class available. The tables package's HasFilters trait | ||
| // uses class_exists(Filament::class) to guard tenant-aware session keys, | ||
| // which passes in our test env but would be false in a real standalone install. | ||
| if (! $this->app->bound('filament')) { | ||
| $this->app->scoped('filament', fn () => new FilamentManager); | ||
| } | ||
| } | ||
|
|
||
| protected function getPackageProviders($app): array | ||
| { | ||
| $providers = [ | ||
| ActionsServiceProvider::class, | ||
| BladeCaptureDirectiveServiceProvider::class, | ||
| BladeHeroiconsServiceProvider::class, | ||
| BladeIconsServiceProvider::class, | ||
| FormsServiceProvider::class, | ||
| InfolistsServiceProvider::class, | ||
| LivewireServiceProvider::class, | ||
| NotificationsServiceProvider::class, | ||
| SupportServiceProvider::class, | ||
| TablesServiceProvider::class, | ||
| FlowforgeServiceProvider::class, | ||
| ]; | ||
|
|
||
| sort($providers); | ||
|
|
||
| return $providers; | ||
| } | ||
|
|
||
| protected function defineEnvironment($app): void | ||
| { | ||
| config()->set('database.default', 'testing'); | ||
| config()->set('database.connections.testing', [ | ||
| 'driver' => 'sqlite', | ||
| 'database' => ':memory:', | ||
| 'prefix' => '', | ||
| ]); | ||
|
|
||
| config()->set('app.key', 'base64:' . base64_encode(random_bytes(32))); | ||
| config()->set('session.driver', 'array'); | ||
| config()->set('session.encrypt', false); | ||
|
|
||
| config()->set('view.paths', [ | ||
| resource_path('views'), | ||
| __DIR__ . '/../resources/views', | ||
| ]); | ||
| } | ||
|
|
||
| protected function defineDatabaseMigrations(): void | ||
| { | ||
| $this->loadMigrationsFrom(__DIR__ . '/database/migrations'); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.