diff --git a/test/conftest.py b/test/conftest.py index c01469b8b..19dc5279a 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -5,6 +5,7 @@ from _pytest.fixtures import SubRequest from pytest_base_url.plugin import base_url from playwright.sync_api import Playwright, APIRequestContext, Route, Page, Browser +import json @fixture def get_test_dir() -> Path: @@ -151,4 +152,31 @@ def expect_nav_items() -> List[Dict[str,str]]: # {'title': 'Archive', 'href': '/archive'}, # failing on tests here: https://github.com/JupiterBroadcasting/jupiterbroadcasting.com/runs/8254156209?check_suite_focus=true#step:9:26 {'title': 'Contact', 'href': '/contact/'}, - ] \ No newline at end of file + ] + +@fixture +def set_live() -> Callable: + return _replace_live_event + +@staticmethod +def _replace_live_event(page: Page) -> None: + def handle_route(route: Route) -> None: + # fetch original response + response = page.request.fetch(route.request) + json_data = response.json() + + # override response values + if json_data.get('data'): + json_data['data'][0]['isLive'] = True + json_data['total'] = 1 + + # setting live event + route.fulfill( + # Pass all fields from the response + response=response, + body=json.dumps(json_data), + ) + page.route( + "https://jupiter.tube/api/v1/video-channels/live/**", + handle_route + ) \ No newline at end of file diff --git a/test/e2e/test_live.py b/test/e2e/test_live.py index eea7a4383..d16c114fd 100644 --- a/test/e2e/test_live.py +++ b/test/e2e/test_live.py @@ -2,23 +2,17 @@ from typing import Tuple, Callable from playwright.sync_api import Page, expect, Locator, FrameLocator, Route -def handle_peertube_response(route: Route): - response = route.fulfill() - json = response.json() - json.data[0].isLive = True - # Fulfill using the original response, while patching the response body - route.fulfill(response=response, json=json) - def test_live_indicator( page: Page, + set_live: Callable, screenshot_dir: Path, ): + # intercepting reponses for live event, and make live + set_live(page) # go to the live page page.goto("/live") - page.route("https://jupiter.tube/api/v1/video-channels/live/videos?isLive=true&skipCount=false&count=1&sort=-createdAt", handle_peertube_response) - # validate live button is red expect(page.locator("#mainnavigation.is-live").locator("#livebutton"),).to_have_css( name="background-color", @@ -37,6 +31,7 @@ def test_live_indicator( def test_mobile_live_indicator( mobile_device_tuple: Tuple[Page, str], + set_live: Callable, screenshot_dir: Path, ): # set mobile page to variable @@ -46,9 +41,10 @@ def test_mobile_live_indicator( screenshot_dir / f"mobile/{mobile_device_tuple[1].replace(' ','-')}/" ) - mobile_device.goto("/live") + # intercepting reponses for live event, and make live + set_live(mobile_device) - mobile_device.route("https://jupiter.tube/api/v1/video-channels/live/videos?isLive=true&skipCount=false&count=1&sort=-createdAt", handle_peertube_response) + mobile_device.goto("/live") navbar: Locator = mobile_device.locator("#mainnavigation.is-live",).locator( ".navbar-burger",