9
9
use DateTimeImmutable ;
10
10
use Illuminate \Support \Collection ;
11
11
use PHPUnit \Framework \TestCase ;
12
+ use Spatie \Period \Period ;
12
13
13
14
final class SparkLineTest extends TestCase
14
15
{
@@ -17,20 +18,72 @@ private function days(): Collection
17
18
return collect ([
18
19
new SparkLineDay (
19
20
count: 1 ,
20
- day: new DateTimeImmutable ('-2 days ' )
21
+ day: new DateTimeImmutable ('2022-01-01 ' )
21
22
),
22
23
new SparkLineDay (
23
24
count: 2 ,
24
- day: new DateTimeImmutable ('-1 day ' )
25
+ day: new DateTimeImmutable ('2022-01-02 ' )
25
26
),
26
27
]);
27
28
}
28
29
29
30
/** @test */
30
- public function it_creates_a_sparkline (): void
31
+ public function test_create_sparkline (): void
31
32
{
32
33
$ sparkLine = SparkLine::new ($ this ->days ())->make ();
33
34
34
35
$ this ->assertStringContainsString ('<svg ' , $ sparkLine );
35
36
}
37
+
38
+ /** @test */
39
+ public function test_colors (): void
40
+ {
41
+ $ sparkLine = SparkLine::new ($ this ->days ())
42
+ ->withColors ('red ' , 'green ' , 'blue ' )
43
+ ->make ();
44
+
45
+ $ this ->assertStringContainsString ('<stop offset="0%" stop-color="red"></stop> ' , $ sparkLine );
46
+ $ this ->assertStringContainsString ('<stop offset="33%" stop-color="green"></stop> ' , $ sparkLine );
47
+ $ this ->assertStringContainsString ('<stop offset="66%" stop-color="blue"></stop> ' , $ sparkLine );
48
+ }
49
+
50
+ /** @test */
51
+ public function test_stroke_width (): void
52
+ {
53
+ $ sparkLine = SparkLine::new ($ this ->days ())
54
+ ->withStrokeWidth (50 )
55
+ ->make ();
56
+
57
+ $ this ->assertStringContainsString ('stroke-width="50" ' , $ sparkLine );
58
+ }
59
+
60
+ /** @test */
61
+ public function test_dimensions (): void
62
+ {
63
+ $ sparkLine = SparkLine::new ($ this ->days ())
64
+ ->withDimensions (500 , 501 )
65
+ ->make ();
66
+
67
+ $ this ->assertStringContainsString ('width="500" ' , $ sparkLine );
68
+ $ this ->assertStringContainsString ('height="501" ' , $ sparkLine );
69
+ }
70
+
71
+ /** @test */
72
+ public function test_get_period (): void
73
+ {
74
+ $ sparkLine = SparkLine::new ($ this ->days ());
75
+
76
+ $ this ->assertTrue (
77
+ Period::fromString ('[2022-01-01, 2022-01-02] ' )
78
+ ->equals ($ sparkLine ->getPeriod ()),
79
+ );
80
+ }
81
+
82
+ /** @test */
83
+ public function test_get_total (): void
84
+ {
85
+ $ sparkLine = SparkLine::new ($ this ->days ());
86
+
87
+ $ this ->assertEquals (3 , $ sparkLine ->getTotal ());
88
+ }
36
89
}
0 commit comments