77use Rappasoft \LaravelLivewireTables \Tests \TestCase ;
88use Rappasoft \LaravelLivewireTables \Views \Column ;
99use Rappasoft \LaravelLivewireTables \Views \Columns \ComponentColumn ;
10+ use Rappasoft \LaravelLivewireTables \Tests \Http \Components \TestComponent ;
11+ use Illuminate \Support \Facades \Blade ;
1012
1113final class ComponentColumnTest extends TestCase
1214{
15+ protected function setUp (): void
16+ {
17+ parent ::setUp ();
18+ }
19+
1320 public function test_can_set_the_column_title (): void
1421 {
1522 $ column = ComponentColumn::make ('Name ' , 'name ' );
@@ -34,4 +41,59 @@ public function test_can_not_be_both_collapsible_on_mobile_and_on_tablet(): void
3441 $ column ->getContents ($ row );
3542
3643 }
44+
45+
46+ public function test_can_set_custom_slot (): void
47+ {
48+ $ column = ComponentColumn::make ('Age 2 ' , 'age ' )
49+ ->attributes (fn ($ value , $ row , Column $ column ) => [
50+ 'age ' => $ row ->age ,
51+ ])
52+ ->slot (fn ($ value , $ row , Column $ column ) => [
53+ ($ row ->age < 2 ) => 'test1 ' ,
54+ ($ row ->age > 2 ) => 'test2 ' ,
55+ ]);
56+ $ this ->assertTrue ($ column ->hasSlotCallback ());
57+ }
58+
59+
60+ public function test_can_get_custom_slot (): void
61+ {
62+
63+ $ column = ComponentColumn::make ('Age 2 ' , 'age ' )
64+ ->attributes (fn ($ value , $ row , Column $ column ) => [
65+ 'age ' => $ row ->age ,
66+ ])
67+ ->slot (fn ($ value , $ row , Column $ column ) => (($ row ->age < 10 ) ? 'youngslot ' : 'oldslot ' ))
68+ ->component ('livewire-tables-test::test ' );
69+
70+ $ pet1 = Pet::where ('age ' , '> ' , 11 )->first ();
71+ $ pet1_contents = $ column ->getContents ($ pet1 );
72+ $ this ->assertSame ('oldslot ' ,$ pet1_contents ->getData ()['slot ' ]->__toString ());
73+
74+ $ pet2 = Pet::where ('age ' , '< ' , 5 )->first ();
75+ $ pet2_contents = $ column ->getContents ($ pet2 );
76+ $ this ->assertSame ('youngslot ' ,$ pet2_contents ->getData ()['slot ' ]->__toString ());
77+
78+ }
79+
80+ public function test_can_get_attributes (): void
81+ {
82+
83+ $ column = ComponentColumn::make ('Age 2 ' , 'age ' )
84+ ->attributes (fn ($ value , $ row , Column $ column ) => [
85+ 'age ' => $ row ->age ,
86+ ])
87+ ->slot (fn ($ value , $ row , Column $ column ) => (($ row ->age < 10 ) ? 'youngslot ' : 'oldslot ' ))
88+ ->component ('livewire-tables-test::test ' );
89+
90+ $ pet1 = Pet::where ('age ' , '> ' , 11 )->first ();
91+ $ pet1_contents = $ column ->getContents ($ pet1 );
92+ $ this ->assertSame (22 , $ pet1_contents ->getData ()['attributes ' ]['age ' ]);
93+
94+ $ pet2 = Pet::where ('age ' , '< ' , 5 )->first ();
95+ $ pet2_contents = $ column ->getContents ($ pet2 );
96+ $ this ->assertSame (2 , $ pet2_contents ->getData ()['attributes ' ]['age ' ]);
97+
98+ }
3799}
0 commit comments