Skip to content

Commit aa1b02d

Browse files
committed
amending highlight tests as per upcoming changes and fixes
1 parent 259bc4c commit aa1b02d

10 files changed

+495
-54
lines changed

playwright/e2e/ui/pages/home.py

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,20 @@ async def logout_link_is_visible(self):
340340
async def click_logout_link(self):
341341
await self.page.get_by_role("menuitem", name="Log out").click()
342342

343+
@property
344+
def small_login_box(self):
345+
return self.page.get_by_text(
346+
"Log in to highlight and take notes. It’s 100% free.Log inCancel"
347+
)
348+
349+
@pytest.mark.asyncio
350+
async def click_small_login_box_cancel(self):
351+
await self.page.get_by_role("button", name="Cancel").click()
352+
353+
@pytest.mark.asyncio
354+
async def click_small_login_box_login(self):
355+
await self.page.get_by_test_id("confirm").click()
356+
343357
# Book chapter section
344358

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

371+
@pytest.mark.asyncio
372+
async def select_text_block_in_solution(self):
373+
await self.page.locator(
374+
"p:has-text('formula. Repeat with values')"
375+
).select_text()
376+
377+
@pytest.mark.asyncio
378+
async def click_astronomy_book_chapter93(self):
379+
await self.page.get_by_test_id("content-link-test").get_by_text(
380+
"Impact Craters"
381+
).click()
382+
357383
# Highlight box and highlights
358384

359385
@pytest.mark.asyncio
360386
async def highlight_box_trash_icon_is_visible(self):
387+
return await self.page.get_by_label("Deselect current highlight").is_visible()
388+
389+
@pytest.mark.asyncio
390+
async def click_highlight_box_trash_icon(self):
391+
await self.page.get_by_label("Deselect current highlight").click()
392+
393+
@pytest.mark.asyncio
394+
async def double_click_highlight_infobox(self):
361395
return (
362-
await self.page.locator("div")
363-
.get_by_test_id("editcard-trash-icon")
364-
.is_visible()
396+
await self.page.get_by_role("dialog")
397+
.get_by_text("Press Enter or double-click highlight to edit highlight")
398+
.dblclick()
399+
)
400+
401+
@property
402+
def highlight_infobox(self):
403+
return self.page.get_by_role("dialog").get_by_text(
404+
"Press Enter or double-click highlight to edit highlight"
365405
)
366406

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

471+
@pytest.mark.asyncio
472+
async def click_small_highlight_box_edit_button(self):
473+
await self.page.get_by_test_id("card").get_by_text("Edit").click()
474+
431475
@pytest.mark.asyncio
432476
async def yellow_highlighted_text_is_visible(self):
433477
return await self.page.locator("mark > span:nth-child(1)").all()
@@ -494,6 +538,10 @@ async def unsaved_highlight_dialog_cancel_button_is_visible(self):
494538
async def click_cancel_changes_button(self):
495539
await self.page.locator("div").get_by_test_id("cancel-discard").click()
496540

541+
@pytest.mark.asyncio
542+
async def click_discard_changes_button(self):
543+
await self.page.locator("div").get_by_test_id("discard-changes").click()
544+
497545
# Error states and pages
498546

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

571+
@pytest.mark.asyncio
572+
async def click_search_magnifier_icon(self):
573+
await self.page.get_by_role("button", name="Search").click()
574+
523575
@property
524576
def search_result_is_visible(self):
525577
return self.page.get_by_test_id("search-results-sidebar")

