'Scenario: User can leave a team.
Given I am enrolled in a course with a team configuration, a topic,
and a team belonging to that topic
And I am a member of team
And I visit the team
And I should not see Join Team button
And I should see New Post button
Then I should see Leave Team link
When I click on Leave Team link
Then user should be removed from team
And an analytics event should be emitted
And I should see Join Team button
And I should not see New Post button
And if I switch to "My Team", the team I have left is not displayed'

def test_leave_team(self):

    self._set_team_configuration_and_membership()
    self.team_page.visit()
    self.assertFalse(self.team_page.join_team_button_present)
    self.assert_team_details(num_members=1)
    expected_events = [{'event_type': 'edx.team.learner_removed', 'event': {'remove_method': 'self_removal'}}]
    with self.assert_events_match_during(event_filter=self.only_team_events, expected_events=expected_events):
        time.sleep(0.5)
        self.team_page.click_leave_team_link()
    self.assert_team_details(num_members=0, is_member=False)
    self.assertTrue(self.team_page.join_team_button_present)
    self.teams_page.click_all_topics()
    self.verify_my_team_count(0)
