aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/test_video_series_stays_open.py
blob: e0fe3f040f2b998caa60b295d13a4d4c7243f9a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
A show's detail modal stays open under the player.

Playing an episode closed the modal, so watching the next one meant finding the
show's card again, opening it, and picking the season again — every episode.
The modal now stays where it was, on the same season, with the episode just
started marked, and the player is drawn over it.

Measured rather than read: whether the reader lands back on the modal depends on
`PosterGrid`, on `GroupPage` mounting the player beside it, and on which of two
`.video-overlay`s the stylesheet puts on top. The probe renders the shipped
`GroupPage` against a stub node and walks it.
"""
import json
import shutil
import subprocess
from pathlib import Path

import pytest

HARNESS = Path(__file__).parent / "harness" / "video_series_probe.py"
STATIC = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static"

pytestmark = pytest.mark.skipif(
    shutil.which("google-chrome") is None or not (STATIC / "video-app.js").exists(),
    reason="Chrome or the SPA sources are not available")


@pytest.fixture(scope="module")
def walk():
    run = subprocess.run(["python3", str(HARNESS)], capture_output=True, timeout=150)
    assert run.returncode == 0, run.stderr.decode()[-2000:]
    out = json.loads(run.stdout.decode())
    assert "error" not in out, out["error"]
    return out


def test_the_player_is_drawn_over_the_modal(walk):
    assert walk["playing"]["detail"], "the show's modal closed when an episode started"
    assert walk["playing"]["player"]
    assert walk["playing"]["topmost"] == "player"


@pytest.mark.parametrize("step", ["afterEscape", "afterClose"])
def test_closing_the_player_lands_back_on_the_season_being_watched(walk, step):
    after = walk[step]
    assert after["detail"] and not after["player"]
    assert after["topmost"] == "detail"
    assert after["season"] == walk["playing"]["season"], "the season picked was lost"
    assert after["rows"] == walk["playing"]["rows"]


def test_the_episode_just_started_is_marked(walk):
    rows = walk["playing"]["rows"]
    assert walk["playing"]["marked"] == [rows[1]]
    assert walk["afterEscape"]["marked"] == [rows[1]]
    # Starting the next one from the modal moves the mark with it.
    assert walk["afterClose"]["marked"] == [rows[2]]


def test_the_modal_still_closes_and_reopens_clean(walk):
    assert not walk["afterModalClose"]["detail"]
    reopened = walk["reopened"]
    assert reopened["detail"]
    assert reopened["marked"] == [], "a mark from the last visit carried over"
    assert reopened["season"] != walk["playing"]["season"], (
        "a reopened show starts on its default season, as it always did")


def test_a_film_still_closes_its_modal(walk):
    """Nothing left to pick once a film starts, so nothing to come back to."""
    assert walk["film"]["player"]
    assert not walk["film"]["detail"]
    assert walk["film"]["topmost"] == "player"