F
Filament9mo ago
tuseto

How to test list table search in translatable (via spatie) field with pest

I have the following test:
it('can search page by tistle', function () {
$title = Page::first()->title;

$result = livewire(ListPages::class)
->searchTable($title)
->assertCanSeeTableRecords(Page::where('title->en', $title)->get());
});
it('can search page by tistle', function () {
$title = Page::first()->title;

$result = livewire(ListPages::class)
->searchTable($title)
->assertCanSeeTableRecords(Page::where('title->en', $title)->get());
});
So if the first page title is :
{"en": "asdasdas", "es": "spain"}
{"en": "asdasdas", "es": "spain"}
- the test passes but if it is:
{"bg": "Dolores.", "en": "Aut."}
{"bg": "Dolores.", "en": "Aut."}
- the test fails P.S. locale is EN by default Can you help me what is going on? And how to proper test it?
2 Replies
awcodes
awcodes9mo ago
Try just ‘title’ you shouldn’t have to specify the ->en since spatie package will automatically query the correct language based on locale. You may need to manually set the locale for tests though. Not 100% sure. Unless the test suite is booting up an application.
tuseto
tusetoOP9mo ago
Page::where('title', $title)->get()
Page::where('title', $title)->get()
Does not return any records. If I dump
app()->locale()
app()->locale()
I get 'en'
Want results from more Discord servers?
Add your server