55use Rappasoft \LaravelLivewireTables \Exceptions \DataTableConfigurationException ;
66use Rappasoft \LaravelLivewireTables \Tests \Models \Pet ;
77use Rappasoft \LaravelLivewireTables \Tests \TestCase ;
8- use Rappasoft \LaravelLivewireTables \Views \Columns \LivewireComponentColumn ;
8+ use Rappasoft \LaravelLivewireTables \Views \Columns \LivewireComponentColumn ;
9+ use Rappasoft \LaravelLivewireTables \Views \Column ;
910
1011final class LivewireComponentColumnTest extends TestCase
1112{
@@ -16,14 +17,22 @@ public function test_can_set_the_column_title(): void
1617 $ this ->assertSame ('Name ' , $ column ->getTitle ());
1718 }
1819
19- public function test_can_not_be_a_label (): void
20+ public function test_can_not_be_a_label_without_component (): void
2021 {
2122 $ this ->expectException (DataTableConfigurationException::class);
2223
2324 $ column = LivewireComponentColumn::make ('Total Users ' )->label (fn () => 'My Label ' )->getContents (Pet::find (1 ));
2425
2526 }
2627
28+ public function test_can_not_be_a_label_with_component (): void
29+ {
30+ $ this ->expectException (DataTableConfigurationException::class);
31+
32+ $ column = LivewireComponentColumn::make ('Total Users ' )->component ('test-component ' )->label (fn () => 'My Label ' )->getContents (Pet::find (1 ));
33+
34+ }
35+
2736 public function test_can_add_livewire_component (): void
2837 {
2938 $ column = LivewireComponentColumn::make ('Name ' , 'name ' );
@@ -43,23 +52,45 @@ public function test_can_get_livewire_component(): void
4352 $ column ->component ('test-component ' );
4453
4554 $ this ->assertTrue ($ column ->hasLivewireComponent ());
46- $ this ->assertSame ('test-component ' , $ column ->getLivewireComponent ());
55+ $ this ->assertSame ('test-component ' ,$ column ->getLivewireComponent ());
4756 }
4857
4958 public function test_can_not_avoid_defining_livewire_component (): void
5059 {
5160 $ this ->expectException (DataTableConfigurationException::class);
5261
53- $ contents = LivewireComponentColumn::make ('Total Users ' )->getContents (Pet::find (1 ));
62+ $ contents = LivewireComponentColumn::make ('Name ' )->getContents (Pet::find (1 ));
5463
5564 }
5665
5766 public function test_attributes_should_return_array (): void
5867 {
5968 $ this ->expectException (DataTableConfigurationException::class);
6069
61- $ column = LivewireComponentColumn::make ('Total Users ' )->attributes (fn ($ value , $ row , Column $ column ) => 'test ' );
70+ $ column = LivewireComponentColumn::make ('Name ' )-> component ( ' test-component ' )->attributes (fn ($ value , $ row , Column $ column ) => 'test ' );
6271
6372 $ column ->getContents (Pet::find (1 ));
6473 }
65- }
74+
75+ public function test_can_check_attribute_callback_presence (): void
76+ {
77+ $ column = LivewireComponentColumn::make ('Name ' , 'name ' )->component ('test-component ' );
78+ $ this ->assertFalse ($ column ->hasAttributesCallback ());
79+ }
80+
81+ public function test_can_set_attribute_callback (): void
82+ {
83+ $ column = LivewireComponentColumn::make ('Name ' , 'name ' )->component ('test-component ' );
84+ $ this ->assertFalse ($ column ->hasAttributesCallback ());
85+
86+ $ column ->attributes (function ($ row ) {
87+ return [
88+ 'class ' => '!rounded-lg self-center ' ,
89+ 'default ' => true ,
90+ ];
91+ });
92+
93+ $ this ->assertTrue ($ column ->hasAttributesCallback ());
94+ }
95+
96+ }
0 commit comments