Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 55 additions & 3 deletions playwright/e2e/ui/pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,20 @@ async def logout_link_is_visible(self):
async def click_logout_link(self):
await self.page.get_by_role("menuitem", name="Log out").click()

@property
def small_login_box(self):
return self.page.get_by_text(
"Log in to highlight and take notes. It’s 100% free.Log inCancel"
)

@pytest.mark.asyncio
async def click_small_login_box_cancel(self):
await self.page.get_by_role("button", name="Cancel").click()

@pytest.mark.asyncio
async def click_small_login_box_login(self):
await self.page.get_by_test_id("confirm").click()

# Book chapter section

@pytest.mark.asyncio
Expand All @@ -354,14 +368,40 @@ async def click_other_text(self):
async def select_text(self):
await self.page.locator("p:has-text('impact history')").select_text()

@pytest.mark.asyncio
async def select_text_block_in_solution(self):
await self.page.locator(
"p:has-text('formula. Repeat with values')"
).select_text()

@pytest.mark.asyncio
async def click_astronomy_book_chapter93(self):
await self.page.get_by_test_id("content-link-test").get_by_text(
"Impact Craters"
).click()

# Highlight box and highlights

@pytest.mark.asyncio
async def highlight_box_trash_icon_is_visible(self):
return await self.page.get_by_label("Deselect current highlight").is_visible()

@pytest.mark.asyncio
async def click_highlight_box_trash_icon(self):
await self.page.get_by_label("Deselect current highlight").click()

@pytest.mark.asyncio
async def double_click_highlight_infobox(self):
return (
await self.page.locator("div")
.get_by_test_id("editcard-trash-icon")
.is_visible()
await self.page.get_by_role("dialog")
.get_by_text("Press Enter or double-click highlight to edit highlight")
.dblclick()
)

@property
def highlight_infobox(self):
return self.page.get_by_role("dialog").get_by_text(
"Press Enter or double-click highlight to edit highlight"
)

@pytest.mark.asyncio
Expand Down Expand Up @@ -428,6 +468,10 @@ async def click_small_highlight_box_delete_button(self):
async def click_delete_highlight_button(self):
await self.page.locator("div").get_by_test_id("confirm").click()

@pytest.mark.asyncio
async def click_small_highlight_box_edit_button(self):
await self.page.get_by_test_id("card").get_by_text("Edit").click()

@pytest.mark.asyncio
async def yellow_highlighted_text_is_visible(self):
return await self.page.locator("mark > span:nth-child(1)").all()
Expand Down Expand Up @@ -494,6 +538,10 @@ async def unsaved_highlight_dialog_cancel_button_is_visible(self):
async def click_cancel_changes_button(self):
await self.page.locator("div").get_by_test_id("cancel-discard").click()

@pytest.mark.asyncio
async def click_discard_changes_button(self):
await self.page.locator("div").get_by_test_id("discard-changes").click()

# Error states and pages

@pytest.mark.asyncio
Expand All @@ -520,6 +568,10 @@ async def click_search(self):
async def fill_search_field(self, value):
await self.content_search_field_is_visible.fill(value)

@pytest.mark.asyncio
async def click_search_magnifier_icon(self):
await self.page.get_by_role("button", name="Search").click()

