Testing that a table can render
To ensure a table component renders, use theassertSuccessful() Livewire helper:
assertCanSeeTableRecords(), assertCanNotSeeTableRecords() and assertCountTableRecords():
If your table uses pagination,assertCanSeeTableRecords()will only check for records on the first page. To switch page, callcall('gotoPage', 2).
If your table usesdeferLoading(), you should callloadTable()beforeassertCanSeeTableRecords().
Testing columns
To ensure that a certain column is rendered, pass the column name toassertCanRenderTableColumn():
assertCanNotRenderTableColumn():
Testing that a column can be searched
To search the table, call thesearchTable() method with your search query.
You can then use assertCanSeeTableRecords() to check your filtered table records, and use assertCanNotSeeTableRecords() to assert that some records are no longer in the table:
searchTableColumns():
Testing that a column can be sorted
To sort table records, you can callsortTable(), passing the name of the column to sort by. You can use 'desc' in the second parameter of sortTable() to reverse the sorting direction.
Once the table is sorted, you can ensure that the table records are rendered in order using assertCanSeeTableRecords() with the inOrder parameter:
Filament tables use a SQL
order statement to sort records before they are output. Different database drivers can use different sorting strategies, and they can differ from PHP’s own sorting strategy, so you should ensure that test records are sorted using orderBy() on a database query rather than sortBy() on a collection of models.Testing the state of a column
To assert that a certain column has a state or does not have a state for a record you can useassertTableColumnStateSet() and assertTableColumnStateNotSet():
assertTableColumnFormattedStateSet() and assertTableColumnFormattedStateNotSet():
Testing the existence of a column
To ensure that a column exists, you can use theassertTableColumnExists() method:
Testing the visibility of a column
To ensure that a particular user cannot see a column, you can use theassertTableColumnVisible() and assertTableColumnHidden() methods:
Testing the description of a column
To ensure a column has the correct description above or below you can use theassertTableColumnHasDescription() and assertTableColumnDoesNotHaveDescription() methods:
Testing the extra attributes of a column
To ensure that a column has the correct extra attributes, you can use theassertTableColumnHasExtraAttributes() and assertTableColumnDoesNotHaveExtraAttributes() methods:
Testing the options in a SelectColumn
If you have a select column, you can ensure it has the correct options with assertTableSelectColumnHasOptions() and assertTableSelectColumnDoesNotHaveOptions():
Testing filters
To filter the table records, you can use thefilterTable() method, along with assertCanSeeTableRecords() and assertCanNotSeeTableRecords():
SelectFilter or TernaryFilter, pass the value as a second argument:
Resetting filters in a test
To reset all filters to their original state, callresetTableFilters():
Removing filters in a test
To remove a single filter you can useremoveTableFilter():
removeTableFilters():
Testing the visibility of a filter
To ensure that a particular user cannot see a filter, you can use theassertTableFilterVisible() and assertTableFilterHidden() methods:
Testing the existence of a filter
To ensure that a filter exists, you can use theassertTableFilterExists() method:
Testing summaries
To test that a summary calculation is working, you may use theassertTableColumnSummarySet() method:
123.12 is considered the same as "123.12", and ['Fred', 'Jim'] is the same as ['Jim', 'Fred'].
You may set a summarizer ID by passing it to the make() method:
Testing summaries on only one pagination page
To calculate the average for only one pagination page, use theisCurrentPaginationPageOnly argument:
Testing a range summarizer
To test a range, pass the minimum and maximum value into a tuple-style[$minimum, $maximum] array:
Testing toggleable columns
By default, only columns that are toggled on by default in the table will be rendered and testable. You can toggle all columns in the table on usingtoggleAllTableColumns():
toggleAllTableColumns(false):