1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\StandardCommand; |
6
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\ScrollAlign; |
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\ScrollToIndexCommand; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class ScrollToIndexCommandTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testConstructorWithAllParameters(): void |
14
|
|
|
{ |
15
|
|
|
$componentId = 'myList'; |
16
|
|
|
$index = 5; |
17
|
|
|
$align = ScrollAlign::CENTER; |
18
|
|
|
$targetDuration = 1200; |
19
|
|
|
|
20
|
|
|
$command = new ScrollToIndexCommand($componentId, $index, $align, $targetDuration); |
21
|
|
|
|
22
|
|
|
$this->assertSame($componentId, $command->componentId); |
23
|
|
|
$this->assertSame($index, $command->index); |
24
|
|
|
$this->assertSame($align, $command->align); |
25
|
|
|
$this->assertSame($targetDuration, $command->targetDuration); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testConstructorWithDefaultParameters(): void |
29
|
|
|
{ |
30
|
|
|
$command = new ScrollToIndexCommand(); |
31
|
|
|
|
32
|
|
|
$this->assertNull($command->componentId); |
33
|
|
|
$this->assertNull($command->index); |
34
|
|
|
$this->assertSame(ScrollAlign::VISIBLE, $command->align); |
35
|
|
|
$this->assertNull($command->targetDuration); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testJsonSerializeWithAllProperties(): void |
39
|
|
|
{ |
40
|
|
|
$componentId = 'testList'; |
41
|
|
|
$index = 3; |
42
|
|
|
$align = ScrollAlign::FIRST; |
43
|
|
|
$targetDuration = 600; |
44
|
|
|
|
45
|
|
|
$command = new ScrollToIndexCommand($componentId, $index, $align, $targetDuration); |
46
|
|
|
$result = $command->jsonSerialize(); |
47
|
|
|
|
48
|
|
|
$this->assertSame(ScrollToIndexCommand::TYPE, $result['type']); |
49
|
|
|
$this->assertSame($componentId, $result['componentId']); |
50
|
|
|
$this->assertSame($index, $result['index']); |
51
|
|
|
$this->assertSame($align->value, $result['align']); |
52
|
|
|
$this->assertSame($targetDuration, $result['targetDuration']); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testJsonSerializeWithNullValues(): void |
56
|
|
|
{ |
57
|
|
|
$command = new ScrollToIndexCommand(); |
58
|
|
|
$result = $command->jsonSerialize(); |
59
|
|
|
|
60
|
|
|
$this->assertSame(ScrollToIndexCommand::TYPE, $result['type']); |
61
|
|
|
$this->assertArrayNotHasKey('componentId', $result); |
62
|
|
|
$this->assertArrayNotHasKey('index', $result); |
63
|
|
|
$this->assertSame(ScrollAlign::VISIBLE->value, $result['align']); |
64
|
|
|
$this->assertArrayNotHasKey('targetDuration', $result); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testJsonSerializeWithPartialProperties(): void |
68
|
|
|
{ |
69
|
|
|
$command = new ScrollToIndexCommand('list1', 2); |
70
|
|
|
$result = $command->jsonSerialize(); |
71
|
|
|
|
72
|
|
|
$this->assertSame(ScrollToIndexCommand::TYPE, $result['type']); |
73
|
|
|
$this->assertSame('list1', $result['componentId']); |
74
|
|
|
$this->assertSame(2, $result['index']); |
75
|
|
|
$this->assertSame(ScrollAlign::VISIBLE->value, $result['align']); |
76
|
|
|
$this->assertArrayNotHasKey('targetDuration', $result); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testJsonSerializeWithZeroIndex(): void |
80
|
|
|
{ |
81
|
|
|
$command = new ScrollToIndexCommand('list', 0, ScrollAlign::LAST); |
82
|
|
|
$result = $command->jsonSerialize(); |
83
|
|
|
|
84
|
|
|
$this->assertSame(ScrollToIndexCommand::TYPE, $result['type']); |
85
|
|
|
$this->assertSame('list', $result['componentId']); |
86
|
|
|
$this->assertSame(0, $result['index']); |
87
|
|
|
$this->assertSame(ScrollAlign::LAST->value, $result['align']); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testJsonSerializeWithNegativeIndex(): void |
91
|
|
|
{ |
92
|
|
|
$command = new ScrollToIndexCommand('list', -1); |
93
|
|
|
$result = $command->jsonSerialize(); |
94
|
|
|
|
95
|
|
|
$this->assertSame(-1, $result['index']); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testTypeConstant(): void |
99
|
|
|
{ |
100
|
|
|
$this->assertSame('ScrollToIndex', ScrollToIndexCommand::TYPE); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|