|
1 | 1 | ## Filament |
2 | 2 | - Filament is used for functionality within this project, check how and where to follow existing project conventions. |
3 | 3 | - Filament is a Server-Driven UI (SDUI) framework for Laravel. It allows developers to define user interfaces in PHP using structured configuration objects. It is built on top of Livewire, Alpine.js, and Tailwind CSS. |
4 | | -- It is often used to build admin panels, dashboards, and form-based apps. |
5 | | -- You can use the `search-docs` tool to get information from the official documentation when needed. This is very useful for artisan command arguments, specific code examples, and ensuring you're following idiomatic practices. |
| 4 | +- You can use the `search-docs` tool to get information from the official documentation when needed. This is very useful for artisan command arguments, specific code examples, testing functionality, relationship management, and ensuring you're following idiomatic practices. |
6 | 5 |
|
7 | 6 | ## Artisan |
8 | | -- You must use the Filament specific artisan commands to create Filament classes and components. You can find these with the `list-artisan-commands` tool. |
| 7 | +- You must use the Filament specific artisan commands to create new files or components for Filament. You can find these with the `list-artisan-commands` tool, or with `php artisan` and the `--help` option. |
| 8 | +- Inspect the required options, always pass `--no-interaction`, and other options with valid arguments. |
9 | 9 |
|
10 | 10 | ## Filament's Core Features |
11 | 11 | - Panels: The top-level container in Filament that can include all other features like pages, resources, forms, tables, notifications, actions, infolists, and widgets. |
|
17 | 17 | - Actions: Handle doing something within the app, often with a button or link. Actions encapsulate the UI, the interactive modal window, and the logic that should be executed when the modal window is submitted. They can be used anywhere in the UI and are commonly used to perform one-time actions like deleting a record, sending an email, or updating data in the database based on modal form input. |
18 | 18 | - Notifications: Flash notifications to users within the app. |
19 | 19 | - Widgets: Small component included within dashboards, often used for displaying data in charts, tables, or as a stat. |
| 20 | + |
| 21 | +## Testing |
| 22 | +- It's important to test Filament functionality for user satisfaction. |
| 23 | +- Ensure that you are authenticated to access the app within the test. |
| 24 | +- Filament uses Livewire so start assertions with `livewire()` or `Livewire::test()`. |
| 25 | + |
| 26 | +### Example tests |
| 27 | +@verbatim |
| 28 | +<code-snippet name="Filament table test" lang="php"> |
| 29 | + livewire(ListUsers::class) |
| 30 | + ->assertCanSeeTableRecords($users) |
| 31 | + ->searchTable($users->first()->name) |
| 32 | + ->assertCanSeeTableRecords($users->take(1)) |
| 33 | + ->assertCanNotSeeTableRecords($users->skip(1)) |
| 34 | + ->searchTable($users->last()->email) |
| 35 | + ->assertCanSeeTableRecords($users->take(-1)) |
| 36 | + ->assertCanNotSeeTableRecords($users->take($users->count() - 1)); |
| 37 | +</code-snippet> |
| 38 | + |
| 39 | +<code-snippet name="Filament create resource test" lang="php"> |
| 40 | + livewire(CreateUser::class) |
| 41 | + ->fillForm([ |
| 42 | + 'name' => 'Howdy', |
| 43 | + |
| 44 | + ]) |
| 45 | + ->call('create') |
| 46 | + ->assertNotified() |
| 47 | + ->assertRedirect(); |
| 48 | + |
| 49 | + assertDatabaseHas(User::class, [ |
| 50 | + 'name' => 'Howdy', |
| 51 | + |
| 52 | + ]); |
| 53 | +</code-snippet> |
| 54 | + |
| 55 | +<code-snippet name="Testing multiple panels (setup())" lang="php"> |
| 56 | + use Filament\Facades\Filament; |
| 57 | + Filament::setCurrentPanel('app'); |
| 58 | +</code-snippet> |
| 59 | + |
| 60 | +<code-snippet name="Calling an action in a test" lang="php"> |
| 61 | + livewire(EditInvoice::class, [ |
| 62 | + 'invoice' => $invoice, |
| 63 | + ])->callAction('send'); |
| 64 | + expect($invoice->refresh())->isSent()->toBeTrue(); |
| 65 | +</code-snippet> |
| 66 | +@endverbatim |
| 67 | + |
| 68 | +## Relationships |
| 69 | +- Check if you can use the `relationship()` method on form components when needing `options` for a select, checkbox, repeater, or when building a Fieldset: |
| 70 | +@verbatim |
| 71 | +<code-snippet name="Relationship example for Form Select" lang="php"> |
| 72 | +Forms\Components\Select::make('user_id') |
| 73 | + ->label('Author') |
| 74 | + ->relationship('author') |
| 75 | + ->required(), |
| 76 | +</code-snippet> |
| 77 | +@endverbatim |
0 commit comments