es` off the record * as a property. See App\Filament\Support\TranslatedOptionLabel. */ class TranslatedRelationshipSelectsTest extends TestCase { use FakesPireon, RefreshDatabase; protected function setUp(): void { parent::setUp(); $this->seed(RolePermissionSeeder::class); Queue::fake(); $this->actingAs($this->userWithRoles('super_admin')); } /** * @return array */ public static function selects(): array { return [ "a page's category" => [CreatePage::class, 'category_id', Category::class], "a call's project" => [CreateCall::class, 'project_id', Project::class], "a testimonial's project" => [CreateTestimonial::class, 'project_id', Project::class], "a testimonial's service" => [CreateTestimonial::class, 'service_id', Service::class], "a talk's project" => [CreateTalk::class, 'project_id', Project::class], "a repository's project" => [CreateRepository::class, 'project_id', Project::class], ]; } /** * @param class-string $page * @param class-string $model */ #[Test] #[DataProvider('selects')] public function the_option_picked_is_accepted(string $page, string $field, string $model): void { $record = $model::factory()->create(); // Only this field is asserted: the rest of each form is left empty on // purpose, and its own errors are not what this is about. Livewire::test($page) ->fillForm([$field => $record->getKey()]) ->call('create') ->assertHasNoFormErrors([$field]); } #[Test] public function the_option_reads_in_the_language_of_whoever_uses_the_panel(): void { $category = Category::factory()->create(['name' => ['es' => 'Novedades', 'en' => 'News']]); app()->setLocale('en'); $select = collect(Livewire::test(CreatePage::class)->instance()->form->getFlatComponents()) ->first(fn ($component) => method_exists($component, 'getName') && $component->getName() === 'category_id'); $label = $select->getOptionLabelFromRecord($category); $this->assertSame('News', $label); } }