'Scenario: Video component with pre-roll emits events correctly
Given the course has a Video component in "Youtube" mode with pre-roll enabled
And I click on the video poster
And the pre-roll video start playing
And I watch (5 seconds/5 seconds/to the end of) it
And I click (skip/do not show again) video button
Then a "edx.video.bumper.loaded" event is emitted
And a "edx.video.bumper.played" event is emitted
And a "edx.video.bumper.skipped/dismissed/stopped" event is emitted
And a "load_video" event is emitted
And a "play_video" event is emitted'

@ddt.data(('edx.video.bumper.skipped', watch_video_and_skip), ('edx.video.bumper.dismissed', watch_video_and_dismiss), ('edx.video.bumper.stopped', wait_for_state))
@ddt.unpack
def test_video_control_events(self, event_type, action):

    def is_video_event(event):
        'Filter    out    anything    other    than    the    video    events    of    interest'
        return ((event['event_type'] in ('edx.video.bumper.loaded', 'edx.video.bumper.played', 'edx.video.bumper.skipped', 'edx.video.bumper.dismissed', 'edx.video.bumper.stopped', 'load_video', 'play_video', 'pause_video')) and (self.video.state != 'buffering'))
    captured_events = []
    self.add_bumper()
    with self.capture_events(is_video_event, number_of_matches=5, captured_events=captured_events):
        self.navigate_to_video_no_render()
        self.video.click_on_poster()
        self.video.wait_for_video_bumper_render()
        (sources, duration) = (self.video.sources[0], self.video.duration)
        action(self)
    filtered_events = []
    for video_event in captured_events:
        is_played_event = (video_event['event_type'] == 'edx.video.bumper.played')
        appears_again = (filtered_events and (video_event['event_type'] == filtered_events[(-1)]['event_type']))
        if (is_played_event and appears_again):
            continue
        filtered_events.append(video_event)
    for (idx, video_event) in enumerate(filtered_events):
        if (idx < 3):
            self.assert_bumper_payload_contains_ids(video_event, sources, duration)
        else:
            self.assert_payload_contains_ids(video_event)
        if (idx == 0):
            assert_event_matches({'event_type': 'edx.video.bumper.loaded'}, video_event)
        elif (idx == 1):
            assert_event_matches({'event_type': 'edx.video.bumper.played'}, video_event)
            self.assert_valid_control_event_at_time(video_event, 0)
        elif (idx == 2):
            assert_event_matches({'event_type': event_type}, video_event)
        elif (idx == 3):
            assert_event_matches({'event_type': 'load_video'}, video_event)
        elif (idx == 4):
            assert_event_matches({'event_type': 'play_video'}, video_event)
            self.assert_valid_control_event_at_time(video_event, 0)
