How to test the schema state of a relationship manager that is a simple resource

What I am trying to do: I'm trying to test if the TextInput inside a form of a relation manager has a default value set. What I did: AddressResource is created with this command: php artisan make:filament-resource Address --simple A relation manager is created for Contact - Address. The form contains:
TextInput::make('country')
->label(__('Country'))
->required()
->default(Address::getDefaultCountryString()),
TextInput::make('country')
->label(__('Country'))
->required()
->default(Address::getDefaultCountryString()),
My issue/the error: I can not figure out how to test that the country has a default value when opening the CreateAction form. Code:
it('has default value for country set to the-default-value', function () {
$user = createUserWithPermissions(['view contacts', 'view addresses', 'create addresses']);
actingAs($user);

$contact = Contact::factory()->create();

// @phpstan-ignore-next-line
livewire(AddressesRelationManager::class, [
'ownerRecord' => $contact,
'pageClass' => EditContact::class,
])
->assertActionExists(TestAction::make(CreateAction::class)->table())
->assertActionVisible(TestAction::make(CreateAction::class)->table())
// what should I from here:
->assertSchemaStateSet([
'country' => 'the-default-value',
]);

});
it('has default value for country set to the-default-value', function () {
$user = createUserWithPermissions(['view contacts', 'view addresses', 'create addresses']);
actingAs($user);

$contact = Contact::factory()->create();

// @phpstan-ignore-next-line
livewire(AddressesRelationManager::class, [
'ownerRecord' => $contact,
'pageClass' => EditContact::class,
])
->assertActionExists(TestAction::make(CreateAction::class)->table())
->assertActionVisible(TestAction::make(CreateAction::class)->table())
// what should I from here:
->assertSchemaStateSet([
'country' => 'the-default-value',
]);

});
Solution:
Apparently you just need to mount the action before calling assertSchemaStateSet:
->mountAction(TestAction::make(CreateAction::class)->table())
->mountAction(TestAction::make(CreateAction::class)->table())
...
Jump to solution
1 Reply
Solution
TDDeveloper
TDDeveloper4w ago
Apparently you just need to mount the action before calling assertSchemaStateSet:
->mountAction(TestAction::make(CreateAction::class)->table())
->mountAction(TestAction::make(CreateAction::class)->table())

Did you find this page helpful?