|
| 1 | +import pytest |
| 2 | + |
| 3 | +from e2e.ui.pages.home import HomeRex |
| 4 | + |
| 5 | +import asyncio |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.asyncio |
| 9 | +@pytest.mark.parametrize("book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]) |
| 10 | +async def test_unsuccessful_search(chrome_page, base_url, book_slug, page_slug, rex_user, rex_password): |
| 11 | + |
| 12 | + # GIVEN: Playwright, chromium and the rex_base_url |
| 13 | + |
| 14 | + # WHEN: The Home page is fully loaded |
| 15 | + await chrome_page.goto(f"{base_url}/books/{book_slug}/pages/{page_slug}") |
| 16 | + home = HomeRex(chrome_page) |
| 17 | + |
| 18 | + assert home.content_search_field_is_visible |
| 19 | + |
| 20 | + await home.click_search() |
| 21 | + |
| 22 | + await home.fill_search_field("mmmxxx11") |
| 23 | + |
| 24 | + # THEN: No search results are shown |
| 25 | + |
| 26 | + await chrome_page.keyboard.press("Enter") |
| 27 | + |
| 28 | + assert "Sorry, no results found for " in await home.search_result_is_visible.inner_text() |
| 29 | + |
| 30 | + assert "Preface" not in await home.book_toc_slideout_is_visible.inner_text() |
| 31 | + |
| 32 | + await home.close_unsuccessful_search_result_sidebar() |
| 33 | + |
| 34 | + assert "Preface" in await home.book_toc_slideout_is_visible.inner_text() |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.asyncio |
| 38 | +@pytest.mark.parametrize("book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]) |
| 39 | +async def test_successful_search(chrome_page, base_url, book_slug, page_slug, rex_user, rex_password): |
| 40 | + |
| 41 | + # GIVEN: Playwright, chromium and the rex_base_url |
| 42 | + |
| 43 | + # WHEN: The Home page is fully loaded |
| 44 | + await chrome_page.goto(f"{base_url}/books/{book_slug}/pages/{page_slug}") |
| 45 | + home = HomeRex(chrome_page) |
| 46 | + |
| 47 | + assert home.content_search_field_is_visible |
| 48 | + |
| 49 | + await home.click_search() |
| 50 | + |
| 51 | + await home.fill_search_field('“cannibal galaxy”') |
| 52 | + |
| 53 | + # THEN: Search results are shown |
| 54 | + |
| 55 | + await chrome_page.keyboard.press("Enter") |
| 56 | + |
| 57 | + assert "4 search results for " in await home.search_result_is_visible.inner_text() |
| 58 | + |
| 59 | + assert '“cannibal galaxy”' in await home.search_result_is_visible.inner_text() |
| 60 | + |
| 61 | + await home.close_successful_search_result_sidebar() |
| 62 | + |
| 63 | + assert "4 search results for " not in await home.book_toc_slideout_is_visible.inner_text() |
| 64 | + |
| 65 | + |
| 66 | +@pytest.mark.asyncio |
| 67 | +@pytest.mark.parametrize("book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]) |
| 68 | +async def test_search_result(chrome_page, base_url, book_slug, page_slug, rex_user, rex_password): |
| 69 | + |
| 70 | + # GIVEN: Playwright, chromium and the rex_base_url |
| 71 | + |
| 72 | + # WHEN: The Home page is fully loaded |
| 73 | + await chrome_page.goto(f"{base_url}/books/{book_slug}/pages/{page_slug}") |
| 74 | + home = HomeRex(chrome_page) |
| 75 | + |
| 76 | + assert home.content_search_field_is_visible |
| 77 | + |
| 78 | + await home.click_search() |
| 79 | + |
| 80 | + await home.fill_search_field('“cannibal galaxy”') |
| 81 | + |
| 82 | + # THEN: Search results are shown |
| 83 | + |
| 84 | + await chrome_page.keyboard.press("Enter") |
| 85 | + |
| 86 | + assert "6.2 Telescopes Today" in await home.search_result_is_visible.inner_text() |
| 87 | + |
| 88 | + await home.click_first_search_result() |
| 89 | + |
| 90 | + # THEN: Correct page opens with the correct search result |
| 91 | + |
| 92 | + if home.content_page_black_overlay_is_visible: |
| 93 | + await home.click_content_page_black_overlay_close() |
| 94 | + |
| 95 | + assert "6.2 Telescopes Today" in await chrome_page.title() |
| 96 | + assert "cannibal galaxy" in await chrome_page.content() |
0 commit comments