@property
def search_result_is_visible(self):
return self.page.get_by_test_id("search-results-sidebar")
Expand Down
86 changes: 71 additions & 15 deletions playwright/e2e/ui/test_highlight_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@pytest.mark.parametrize(
"book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]
)
async def test_highlight_box_dismiss_with_esc(
async def test_highlight_box_opens_on_enter(
chrome_page, base_url, book_slug, page_slug, rex_user, rex_password
):

Expand All @@ -30,23 +30,69 @@ async def test_highlight_box_dismiss_with_esc(

await home.double_click_text()

assert await home.highlight_infobox.is_visible()

await chrome_page.keyboard.press("Enter")

assert await home.highlight_box_is_visible()

assert await home.highlight_box_colours_are_visible()
assert await home.highlight_box_trash_icon_is_visible()

await home.click_highlight_box_trash_icon()

await home.click_highlights_option()

assert (
"You have no highlights in this book"
in await home.highlights_option_page_is_empty.inner_text()
)


@pytest.mark.asyncio
@pytest.mark.parametrize(
"book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]
)
async def test_highlight_box_opens_on_double_click(
chrome_page, base_url, book_slug, page_slug, rex_user, rex_password
):

# GIVEN: Playwright, chromium and the rex_base_url

# WHEN: The Home page is fully loaded
await chrome_page.goto(f"{base_url}/books/{book_slug}/pages/{page_slug}")
home = HomeRex(chrome_page)

await home.click_login()

await home.fill_user_field(rex_user)
await home.fill_password_field(rex_password)

await home.click_continue_login()

# THEN: Book page opens, highlight box appears, then disappears on Escape key

await chrome_page.keyboard.press("Escape")

# Adjusting the test until the expected behaviour is implemented for Escape key (to avoid test fail)
await home.double_click_text()

assert await home.highlight_infobox.is_visible()

await home.double_click_highlight_infobox()

assert await home.highlight_box_is_visible()
# await home.click_highlights_option()
# assert "You have no highlights in this book" not in await home.highlights_option_page_is_empty.inner_text()

assert await home.highlight_box_colours_are_visible()
assert await home.highlight_box_trash_icon_is_visible()

await home.click_highlight_box_trash_icon()


@pytest.mark.asyncio
@pytest.mark.parametrize(
"book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]
)
async def test_highlight_box_dismiss_with_click(
async def tst_highlight_is_created_without_annotation_on_enter(
chrome_page, base_url, book_slug, page_slug, rex_user, rex_password
):

Expand All @@ -63,31 +109,37 @@ async def test_highlight_box_dismiss_with_click(

await home.click_continue_login()

# THEN: Book page opens, highlight box appears, then disappears on clicking away from the box
# THEN: Book page opens, highlight box appears, then disappears on Escape key

await chrome_page.keyboard.press("Escape")

await home.double_click_text()

assert await home.highlight_infobox.is_visible()

await chrome_page.keyboard.press("Enter")

assert await home.highlight_box_is_visible()

await home.click_other_text()
await chrome_page.keyboard.press("Escape")

assert not await home.highlight_box_is_visible()

await chrome_page.keyboard.press("Enter")

await home.click_highlights_option()

assert (
"You have no highlights in this book"
in await home.highlights_option_page_is_empty.inner_text()
not in await home.highlights_option_page_is_empty.inner_text()
)


@pytest.mark.asyncio
@pytest.mark.parametrize(
"book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]
)
async def test_highlight_box_click_highlights_option_after_highlighting_text(
async def tst_highlight_is_created_without_annotation_on_double_click(
chrome_page, base_url, book_slug, page_slug, rex_user, rex_password
):

Expand All @@ -104,21 +156,25 @@ async def test_highlight_box_click_highlights_option_after_highlighting_text(

await home.click_continue_login()

# THEN: Book page opens, highlight box appears, then disappears on clicking the highlights option page
# THEN: Book page opens, highlight box appears, then disappears on Escape key

await chrome_page.keyboard.press("Escape")

await home.double_click_text()

assert await home.highlight_infobox.is_visible()

await home.double_click_highlight_infobox()

assert await home.highlight_box_is_visible()

await chrome_page.keyboard.press("Escape")

assert not await home.highlight_box_is_visible()

await home.click_highlights_option()

assert (
"You have no highlights in this book"
in await home.highlights_option_page_is_empty.inner_text()
not in await home.highlights_option_page_is_empty.inner_text()
)

await chrome_page.keyboard.press("Escape")

assert not await home.highlight_box_is_visible()
18 changes: 9 additions & 9 deletions playwright/e2e/ui/test_highlight_box_delete_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

from e2e.ui.pages.home import HomeRex

import asyncio


@pytest.mark.asyncio
@pytest.mark.parametrize("book_slug, page_slug",
[("astronomy-2e", "9-3-impact-craters")])
async def test_highlight_box_delete_note(chrome_page, base_url, book_slug, page_slug, rex_user, rex_password):
@pytest.mark.parametrize(
"book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]
)
async def test_small_highlight_box_delete_note(
chrome_page, base_url, book_slug, page_slug, rex_user, rex_password
):

# GIVEN: Playwright, chromium and the rex_base_url

Expand All @@ -23,17 +24,16 @@ async def test_highlight_box_delete_note(chrome_page, base_url, book_slug, page_

await home.click_continue_login()

#THEN: Book page opens, highlight box appears, note is saved, then deleted and box disappears
# THEN: Book page opens, highlight box appears, note is saved, then deleted and box disappears

await chrome_page.keyboard.press("Escape")

await home.double_click_text()
await chrome_page.keyboard.press("Enter")

assert home.highlight_box_is_visible

await home.click_highlight_box_note_field()

await home.fill_highlight_box_note_field('autotest highlight')
await home.fill_highlight_box_note_field("autotest highlight")

await home.click_highlight_box_save_button()

Expand Down
11 changes: 9 additions & 2 deletions playwright/e2e/ui/test_highlight_box_save_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ async def test_highlight_box_save_note(
await home.select_text()
await home.double_click_text()

await chrome_page.keyboard.press("Enter")

assert await home.highlight_box_is_visible()

await home.click_highlight_box_note_field()
Expand Down Expand Up @@ -77,8 +79,7 @@ async def test_overlapping_highlights(

await chrome_page.keyboard.press("Escape")

assert not await home.small_highlighted_note_box_is_visible()

await home.select_text()
await home.double_click_text()

assert await home.overlapping_highlights_message_is_visible()
Expand All @@ -88,6 +89,8 @@ async def test_overlapping_highlights(
in await home.overlapping_highlights_message.inner_text()
)

# THEN: Delete the created highlight

await home.click_highlights_option()
await home.click_highlights_option_page_menu()

Expand Down Expand Up @@ -128,6 +131,8 @@ async def test_highlight_box_note_colours(
await home.select_text()
await home.double_click_text()

await chrome_page.keyboard.press("Enter")

assert await home.highlight_box_is_visible()

await home.click_highlight_box_purple_colour()
Expand Down Expand Up @@ -157,6 +162,8 @@ async def test_highlight_box_note_colours(

assert "green" in await home.highlights_option_text_colour_check_green

# THEN: Delete the created highlight

await home.click_highlights_option_page_menu()

await home.click_highlights_option_page_menu_delete()
Expand Down
Loading
Loading