playwright/e2e/ui/test_highlight_box.py

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@pytest.mark.parametrize(
88
"book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]
99
)
10-
async def test_highlight_box_dismiss_with_esc(
10+
async def test_highlight_box_opens_on_enter(
1111
chrome_page, base_url, book_slug, page_slug, rex_user, rex_password
1212
):
1313

@@ -30,23 +30,69 @@ async def test_highlight_box_dismiss_with_esc(
3030

3131
await home.double_click_text()
3232

33+
assert await home.highlight_infobox.is_visible()
34+
35+
await chrome_page.keyboard.press("Enter")
36+
3337
assert await home.highlight_box_is_visible()
3438

3539
assert await home.highlight_box_colours_are_visible()
40+
assert await home.highlight_box_trash_icon_is_visible()
41+
42+
await home.click_highlight_box_trash_icon()
43+
44+
await home.click_highlights_option()
45+
46+
assert (
47+
"You have no highlights in this book"
48+
in await home.highlights_option_page_is_empty.inner_text()
49+
)
50+
51+
52+
@pytest.mark.asyncio
53+
@pytest.mark.parametrize(
54+
"book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]
55+
)
56+
async def test_highlight_box_opens_on_double_click(
57+
chrome_page, base_url, book_slug, page_slug, rex_user, rex_password
58+
):
59+
60+
# GIVEN: Playwright, chromium and the rex_base_url
61+
62+
# WHEN: The Home page is fully loaded
63+
await chrome_page.goto(f"{base_url}/books/{book_slug}/pages/{page_slug}")
64+
home = HomeRex(chrome_page)
65+
66+
await home.click_login()
67+
68+
await home.fill_user_field(rex_user)
69+
await home.fill_password_field(rex_password)
70+
71+
await home.click_continue_login()
72+
73+
# THEN: Book page opens, highlight box appears, then disappears on Escape key
3674

3775
await chrome_page.keyboard.press("Escape")
3876

39-
# Adjusting the test until the expected behaviour is implemented for Escape key (to avoid test fail)
77+
await home.double_click_text()
78+
79+
assert await home.highlight_infobox.is_visible()
80+
81+
await home.double_click_highlight_infobox()
82+
4083
assert await home.highlight_box_is_visible()
41-
# await home.click_highlights_option()
42-
# assert "You have no highlights in this book" not in await home.highlights_option_page_is_empty.inner_text()
84+
85+
assert await home.highlight_box_colours_are_visible()
86+
assert await home.highlight_box_trash_icon_is_visible()
87+
88+
await home.click_highlight_box_trash_icon()
4389

4490

4591
@pytest.mark.asyncio
4692
@pytest.mark.parametrize(
4793
"book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]
4894
)
49-
async def test_highlight_box_dismiss_with_click(
95+
async def tst_highlight_is_created_without_annotation_on_enter(
5096
chrome_page, base_url, book_slug, page_slug, rex_user, rex_password
5197
):
5298

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

64110
await home.click_continue_login()
65111

66-
# THEN: Book page opens, highlight box appears, then disappears on clicking away from the box
112+
# THEN: Book page opens, highlight box appears, then disappears on Escape key
67113

68114
await chrome_page.keyboard.press("Escape")
69115

70116
await home.double_click_text()
71117

118+
assert await home.highlight_infobox.is_visible()
119+
120+
await chrome_page.keyboard.press("Enter")
121+
72122
assert await home.highlight_box_is_visible()
73123

74-
await home.click_other_text()
124+
await chrome_page.keyboard.press("Escape")
75125

76126
assert not await home.highlight_box_is_visible()
77127

128+
await chrome_page.keyboard.press("Enter")
129+
78130
await home.click_highlights_option()
79131

80132
assert (
81133
"You have no highlights in this book"
82-
in await home.highlights_option_page_is_empty.inner_text()
134+
not in await home.highlights_option_page_is_empty.inner_text()
83135
)
84136

85137

86138
@pytest.mark.asyncio
87139
@pytest.mark.parametrize(
88140
"book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]
89141
)
90-
async def test_highlight_box_click_highlights_option_after_highlighting_text(
142+
async def tst_highlight_is_created_without_annotation_on_double_click(
91143
chrome_page, base_url, book_slug, page_slug, rex_user, rex_password
92144
):
93145

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

105157
await home.click_continue_login()
106158

107-
# THEN: Book page opens, highlight box appears, then disappears on clicking the highlights option page
159+
# THEN: Book page opens, highlight box appears, then disappears on Escape key
108160

109161
await chrome_page.keyboard.press("Escape")
110162

111163
await home.double_click_text()
112164

165+
assert await home.highlight_infobox.is_visible()
166+
167+
await home.double_click_highlight_infobox()
168+
113169
assert await home.highlight_box_is_visible()
114170

171+
await chrome_page.keyboard.press("Escape")
172+
173+
assert not await home.highlight_box_is_visible()
174+
115175
await home.click_highlights_option()
116176

117177
assert (
118178
"You have no highlights in this book"
119-
in await home.highlights_option_page_is_empty.inner_text()
179+
not in await home.highlights_option_page_is_empty.inner_text()
120180
)
121-
122-
await chrome_page.keyboard.press("Escape")
123-
124-
assert not await home.highlight_box_is_visible()

playwright/e2e/ui/test_highlight_box_delete_note.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
from e2e.ui.pages.home import HomeRex
44

5-
import asyncio
6-
75

86
@pytest.mark.asyncio
9-
@pytest.mark.parametrize("book_slug, page_slug",
10-
[("astronomy-2e", "9-3-impact-craters")])
11-
async def test_highlight_box_delete_note(chrome_page, base_url, book_slug, page_slug, rex_user, rex_password):
7+
@pytest.mark.parametrize(
8+
"book_slug, page_slug", [("astronomy-2e", "9-3-impact-craters")]
9+
)
10+
async def test_small_highlight_box_delete_note(
11+
chrome_page, base_url, book_slug, page_slug, rex_user, rex_password
12+
):
1213

1314
# GIVEN: Playwright, chromium and the rex_base_url
1415

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

2425
await home.click_continue_login()
2526

26-
#THEN: Book page opens, highlight box appears, note is saved, then deleted and box disappears
27+
# THEN: Book page opens, highlight box appears, note is saved, then deleted and box disappears
2728

2829
await chrome_page.keyboard.press("Escape")
2930

3031
await home.double_click_text()
32+
await chrome_page.keyboard.press("Enter")
3133

3234
assert home.highlight_box_is_visible
3335

34-
await home.click_highlight_box_note_field()
35-
36-
await home.fill_highlight_box_note_field('autotest highlight')
36+
await home.fill_highlight_box_note_field("autotest highlight")
3737

3838
await home.click_highlight_box_save_button()
3939

playwright/e2e/ui/test_highlight_box_save_note.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ async def test_highlight_box_save_note(
3333
await home.select_text()
3434
await home.double_click_text()
3535

36+
await chrome_page.keyboard.press("Enter")
37+
3638
assert await home.highlight_box_is_visible()
3739

3840
await home.click_highlight_box_note_field()
@@ -77,8 +79,7 @@ async def test_overlapping_highlights(
7779

7880
await chrome_page.keyboard.press("Escape")
7981

80-
assert not await home.small_highlighted_note_box_is_visible()
81-
82+
await home.select_text()
8283
await home.double_click_text()
8384

8485
assert await home.overlapping_highlights_message_is_visible()
@@ -88,6 +89,8 @@ async def test_overlapping_highlights(
8889
in await home.overlapping_highlights_message.inner_text()
8990
)
9091

92+
# THEN: Delete the created highlight
93+
9194
await home.click_highlights_option()
9295
await home.click_highlights_option_page_menu()
9396

@@ -128,6 +131,8 @@ async def test_highlight_box_note_colours(
128131
await home.select_text()
129132
await home.double_click_text()
130133

134+
await chrome_page.keyboard.press("Enter")
135+
131136
assert await home.highlight_box_is_visible()
132137

133138
await home.click_highlight_box_purple_colour()
@@ -157,6 +162,8 @@ async def test_highlight_box_note_colours(
157162

158163
assert "green" in await home.highlights_option_text_colour_check_green
159164

165+
# THEN: Delete the created highlight
166+
160167
await home.click_highlights_option_page_menu()
161168

162169
await home.click_highlights_option_page_menu_delete()

0 commit comments

Comments
 (0)