<?phpnamespace Tests;use App\Gui\PlaylistWindow;/** * The play list follows the song playing (next, previous, the end of a song, Hasard), unless it was scrolled by hand a * moment ago; the target of its foot (« Aller au morceau en cours ») brings it back at once. Every skin, and the * original phone interface. */final class PlaylistFollowTest extends PlayerTestCase{ private function list(int $songs = 80, array $params = []): PlaylistWindow { $this->startPlayer($params); $list = $this->desk->playlist; self::assertNotNull($list); $this->wz->playlist->clear(); $demo = ['assets/music/winzik.mp3', 'assets/music/archettes-city.ogg', 'assets/music/chaine-hifi.wav', 'assets/music/partage.mp3']; for ($i = 0; $i < $songs; $i++) { $this->wz->playlist->add($demo[$i % 4]); } $this->wz->playIndex(0); $this->game->wait(1); // the windows unrolled return $list; } private function shown(PlaylistWindow $list, int $index): bool { $line = $list->lineOf($index); return $line >= $list->top() && $line < $list->top() + $list->rows(); } public function testASongChangedFarAwayScrollsTheListToItsLineInTheMiddle(): void { $list = $this->list(); self::assertSame(0, $list->top()); $this->wz->playIndex(50); // a click elsewhere, Hasard, a .FLS: far below what is shown $this->game->run(2); self::assertTrue($this->shown($list, 50), 'the line playing is shown'); self::assertSame(50 - intdiv($list->rows(), 2), $list->top(), 'in the middle'); // next / previous / the end of the song: it goes on following $this->wz->playIndex(79); $this->game->run(2); self::assertTrue($this->shown($list, 79)); $this->wz->playIndex(3); $this->game->run(2); self::assertTrue($this->shown($list, 3)); $this->game->shot('playlist-follow'); } public function testAListScrolledByHandIsNotYankedThenFollowsAgainAfterAMoment(): void { $list = $this->list(); $this->wz->playIndex(0); $this->game->run(2); self::assertTrue($list->wheel(-5)); // the wheel: down 15 lines $top = $list->top(); self::assertSame(15, $top); $this->wz->playIndex(70); $this->game->run(2); self::assertSame($top, $list->top(), 'scrolled by hand a moment ago: the list stays where the user put it'); self::assertFalse($list->activeInView()); $this->game->shot('playlist-follow-held'); // left alone FOLLOW_AFTER seconds: it shows the song playing $this->game->wait(PlaylistWindow::FOLLOW_AFTER + 0.5); self::assertTrue($this->shown($list, 70), 'the hand gone, the list follows again'); } public function testTheTargetOfTheFootBringsBackTheSongPlayingAtOnce(): void { $list = $this->list(); $list->wheel(-6); $this->wz->playIndex(60); $this->game->run(2); self::assertFalse($list->activeInView(), 'held: not followed'); self::assertSame('Aller au morceau en cours', $list->tip('locate')); $this->game->shot('playlist-locate-lost'); $this->clickControl($list, 'locate'); self::assertTrue($this->shown($list, 60), 'the button: the line playing in view'); self::assertFalse($list->heldByHand(), 'and the list follows the songs again'); $this->wz->playIndex(5); $this->game->run(2); self::assertTrue($this->shown($list, 5)); } public function testTheSearchAndTheFoldersFollowTooAndASongTheyHideMovesNothing(): void { $list = $this->list(200); // the search: only partage (one song in four); the 41st of them is line 40 of the search $list->toggleSearch(); $list->filter = 'partage'; $this->game->run(1); $this->wz->playIndex(4 * 40 + 3); $this->game->run(2); self::assertSame(40, $list->lineOf(4 * 40 + 3)); self::assertTrue($this->shown($list, 4 * 40 + 3), 'its line of the search is shown'); $top = $list->top(); $this->wz->playIndex(0); // not found by the search: nothing moves $this->game->run(2); self::assertSame(-1, $list->lineOf(0)); self::assertSame($top, $list->top()); $list->toggleSearch(); // by folders: the folders open, its line shown $this->wz->ui['playlist']['grouped'] = true; $this->game->run(1); for ($pass = 0; $pass < 2; $pass++) { foreach ($list->tree() as $node) { if ($node['kind'] !== 'song') { $this->wz->ui['playlist']['open'][$node['key']] = true; } } $this->game->run(1); } $this->wz->playIndex(198); $this->game->run(2); self::assertGreaterThanOrEqual(0, $list->lineOf(198)); self::assertTrue($this->shown($list, 198)); } public function testEverySkinDrawsTheTargetInItsFoot(): void { $this->list(40); $skins = array_values(array_filter($this->wz->skins(), fn ($s) => str_contains(str_replace('\\', '/', $s->dir), '/assets/skins/'))); self::assertNotEmpty($skins); $list = $this->desk->playlist; foreach ($skins as $skin) { self::assertTrue($this->wz->useSkin($skin->dir), basename($skin->dir)); $this->game->run(2); [$x, $y, $w, $h] = $list->controls()['locate']; self::assertLessThanOrEqual($list->width() - 19, $x + $w, 'before the right dot'); self::assertSame('locate', $list->controlAt($x + $w / 2, $y + $h / 2)); $this->game->shot('playlist-locate-' . basename($skin->dir)); } } public function testTheOriginalPhoneInterfaceFollowsAndHasTheTarget(): void { $list = $this->list(200, ['phone' => true]); $this->wz->playIndex(64); $this->game->run(2); self::assertTrue($this->shown($list, 64)); $list->wheel(5); $this->wz->playIndex(10); $this->game->run(2); self::assertFalse($list->activeInView()); $this->clickControl($list, 'locate'); self::assertTrue($this->shown($list, 10)); $this->game->shot('original-phone-playlist-locate'); }}