def test_select_chapter_with_highlights_and_select_color_not_used_in_that_chapter( selenium, base_url, book_slug, page_slug): """Select chapter with highlights and a color that is not used in that chapter in MH page filters dropdown.""" # NOQA # GIVEN: Login book page book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() while book.notification_present: book.notification.got_it() book.navbar.click_login() name, email = Signup(selenium).register() book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() # AND: Highlights are present in different chapter pages data = [ ("1-1-what-is-psychology", Color.GREEN), ("1-4-careers-in-psychology", Color.BLUE), ("2-introduction", Color.PINK), ] for page, color in data: book = Content(selenium, base_url, book_slug=book_slug, page_slug=page).open() Highlight.force_highlight(book=book, by=random.choice, group=book.content.paragraphs, offset=Highlight.ENTIRE, color=color) # WHEN: Update chapter dropdown to include only one highlighted # Chapter - ch 1 remains selected my_highlights = book.toolbar.my_highlights() filterbar = my_highlights.filter_bar filterbar.toggle_chapter_dropdown_menu() filterbar.chapter_filters.chapters[2].click() # AND: Select color not used in that chapter and unselect the remaining # colors - pink remains selected filterbar.toggle_color_dropdown_menu() filterbar.color_filters.colors[1].click() filterbar.color_filters.colors[2].click() filterbar.toggle_color_dropdown_menu() # THEN: No results message is displayed assert ( my_highlights.highlights.no_results_message == "No results.Try selecting different chapter or color filters to see different results." ), "message not displayed or incorrect message when both tags are removed"
def test_keyboard_navigation_for_MH_filter_tags(selenium, base_url, book_slug, page_slug): """Keyboard navigation for the MH filter tags.""" # GIVEN: Login book page book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() while book.notification_present: book.notification.got_it() book.navbar.click_login() name, email = Signup(selenium).register() book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() # AND: Highlight 1 paragraph Highlight.force_highlight(book=book, by=random.choice, group=book.content.paragraphs, offset=Highlight.ENTIRE, color=Color.YELLOW) # AND: Open MH page my_highlights = book.toolbar.my_highlights() filterbar = my_highlights.filter_bar # WHEN: Hit tab to focus the first filter tag and hit the return key - remove chapter tag (ActionChains(selenium).send_keys(Keys.TAB * 5).send_keys( Keys.RETURN).perform()) # THEN: No results message is displayed assert ( my_highlights.highlights.no_results_message == "No results.Try selecting different chapter or color filters to see different results." ), "message not displayed or incorrect message when both tags are removed" # WHEN: Hit Tab (ActionChains(selenium).send_keys(Keys.TAB).perform()) # THEN: The 'x' button of color filter tag is focussed assert selenium.switch_to.active_element == filterbar.active_filter_tags[ 0].remove_tag_icon
def test_highlight_is_not_created_until_a_color_is_selected( selenium, base_url, book_slug, page_slug): """A highlight is not created until the highlight color is selected.""" # GIVEN: the Astronomy book section 1.0 introduction is displayed # AND: a user is logged in # AND: all content is visible book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() while book.notification_present: book.notification.got_it() book.navbar.click_login() Signup(selenium).register() book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() total_highlight_count = book.content.highlight_count # WHEN: they select some text content paragraph = random.choice(book.content.paragraphs) book.content.highlight(target=paragraph, offset=Highlight.RANDOM, color=None) new_highlight_count = book.content.highlight_count # THEN: the create note box is displayed # AND: the selected text is not a saved highlight try: book.content.highlight_box except NoSuchElementException: pytest.fail("the create note box is not open") assert(new_highlight_count == total_highlight_count), \ "a new highlight was found" total_highlight_count = book.content.highlight_count # WHEN: they select a highlight color book.content.highlight_box.toggle_color(Highlight.random_color()) new_highlight_count = book.content.highlight_count # THEN: the highlight is created assert(new_highlight_count > total_highlight_count), \ "the new highlight was not found"
def test_note_indicator_not_present_for_highlights_without_notes( selenium, base_url, book_slug, page_slug): """The note indicator is not present on highlights without notes. .. note:: The note indicator has been temporarily been replaced by off-color underlining (bottom border). """ # GIVEN: a book page is displayed # AND: a user is logged in # AND: all content is visible # AND: some content is highlighted without a note # AND: some content is highlighted with a note book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() while book.notification_present: book.notification.got_it() book.navbar.click_login() name, email = Signup(selenium).register() book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() # making a highlight requires a non-mobile window width temporarily width, height = book.get_window_size() if width < DESKTOP[0]: selenium.set_window_size(width=DESKTOP[0], height=height) paragraphs = random.sample(book.content.paragraphs, 2) book.content.highlight(target=paragraphs[0], offset=Highlight.ENTIRE, color=Highlight.random_color()) no_note = list(set(book.content.highlight_ids))[0] book.content.highlight(target=paragraphs[1], offset=Highlight.ENTIRE, color=Highlight.random_color(), note=Utilities.random_string()) _ids = book.content.highlight_ids with_note = _ids[0] if _ids[0] != no_note else _ids[1] if width != DESKTOP[0]: # reset the window width for a mobile test selenium.set_window_size(width=width, height=height) # WHEN: # THEN: the note indicator is not present on the highlight # AND: the note indicator is present on the highlight with a note no_note = book.content.get_highlight(by_id=no_note)[0] assert(not selenium.execute_script(HAS_INDICATOR, no_note)), \ "indicator found on a highlight without a note" with_note = book.content.get_highlight(by_id=with_note)[0] assert(selenium.execute_script(HAS_INDICATOR, with_note)), \ "indicator not found on a highlight with a note"
def test_clicking_on_the_note_indicator_opens_the_note_card( selenium, base_url, book_slug, page_slug): """Open the note card for various highlights with notes.""" # GIVEN: a book page is displayed # AND: a user is logged in # AND: all content is visible # AND: several types of content are highlighted with notes book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() while book.notification_present: book.notification.got_it() book.navbar.click_login() name, email = Signup(selenium).register() book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() # making a highlight requires a non-mobile window width temporarily width, height = book.get_window_size() if width < DESKTOP[0]: selenium.set_window_size(width=DESKTOP[0], height=height) highlight_options = [ (random.choice(book.content.figures_and_captions), Utilities.random_string()), (random.choice(book.content.lists), Utilities.random_string()), (random.choice(book.content.math), Utilities.random_string()), (random.choice(book.content.paragraphs), Utilities.random_string()), (random.choice(book.content.tables), Utilities.random_string()) ] highlight_list = {} for content, note in highlight_options: highlight_ids = book.content.highlight_ids book.content.highlight(target=content, offset=Highlight.ENTIRE, color=Highlight.random_color(), note=note) new_id = list(set(book.content.highlight_ids) - set(highlight_ids))[0] highlight_list[new_id] = note if width != DESKTOP[0]: # reset the window width for a mobile test selenium.set_window_size(width=width, height=height) for _id in book.content.highlight_ids: # WHEN: they select each highlight Utilities.click_option( driver=selenium, element=book.content.get_highlight(by_id=_id)[0], scroll_to=-130) # THEN: the highlight card and note are displayed try: book.content.highlight_box except NoSuchElementException: pytest.fail("the highlight note card is not open") assert(book.content.highlight_box.note == highlight_list[_id]), \ "Displayed note does not match"
def test_lengthy_highlights_summary_page_has_a_floating_back_to_top_link( selenium, base_url, book_slug, page_slug): """My Highlights and Notes summary has a floating back to top button.""" # GIVEN: a book section is displayed # AND: a user is logged in # AND: all content is visible # AND: several sections are highlighted book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() while book.notification_present: book.notification.got_it() book.navbar.click_login() name, email, password = Signup(selenium).register(True) logging.info(f'"{email.address}":"{password}"') book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() # making a highlight requires a non-mobile window width temporarily width, height = book.get_window_size() if width <= DESKTOP[0]: selenium.set_window_size(width=DESKTOP[0], height=height) for _ in range(10): Highlight.force_highlight(book=book, by=random.choice, group=book.content.paragraphs, offset=Highlight.ENTIRE, color=Highlight.random_color()) if width != DESKTOP[0]: # reset the window width for a mobile test selenium.set_window_size(width=width, height=height) # WHEN: they open the highlights summary modal # AND: the modal is scrolled down my_highlights = book.toolbar.my_highlights() initial_scroll_top = my_highlights.scroll_position within = max(initial_scroll_top * 0.01, 10.0) Utilities.scroll_to(selenium, element=my_highlights.all_highlights[-1].root) sleep(0.33) # THEN: a floating back to top button is displayed in the lower right # side of the modal assert my_highlights.scroll_position > initial_scroll_top, "modal not scrolled down" assert my_highlights.back_to_top_available, "back to top button not found" # WHEN: they click the back to top button my_highlights = my_highlights.back_to_top() # THEN: the modal is scrolled to the top # AND: the back to top button is not available return_position = my_highlights.scroll_position assert isclose(return_position, initial_scroll_top, rel_tol=within), ( r"return scroll position not within 1% of the initial scroll position " "({low} <= {target} <= {high})".format( low=initial_scroll_top - within, high=initial_scroll_top + within, target=return_position, )) assert not my_highlights.back_to_top_available, "back to top button still available"
def test_my_highlights_summary_shows_all_types_of_content( selenium, base_url, book_slug, page_slug): """My Highlights and Notes summary shows all types of page content.""" # GIVEN: the Chemistry 2e book section 1.4 is displayed # AND: a user is logged in # AND: all content is visible # AND: a long text paragraph, an image, a figure description, a bulleted # or numbered list, a table, a footnote, a link, and a rendered math # equation are highlighted book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() while book.notification_present: book.notification.got_it() book.navbar.click_login() name, email, password = Signup(selenium).register(True) logging.info(f'"{email.address}":"{password}"') book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() # making a highlight requires a non-mobile window width temporarily width, height = book.get_window_size() if width <= DESKTOP[0]: selenium.set_window_size(width=DESKTOP[0], height=height) Highlight.force_highlight(book=book, by=random.choice, group=book.content.paragraphs, offset=Highlight.ENTIRE, color=Highlight.random_color(), name="Paragraph") Highlight.force_highlight(book=book, by=random.choice, group=book.content.images, offset=Highlight.ENTIRE, color=Highlight.random_color(), name="Image") Highlight.force_highlight(book=book, by=random.choice, group=book.content.figures, offset=Highlight.ENTIRE, color=Highlight.random_color(), name="Figure") Highlight.force_highlight(book=book, by=random.choice, group=book.content.captions, offset=Highlight.ENTIRE, color=Highlight.random_color(), name="Caption") Highlight.force_highlight(book=book, by=random.choice, group=book.content.lists, offset=Highlight.ENTIRE, color=Highlight.random_color(), name="List") Highlight.force_highlight(book=book, by=random.choice, group=book.content.tables, offset=Highlight.ENTIRE, color=Highlight.random_color(), name="Table") Highlight.force_highlight(book=book, by=random.choice, group=book.content.footnotes, offset=Highlight.ENTIRE, color=Highlight.random_color(), name="Footnote") Highlight.force_highlight(book=book, by=random.choice, group=book.content.links, offset=Highlight.ENTIRE, color=Highlight.random_color(), name="Link") Highlight.force_highlight(book=book, by=random.choice, group=book.content.math, offset=Highlight.ENTIRE, color=Highlight.random_color(), name="Math") highlight_ids = set(book.content.highlight_ids) if width != DESKTOP[0]: # reset the window width for a mobile test selenium.set_window_size(width=width, height=height) # WHEN: they click on the My highlights button my_highlights = book.toolbar.my_highlights() # THEN: the My Highlights and Notes modal is displayed # AND: all of the highlighted content is displayed in the summary page assert book.my_highlights_open, "My Highlights modal not open" assert my_highlights.root.is_displayed( ), "My Highlights modal not displayed" summary_highlights = len(my_highlights.all_highlights) assert summary_highlights == len(highlight_ids), ( "number of summary highlights different from page highlights " f"(found {summary_highlights}, expected {len(highlight_ids)})")
def test_no_results_message_in_MH_filter_tags(selenium, base_url, book_slug, page_slug): """No results message when removing filter tags.""" # GIVEN: Login book page book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() while book.notification_present: book.notification.got_it() book.navbar.click_login() name, email = Signup(selenium).register() book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() # AND: Highlight 1 paragraph Highlight.force_highlight(book=book, by=random.choice, group=book.content.paragraphs, offset=Highlight.ENTIRE, color=Color.YELLOW) my_highlights = book.toolbar.my_highlights() filterbar = my_highlights.filter_bar # WHEN: Remove the chapter tag x = filterbar.active_filter_tags x[0].remove_tag() # THEN: No results message is displayed assert ( my_highlights.highlights.no_results_message == "No results.Try selecting different chapter or color filters to see different results." ), "message not displayed or incorrect message when chapter tag is removed" # WHEN: Remove the color tag selenium.refresh() my_highlights = book.toolbar.my_highlights() filterbar = my_highlights.filter_bar x = filterbar.active_filter_tags x[1].remove_tag() # THEN: No results message is displayed assert ( my_highlights.highlights.no_results_message == "No results.Try selecting different chapter or color filters to see different results." ), "message not displayed or incorrect message when color tag is removed" # WHEN: Remove both tags selenium.refresh() my_highlights = book.toolbar.my_highlights() filterbar = my_highlights.filter_bar x = filterbar.active_filter_tags x[0].remove_tag() x[1].remove_tag() # THEN: No results message is displayed assert ( my_highlights.highlights.no_results_message == "No results.Try selecting different chapter or color filters to see different results." ), "message not displayed or incorrect message when both tags are removed"
def test_keyboard_navigation_for_MH_dropdown_filters(selenium, base_url, book_slug, page_slug): """Keyboard navigation for the MH dropdown filters.""" # GIVEN: Login book page book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() while book.notification_present: book.notification.got_it() book.navbar.click_login() name, email = Signup(selenium).register() book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() # AND: Highlight 1 paragraph Highlight.force_highlight(book=book, by=random.choice, group=book.content.paragraphs, offset=Highlight.ENTIRE, color=Color.YELLOW) content_highlight_ids = list(book.content.highlight_ids) # AND: Open MH page my_highlights = book.toolbar.my_highlights() mh_highlight_ids = my_highlights.highlights.mh_highlight_ids filterbar = my_highlights.filter_bar # WHEN: Hit tab twice and hit the return key (ActionChains(selenium).send_keys(Keys.TAB * 2).send_keys( Keys.RETURN).perform()) # THEN: Chapter dropdown is open assert filterbar.chapter_dropdown_open # WHEN: Tab to None in the chapter dropdown and hit Enter (ActionChains(selenium).send_keys(Keys.TAB * 2).send_keys( Keys.ENTER).perform()) # THEN: No results message is displayed assert ( my_highlights.highlights.no_results_message == "No results.Try selecting different chapter or color filters to see different results." ), "message not displayed or incorrect message when both tags are removed" # WHEN: Tab to All in chapter dropdown and hit Enter (ActionChains(selenium).send_keys( Keys.SHIFT, Keys.TAB, Keys.SHIFT).send_keys(Keys.ENTER).perform()) # THEN: MH page displays the highlights made in content page assert mh_highlight_ids == content_highlight_ids # WHEN: Tab to a selected chapter and hit spacebar to remove the selection (ActionChains(selenium).send_keys(Keys.TAB * 2).send_keys( Keys.SPACE).perform()) # THEN: No results message is displayed assert ( my_highlights.highlights.no_results_message == "No results.Try selecting different chapter or color filters to see different results." ), "message not displayed or incorrect message when both tags are removed" # WHEN: Hit spacebar again to select the chapter (ActionChains(selenium).send_keys(Keys.SPACE).perform()) # THEN: MH page displays the highlights made in content page assert mh_highlight_ids == content_highlight_ids # WHEN: Tab to color filter and hit Return (ActionChains(selenium).send_keys(Keys.TAB).send_keys( Keys.RETURN).perform()) # THEN: Color dropdown is open assert filterbar.color_dropdown_open # AND: Chapter dropdown is closed assert not filterbar.chapter_dropdown_open # WHEN: Tab to None in color dropdown and hit Enter (ActionChains(selenium).send_keys(Keys.TAB * 2).send_keys( Keys.ENTER).perform()) # THEN: No results message is displayed assert ( my_highlights.highlights.no_results_message == "No results.Try selecting different chapter or color filters to see different results." ), "message not displayed or incorrect message when both tags are removed" # WHEN: Tab to All in Color dropdown and hit Enter (ActionChains(selenium).send_keys( Keys.SHIFT, Keys.TAB, Keys.SHIFT).send_keys(Keys.ENTER).perform()) # THEN: MH page displays the highlights made in content page assert mh_highlight_ids == content_highlight_ids # WHEN: Tab to a selected color and hit spacebar to remove the selection (ActionChains(selenium).send_keys(Keys.TAB * 2).send_keys( Keys.SPACE).perform()) # THEN: No results message is displayed assert ( my_highlights.highlights.no_results_message == "No results.Try selecting different chapter or color filters to see different results." ), "message not displayed or incorrect message when both tags are removed" # WHEN: Hit spacebar again to select the color (ActionChains(selenium).send_keys(Keys.SPACE).perform()) sleep(0.25) # THEN: MH page displays the highlights made in content page assert mh_highlight_ids == content_highlight_ids # WHEN: Hit Tab (ActionChains(selenium).send_keys(Keys.TAB).perform()) # THEN: Print icon is focussed assert selenium.switch_to.active_element == filterbar.print # AND: Color dropdown is closed assert not filterbar.color_dropdown_open
def test_chapter_filter_collapses_on_clicking_color_filter( selenium, base_url, book_slug, page_slug): """Clicking on a filter dropdown will close the other filter dropdown if open.""" sections = [("4.2", "Proteobacteria"), ("", "Introduction")] # GIVEN: Login book page book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() while book.notification_present: book.notification.got_it() book.navbar.click_login() name, email = Signup(selenium).register() book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() my_highlights = book.toolbar.my_highlights() mh_highlight_ids = my_highlights.highlights.mh_highlight_ids # AND: Highlights are present in different chapter pages data = [ ("1-3-types-of-microorganisms", Color.GREEN), ("2-4-staining-microscopic-specimens", Color.BLUE), ("4-2-proteobacteria", Color.YELLOW), ("5-introduction", Color.PINK), ] for page, color in data: book = Content(selenium, base_url, book_slug=book_slug, page_slug=page).open() Highlight.force_highlight(book=book, by=random.choice, group=book.content.paragraphs, offset=Highlight.ENTIRE, color=color) my_highlights = book.toolbar.my_highlights() mh_highlight_ids = mh_highlight_ids + list( set(my_highlights.highlights.mh_highlight_ids) - set(mh_highlight_ids)) filterbar = my_highlights.filter_bar last_two_highlights = (mh_highlight_ids[2], mh_highlight_ids[3]) # AND: Open chapter dropdown to remove one chapter filterbar.toggle_chapter_dropdown_menu() filterbar.chapter_filters.chapters[2].click() # AND: Do not close the chapter dropdown assert filterbar.chapter_dropdown_open # WHEN: Open color dropdown filterbar.toggle_color_dropdown_menu() # THEN: Color dropdown is opened assert filterbar.color_dropdown_open # AND: Chapter dropdown is closed automatically assert not filterbar.chapter_dropdown_open # WHEN: Remove one color from color dropdown filterbar.color_filters.colors[1].click() sleep(0.25) # THEN: The selections made in the filters are applied to the highlight list immediately highlight_sections = [(section.number, section.title) for section in my_highlights.highlights.sections] assert set(highlight_sections) == set( sections), "mismatched section numbers and/or names" assert len(my_highlights.all_highlights) == 2, ( "unexpected number of highlights found on the summary page (" f"found {len(my_highlights.all_highlights)}") assert set( my_highlights.highlights.mh_highlight_ids) == set(last_two_highlights)
def test_filter_state_not_preserved_for_MH_in_new_tab(selenium, base_url, book_slug, page_slug): """Filter state is not preserved if MH page is opened in a new tab.""" # GIVEN: Login book page book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() toolbar = book.toolbar toc = book.sidebar.toc while book.notification_present: book.notification.got_it() book.navbar.click_login() name, email = Signup(selenium).register() book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() content_highlight_ids = book.content.highlight_ids my_highlights = book.toolbar.my_highlights() mh_highlight_ids = my_highlights.highlights.mh_highlight_ids # AND: Highlights are present in different chapter pages page_slug = [ "1-3-types-of-microorganisms", "2-4-staining-microscopic-specimens", "4-2-proteobacteria", "5-introduction", ] for page in page_slug: book = Content(selenium, base_url, book_slug=book_slug, page_slug=page).open() Highlight.force_highlight(book=book, by=random.choice, group=book.content.paragraphs, offset=Highlight.ENTIRE, color=Highlight.random_color()) content_highlight_ids = content_highlight_ids + list( set(book.content.highlight_ids) - set(content_highlight_ids)) my_highlights = book.toolbar.my_highlights() mh_highlight_ids = mh_highlight_ids + list( set(my_highlights.highlights.mh_highlight_ids) - set(mh_highlight_ids)) # THEN: MH page displays all the content highlights assert mh_highlight_ids == content_highlight_ids # WHEN: Change the MH chapter filters to remove 2 chapters my_highlights = book.toolbar.my_highlights() filterbar = my_highlights.filter_bar # Use chapter dropdown to remove one chapter filterbar.toggle_chapter_dropdown_menu() filterbar.chapter_filters.chapters[2].click() filterbar.toggle_chapter_dropdown_menu() # Use filter tag to remove one chapter x = filterbar.active_filter_tags x[1].remove_tag() my_highlights = book.toolbar.my_highlights() mh_filtered_list = my_highlights.highlights.mh_highlight_ids my_highlights.close() # AND: Open MH page from a chapter that does not have highlights if book.is_mobile: toolbar.click_toc_toggle_button() toc.expand_chapter(-3) toc.sections[-40].click() my_highlights = book.toolbar.my_highlights() mh_list_from_chapter_without_highlights = my_highlights.highlights.mh_highlight_ids # THEN: Filter changes made earlier are retained assert set(mh_list_from_chapter_without_highlights) == set( mh_filtered_list) # WHEN: Open MH page in new tab book.open_new_tab() book.switch_to_window(1) page_slug = "2-4-staining-microscopic-specimens" book1 = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() my_highlights_1 = book1.toolbar.my_highlights() # THEN: MH page in the new tab displays highlights from all the chapters mh_list_in_new_tab = my_highlights_1.highlights.mh_highlight_ids assert set(mh_list_in_new_tab) == set(content_highlight_ids)
def test_filter_state_preserved_throughout_session(selenium, base_url, book_slug, page_slug): """Filter state preserved throughout the session irrespective of chapter/section navigation.""" # GIVEN: Login book page book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() toolbar = book.toolbar toc = book.sidebar.toc while book.notification_present: book.notification.got_it() book.navbar.click_login() name, email = Signup(selenium).register() book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() content_highlight_ids = book.content.highlight_ids my_highlights = book.toolbar.my_highlights() mh_highlight_ids = my_highlights.highlights.mh_highlight_ids # AND: Highlights are present in different chapter pages page_slug = [ "1-3-types-of-microorganisms", "2-4-staining-microscopic-specimens", "4-2-proteobacteria", "5-introduction", ] for page in page_slug: book = Content(selenium, base_url, book_slug=book_slug, page_slug=page).open() Highlight.force_highlight(book=book, by=random.choice, group=book.content.paragraphs, offset=Highlight.ENTIRE, color=Highlight.random_color()) content_highlight_ids = content_highlight_ids + list( set(book.content.highlight_ids) - set(content_highlight_ids)) my_highlights = book.toolbar.my_highlights() mh_highlight_ids = mh_highlight_ids + list( set(my_highlights.highlights.mh_highlight_ids) - set(mh_highlight_ids)) # THEN: MH page displays all the content highlights assert mh_highlight_ids == content_highlight_ids # WHEN: Change the MH chapter filters to remove 2 chapters my_highlights = book.toolbar.my_highlights() filterbar = my_highlights.filter_bar # Use chapter dropdown to remove one chapter filterbar.toggle_chapter_dropdown_menu() filterbar.chapter_filters.chapters[2].click() filterbar.toggle_chapter_dropdown_menu() # Use filter tag to remove one chapter x = filterbar.active_filter_tags x[1].remove_tag() my_highlights = book.toolbar.my_highlights() mh_filtered_list = my_highlights.highlights.mh_highlight_ids my_highlights.close() # AND: Open MH page from a chapter page that has highlights but removed via MH filter if book.is_mobile: toolbar.click_toc_toggle_button() toc.expand_chapter(2) toc.sections[14].click() my_highlights = book.toolbar.my_highlights() mh_list_from_chapter_with_highlights = my_highlights.highlights.mh_highlight_ids # THEN: Filter changes made earlier are retained assert set(mh_list_from_chapter_with_highlights) == set(mh_filtered_list) my_highlights.close() # WHEN: Open MH page from a chapter that does not have highlights if book.is_mobile: toolbar.click_toc_toggle_button() toc.expand_chapter(-3) toc.sections[-40].click() my_highlights = book.toolbar.my_highlights() mh_list_from_chapter_without_highlights = my_highlights.highlights.mh_highlight_ids # THEN: Filter changes made earlier are retained assert set(mh_list_from_chapter_without_highlights) == set( mh_filtered_list) # WHEN: Re-add one of the removed chapter filterbar = my_highlights.filter_bar filterbar.toggle_chapter_dropdown_menu() filterbar.chapter_filters.chapters[2].click() filterbar.toggle_chapter_dropdown_menu() mh_updated_filtered_list = my_highlights.highlights.mh_highlight_ids my_highlights.close() # AND: Navigate to another chapter if book.is_mobile: toolbar.click_toc_toggle_button() toc.expand_chapter(0) toc.sections[4].click() # THEN: The MH list is updated with the highlight from re-added chapter my_highlights = book.toolbar.my_highlights() mh_list_after_page_navigation = my_highlights.highlights.mh_highlight_ids assert set(mh_list_after_page_navigation) == set(mh_updated_filtered_list) # WHEN: Reload the page book.reload() # THEN: MH filters resets to display highlights from all the chapters my_highlights = book.toolbar.my_highlights() mh_list_after_reload = my_highlights.highlights.mh_highlight_ids assert set(mh_list_after_reload) == set(content_highlight_ids)
def test_no_results_message_in_MH_dropdown_filter(selenium, base_url, book_slug, page_slug): """No results message when selecting None in either or both chapter & color filters.""" # GIVEN: Login book page book = Content(selenium, base_url, book_slug=book_slug, page_slug=page_slug).open() while book.notification_present: book.notification.got_it() book.navbar.click_login() name, email = Signup(selenium).register() book.wait_for_page_to_load() while book.notification_present: book.notification.got_it() book.content.show_solutions() # AND: Highlight 1 paragraph Highlight.force_highlight(book=book, by=random.choice, group=book.content.paragraphs, offset=Highlight.ENTIRE, color=Color.YELLOW) my_highlights = book.toolbar.my_highlights() # WHEN: Select None in Chapter filter filterbar = my_highlights.filter_bar filterbar.toggle_chapter_dropdown_menu() filterbar.chapter_filters.select_none() filterbar.toggle_chapter_dropdown_menu() # THEN: No results message is displayed assert ( my_highlights.highlights.no_results_message == "No results.Try selecting different chapter or color filters to see different results." ), "message not displayed or incorrect message when None is selected in chapter filter" # WHEN: Select None in Color filter selenium.refresh() my_highlights = book.toolbar.my_highlights() filterbar = my_highlights.filter_bar filterbar.toggle_color_dropdown_menu() filterbar.color_filters.select_none() filterbar.toggle_color_dropdown_menu() # THEN: No results message is displayed assert ( my_highlights.highlights.no_results_message == "No results.Try selecting different chapter or color filters to see different results." ), "message not displayed or incorrect message when None is selected in Color filter" # WHEN: Select None in both filters selenium.refresh() my_highlights = book.toolbar.my_highlights() filterbar = my_highlights.filter_bar filterbar.toggle_chapter_dropdown_menu() filterbar.chapter_filters.select_none() filterbar.toggle_chapter_dropdown_menu() filterbar.toggle_color_dropdown_menu() filterbar.color_filters.select_none() filterbar.toggle_color_dropdown_menu() # THEN: No results message is displayed assert ( my_highlights.highlights.no_results_message == "No results.Try selecting different chapter or color filters to see different results." ), "message not displayed or incorrect message when None is selected in both filters"