'Scenario: the list of topics should remain sorted after updates
Given I am enrolled in a course with team configuration and topics
When I visit the Teams page
And I browse topics and choose a sort order
Then I should see the paginated list of topics in that order
When I create a team in one of those topics
And I return to the topics list
Then I should see the topics in the correct sorted order'

def test_sort_topics_update(self):

    topics = self.create_topics(3)
    self.set_team_configuration({u'max_team_size': 100, u'topics': topics})
    self.topics_page.visit()
    self.topics_page.sort_topics_by('team_count')
    topic_name = self.topics_page.topic_names[(-1)]
    topic = [t for t in topics if (t['name'] == topic_name)][0]
    self.topics_page.browse_teams_for_topic(topic_name)
    browse_teams_page = BrowseTeamsPage(self.browser, self.course_id, topic)
    browse_teams_page.wait_for_page()
    browse_teams_page.click_create_team_link()
    create_team_page = TeamManagementPage(self.browser, self.course_id, topic)
    create_team_page.create_team()
    team_page = TeamPage(self.browser, self.course_id)
    team_page.wait_for_page()
    team_page.click_all_topics()
    self.topics_page.wait_for_page()
    self.topics_page.wait_for_ajax()
    self.assertEqual(topic_name, self.topics_page.topic_names[0])
