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