Add searching to the teams view
TNL-1935
This commit is contained in:
@@ -142,6 +142,11 @@ class BrowseTopicsPage(CoursePage, PaginatedUIMixin):
|
||||
"""Return a list of the topic names present on the page."""
|
||||
return self.q(css=CARD_TITLE_CSS).map(lambda e: e.text).results
|
||||
|
||||
@property
|
||||
def topic_descriptions(self):
|
||||
"""Return a list of the topic descriptions present on the page."""
|
||||
return self.q(css='p.card-description').map(lambda e: e.text).results
|
||||
|
||||
def browse_teams_for_topic(self, topic_name):
|
||||
"""
|
||||
Show the teams list for `topic_name`.
|
||||
@@ -159,36 +164,32 @@ class BrowseTopicsPage(CoursePage, PaginatedUIMixin):
|
||||
self.wait_for_ajax()
|
||||
|
||||
|
||||
class BrowseTeamsPage(CoursePage, PaginatedUIMixin, TeamCardsMixin):
|
||||
class BaseTeamsPage(CoursePage, PaginatedUIMixin, TeamCardsMixin):
|
||||
"""
|
||||
The paginated UI for browsing teams within a Topic on the Teams
|
||||
page.
|
||||
"""
|
||||
def __init__(self, browser, course_id, topic):
|
||||
"""
|
||||
Set up `self.url_path` on instantiation, since it dynamically
|
||||
reflects the current topic. Note that `topic` is a dict
|
||||
representation of a topic following the same convention as a
|
||||
course module's topic.
|
||||
Note that `topic` is a dict representation of a topic following
|
||||
the same convention as a course module's topic.
|
||||
"""
|
||||
super(BrowseTeamsPage, self).__init__(browser, course_id)
|
||||
super(BaseTeamsPage, self).__init__(browser, course_id)
|
||||
self.topic = topic
|
||||
self.url_path = "teams/#topics/{topic_id}".format(topic_id=self.topic['id'])
|
||||
|
||||
def is_browser_on_page(self):
|
||||
"""Check if we're on the teams list page for a particular topic."""
|
||||
self.wait_for_element_presence('.team-actions', 'Wait for the bottom links to be present')
|
||||
"""Check if we're on a teams list page for a particular topic."""
|
||||
has_correct_url = self.url.endswith(self.url_path)
|
||||
teams_list_view_present = self.q(css='.teams-main').present
|
||||
return has_correct_url and teams_list_view_present
|
||||
|
||||
@property
|
||||
def header_topic_name(self):
|
||||
def header_name(self):
|
||||
"""Get the topic name displayed by the page header"""
|
||||
return self.q(css=TEAMS_HEADER_CSS + ' .page-title')[0].text
|
||||
|
||||
@property
|
||||
def header_topic_description(self):
|
||||
def header_description(self):
|
||||
"""Get the topic description displayed by the page header"""
|
||||
return self.q(css=TEAMS_HEADER_CSS + ' .page-description')[0].text
|
||||
|
||||
@@ -229,6 +230,48 @@ class BrowseTeamsPage(CoursePage, PaginatedUIMixin, TeamCardsMixin):
|
||||
).click()
|
||||
self.wait_for_ajax()
|
||||
|
||||
@property
|
||||
def _showing_search_results(self):
|
||||
"""
|
||||
Returns true if showing search results.
|
||||
"""
|
||||
return self.header_description.startswith(u"Showing results for")
|
||||
|
||||
def search(self, string):
|
||||
"""
|
||||
Searches for the specified string, and returns a SearchTeamsPage
|
||||
representing the search results page.
|
||||
"""
|
||||
self.q(css='.search-field').first.fill(string)
|
||||
self.q(css='.action-search').first.click()
|
||||
self.wait_for(
|
||||
lambda: self._showing_search_results,
|
||||
description="Showing search results"
|
||||
)
|
||||
page = SearchTeamsPage(self.browser, self.course_id, self.topic)
|
||||
page.wait_for_page()
|
||||
return page
|
||||
|
||||
|
||||
class BrowseTeamsPage(BaseTeamsPage):
|
||||
"""
|
||||
The paginated UI for browsing teams within a Topic on the Teams
|
||||
page.
|
||||
"""
|
||||
def __init__(self, browser, course_id, topic):
|
||||
super(BrowseTeamsPage, self).__init__(browser, course_id, topic)
|
||||
self.url_path = "teams/#topics/{topic_id}".format(topic_id=self.topic['id'])
|
||||
|
||||
|
||||
class SearchTeamsPage(BaseTeamsPage):
|
||||
"""
|
||||
The paginated UI for showing team search results.
|
||||
page.
|
||||
"""
|
||||
def __init__(self, browser, course_id, topic):
|
||||
super(SearchTeamsPage, self).__init__(browser, course_id, topic)
|
||||
self.url_path = "teams/#topics/{topic_id}/search".format(topic_id=self.topic['id'])
|
||||
|
||||
|
||||
class CreateOrEditTeamPage(CoursePage, FieldsMixin):
|
||||
"""
|
||||
|
||||
@@ -444,7 +444,7 @@ class BrowseTopicsTest(TeamsTabBase):
|
||||
{u"max_team_size": 1, u"topics": [{"name": "", "id": "", "description": initial_description}]}
|
||||
)
|
||||
self.topics_page.visit()
|
||||
truncated_description = self.topics_page.topic_cards[0].text
|
||||
truncated_description = self.topics_page.topic_descriptions[0]
|
||||
self.assertLess(len(truncated_description), len(initial_description))
|
||||
self.assertTrue(truncated_description.endswith('...'))
|
||||
self.assertIn(truncated_description.split('...')[0], initial_description)
|
||||
@@ -467,8 +467,8 @@ class BrowseTopicsTest(TeamsTabBase):
|
||||
self.topics_page.browse_teams_for_topic('Example Topic')
|
||||
browse_teams_page = BrowseTeamsPage(self.browser, self.course_id, topic)
|
||||
self.assertTrue(browse_teams_page.is_browser_on_page())
|
||||
self.assertEqual(browse_teams_page.header_topic_name, 'Example Topic')
|
||||
self.assertEqual(browse_teams_page.header_topic_description, 'Description')
|
||||
self.assertEqual(browse_teams_page.header_name, 'Example Topic')
|
||||
self.assertEqual(browse_teams_page.header_description, 'Description')
|
||||
|
||||
|
||||
@attr('shard_5')
|
||||
@@ -503,15 +503,24 @@ class BrowseTeamsWithinTopicTest(TeamsTabBase):
|
||||
|
||||
def verify_page_header(self):
|
||||
"""Verify that the page header correctly reflects the current topic's name and description."""
|
||||
self.assertEqual(self.browse_teams_page.header_topic_name, self.topic['name'])
|
||||
self.assertEqual(self.browse_teams_page.header_topic_description, self.topic['description'])
|
||||
self.assertEqual(self.browse_teams_page.header_name, self.topic['name'])
|
||||
self.assertEqual(self.browse_teams_page.header_description, self.topic['description'])
|
||||
|
||||
def verify_on_page(self, page_num, total_teams, pagination_header_text, footer_visible):
|
||||
def verify_search_header(self, search_results_page, search_query):
|
||||
"""Verify that the page header correctly reflects the current topic's name and description."""
|
||||
self.assertEqual(search_results_page.header_name, 'Team Search')
|
||||
self.assertEqual(
|
||||
search_results_page.header_description,
|
||||
'Showing results for "{search_query}"'.format(search_query=search_query)
|
||||
)
|
||||
|
||||
def verify_on_page(self, teams_page, page_num, total_teams, pagination_header_text, footer_visible):
|
||||
"""
|
||||
Verify that we are on the correct team list page.
|
||||
|
||||
Arguments:
|
||||
page_num (int): The one-indexed page we expect to be on
|
||||
teams_page (BaseTeamsPage): The teams page object that should be the current page.
|
||||
page_num (int): The one-indexed page number that we expect to be on
|
||||
total_teams (list): An unsorted list of all the teams for the
|
||||
current topic
|
||||
pagination_header_text (str): Text we expect to see in the
|
||||
@@ -520,13 +529,13 @@ class BrowseTeamsWithinTopicTest(TeamsTabBase):
|
||||
footer controls.
|
||||
"""
|
||||
sorted_teams = self.teams_with_default_sort_order(total_teams)
|
||||
self.assertTrue(self.browse_teams_page.get_pagination_header_text().startswith(pagination_header_text))
|
||||
self.assertTrue(teams_page.get_pagination_header_text().startswith(pagination_header_text))
|
||||
self.verify_teams(
|
||||
self.browse_teams_page,
|
||||
teams_page,
|
||||
sorted_teams[(page_num - 1) * self.TEAMS_PAGE_SIZE:page_num * self.TEAMS_PAGE_SIZE]
|
||||
)
|
||||
self.assertEqual(
|
||||
self.browse_teams_page.pagination_controls_visible(),
|
||||
teams_page.pagination_controls_visible(),
|
||||
footer_visible,
|
||||
msg='Expected paging footer to be ' + 'visible' if footer_visible else 'invisible'
|
||||
)
|
||||
@@ -648,11 +657,11 @@ class BrowseTeamsWithinTopicTest(TeamsTabBase):
|
||||
teams = self.create_teams(self.topic, self.TEAMS_PAGE_SIZE + 1, time_between_creation=1)
|
||||
self.browse_teams_page.visit()
|
||||
self.verify_page_header()
|
||||
self.verify_on_page(1, teams, 'Showing 1-10 out of 11 total', True)
|
||||
self.verify_on_page(self.browse_teams_page, 1, teams, 'Showing 1-10 out of 11 total', True)
|
||||
self.browse_teams_page.press_next_page_button()
|
||||
self.verify_on_page(2, teams, 'Showing 11-11 out of 11 total', True)
|
||||
self.verify_on_page(self.browse_teams_page, 2, teams, 'Showing 11-11 out of 11 total', True)
|
||||
self.browse_teams_page.press_previous_page_button()
|
||||
self.verify_on_page(1, teams, 'Showing 1-10 out of 11 total', True)
|
||||
self.verify_on_page(self.browse_teams_page, 1, teams, 'Showing 1-10 out of 11 total', True)
|
||||
|
||||
def test_teams_page_input(self):
|
||||
"""
|
||||
@@ -670,25 +679,21 @@ class BrowseTeamsWithinTopicTest(TeamsTabBase):
|
||||
teams = self.create_teams(self.topic, self.TEAMS_PAGE_SIZE + 10, time_between_creation=1)
|
||||
self.browse_teams_page.visit()
|
||||
self.verify_page_header()
|
||||
self.verify_on_page(1, teams, 'Showing 1-10 out of 20 total', True)
|
||||
self.verify_on_page(self.browse_teams_page, 1, teams, 'Showing 1-10 out of 20 total', True)
|
||||
self.browse_teams_page.go_to_page(2)
|
||||
self.verify_on_page(2, teams, 'Showing 11-20 out of 20 total', True)
|
||||
self.verify_on_page(self.browse_teams_page, 2, teams, 'Showing 11-20 out of 20 total', True)
|
||||
self.browse_teams_page.go_to_page(1)
|
||||
self.verify_on_page(1, teams, 'Showing 1-10 out of 20 total', True)
|
||||
self.verify_on_page(self.browse_teams_page, 1, teams, 'Showing 1-10 out of 20 total', True)
|
||||
|
||||
def test_navigation_links(self):
|
||||
def test_browse_team_topics(self):
|
||||
"""
|
||||
Scenario: User should be able to navigate to "browse all teams" and "search team description" links.
|
||||
Given I am enrolled in a course with a team configuration and a topic
|
||||
containing one team
|
||||
When I visit the Teams page for that topic
|
||||
Given I am enrolled in a course with teams enabled
|
||||
When I visit the Teams page for a topic
|
||||
Then I should see the correct page header
|
||||
And I should see the link to "browse all team"
|
||||
And I should navigate to that link
|
||||
And I see the relevant page loaded
|
||||
And I should see the link to "search teams"
|
||||
And I should navigate to that link
|
||||
And I see the relevant page loaded
|
||||
And I should see the link to "browse teams in other topics"
|
||||
When I should navigate to that link
|
||||
Then I should see the topic browse page
|
||||
"""
|
||||
self.browse_teams_page.visit()
|
||||
self.verify_page_header()
|
||||
@@ -696,10 +701,23 @@ class BrowseTeamsWithinTopicTest(TeamsTabBase):
|
||||
self.browse_teams_page.click_browse_all_teams_link()
|
||||
self.assertTrue(self.topics_page.is_browser_on_page())
|
||||
|
||||
def test_search(self):
|
||||
"""
|
||||
Scenario: User should be able to search for a team
|
||||
Given I am enrolled in a course with teams enabled
|
||||
When I visit the Teams page for that topic
|
||||
And I search for 'banana'
|
||||
Then I should see the search result page
|
||||
And the search header should be shown
|
||||
And 0 results should be shown
|
||||
"""
|
||||
# Note: all searches will return 0 results with the mock search server
|
||||
# used by Bok Choy.
|
||||
self.create_teams(self.topic, 5)
|
||||
self.browse_teams_page.visit()
|
||||
self.verify_page_header()
|
||||
self.browse_teams_page.click_search_team_link()
|
||||
# TODO Add search page expectation once that implemented.
|
||||
search_results_page = self.browse_teams_page.search('banana')
|
||||
self.verify_search_header(search_results_page, 'banana')
|
||||
self.assertTrue(search_results_page.get_pagination_header_text().startswith('Showing 0 out of 0 total'))
|
||||
|
||||
|
||||
@attr('shard_5')
|
||||
@@ -726,8 +744,8 @@ class TeamFormActions(TeamsTabBase):
|
||||
self.browse_teams_page.click_create_team_link()
|
||||
self.verify_page_header(
|
||||
title='Create a New Team',
|
||||
description='Create a new team if you can\'t find existing teams to '
|
||||
'join, or if you would like to learn with friends you know.',
|
||||
description='Create a new team if you can\'t find an existing team to join, '
|
||||
'or if you would like to learn with friends you know.',
|
||||
breadcrumbs='All Topics {topic_name}'.format(topic_name=self.topic['name'])
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user