To test a Livewire component that is part of a Filament resource created with the --simple flag, you need to ensure that you are calling the correct method that handles the form submission. In the case of Filament, the method might not be named save. Instead, it could be createRecord or updateRecord depending on whether you are creating or updating a record.
Here's how you can adjust your test to work with the simple Filament resource:
it('can create equipment owners', function () {
$equipmentOwnerData = EquipmentOwner::factory()->make()->toArray();
// Assuming that the Livewire component is named `EquipmentOwnersResource`
// and the method to create a record is `createRecord`.
livewire(EquipmentOwnersResource::class)
->set('data', $equipmentOwnerData)
->call('createRecord')
->assertHasNoErrors();
// Optionally, you can assert that the record was created in the database.
$this->assertDatabaseHas('equipment_owners', [
'name' => $equipmentOwnerData['name'],
// ... other fields
]);
});
Please note the following:
- You need to use the actual name of the Livewire component that corresponds to your
EquipmentOwnersResource. ReplaceEquipmentOwnersResource::classwith the correct class name if it's different. - The
->set('data', $equipmentOwnerData)line assumes that your Livewire component uses an array calleddatato store the form input. Adjust this to match the actual property names used in your component. - The
->call('createRecord')line assumes that the method to create a new record is namedcreateRecord. This is a common convention in Filament, but you should verify the actual method name in your Livewire component. - The
->assertHasNoErrors()method asserts that there are no validation errors. If your component uses a different method to handle errors, you may need to adjust this assertion accordingly. - The
assertDatabaseHasmethod is optional and is used to verify that the record was indeed created in the database. Make sure to include all relevant fields that you expect to be present in the database record.
If you're still encountering issues, double-check the Livewire component for the correct method names and properties, and ensure that your test is set up to interact with those correctly.