- Introduced `testing-schemas.md` with detailed instructions on filling forms, asserting schema states, validating forms, and testing visibility and existence of form fields and components. - Added `testing-tables.md` covering table rendering, column testing, searching, sorting, filtering, and summarizing, along with visibility and existence checks for filters and columns.
88 lines
2.0 KiB
Markdown
88 lines
2.0 KiB
Markdown
# Testing Notifications
|
|
|
|
## Testing Session Notifications
|
|
|
|
To check if a notification was sent using the session, use the `assertNotified()` helper:
|
|
|
|
```php
|
|
use function Pest\Livewire\livewire;
|
|
|
|
it('sends a notification', function () {
|
|
livewire(CreatePost::class)
|
|
->assertNotified();
|
|
});
|
|
```
|
|
|
|
```php
|
|
use Filament\Notifications\Notification;
|
|
|
|
it('sends a notification', function () {
|
|
Notification::assertNotified();
|
|
});
|
|
```
|
|
|
|
```php
|
|
use function Filament\Notifications\Testing\assertNotified;
|
|
|
|
it('sends a notification', function () {
|
|
assertNotified();
|
|
});
|
|
```
|
|
|
|
You may optionally pass a notification title to test for:
|
|
|
|
```php
|
|
use Filament\Notifications\Notification;
|
|
use function Pest\Livewire\livewire;
|
|
|
|
it('sends a notification', function () {
|
|
livewire(CreatePost::class)
|
|
->assertNotified('Unable to create post');
|
|
});
|
|
```
|
|
|
|
Or test if the exact notification was sent:
|
|
|
|
```php
|
|
use Filament\Notifications\Notification;
|
|
use function Pest\Livewire\livewire;
|
|
|
|
it('sends a notification', function () {
|
|
livewire(CreatePost::class)
|
|
->assertNotified(
|
|
Notification::make()
|
|
->danger()
|
|
->title('Unable to create post')
|
|
->body('Something went wrong.'),
|
|
);
|
|
});
|
|
```
|
|
|
|
Conversely, you can assert that a notification was not sent:
|
|
|
|
```php
|
|
use Filament\Notifications\Notification;
|
|
use function Pest\Livewire\livewire;
|
|
|
|
it('does not send a notification', function () {
|
|
livewire(CreatePost::class)
|
|
->assertNotNotified()
|
|
// or
|
|
->assertNotNotified('Unable to create post')
|
|
// or
|
|
->assertNotNotified(
|
|
Notification::make()
|
|
->danger()
|
|
->title('Unable to create post')
|
|
->body('Something went wrong.'),
|
|
);
|
|
});
|
|
```
|
|
// or
|
|
->assertNotNotified(
|
|
Notification::make()
|
|
->danger()
|
|
->title('Unable to create post')
|
|
->body('Something went wrong.'),
|
|
);
|