package eu.ydp.empiria.player.client.module.menu;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.xml.client.Element;
import com.google.gwtmockito.GwtMockitoTestRunner;
import eu.ydp.empiria.player.client.controller.body.BodyGeneratorSocket;
import eu.ydp.empiria.player.client.controller.flow.FlowDataSupplier;
import eu.ydp.empiria.player.client.controller.report.table.ReportTable;
import eu.ydp.empiria.player.client.controller.report.table.ReportTableGenerator;
import eu.ydp.empiria.player.client.gin.factory.ReportModuleFactory;
import eu.ydp.empiria.player.client.module.ModuleSocket;
import eu.ydp.empiria.player.client.util.events.internal.bus.EventsBus;
import eu.ydp.empiria.player.client.util.events.internal.player.PlayerEvent;
import eu.ydp.empiria.player.client.util.events.internal.player.PlayerEventTypes;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import java.util.HashMap;
import java.util.Map;

import static org.mockito.Mockito.*;

@RunWith(GwtMockitoTestRunner.class)
public class MenuModuleTest {

    @InjectMocks
    private MenuModule testObj;
    @Mock
    private MenuPresenter presenter;
    @Mock
    private ReportModuleFactory reportModuleFactory;
    @Mock
    private Element element;
    @Mock
    private ModuleSocket moduleSocket;
    @Mock
    private BodyGeneratorSocket bodyGeneratorSocket;
    @Mock
    private EventsBus eventsBus;
    @Mock
    private FlowDataSupplier flowDataSupplier;
    @Mock
    private ReportTableGenerator reportTableGenerator;
    int currentPageIndex = 1;

    @Before
    public void init() {
        when(reportModuleFactory.createReportTableGenerator(bodyGeneratorSocket)).thenReturn(reportTableGenerator);
        when(flowDataSupplier.getCurrentPageIndex()).thenReturn(currentPageIndex);
    }

    @Test
    public void shouldCreateTable_onInit() {
        // given
        ReportTable reportTable = mock(ReportTable.class);
        when(reportTableGenerator.generate(element)).thenReturn(reportTable);

        // when
        testObj.initModule(element, moduleSocket, bodyGeneratorSocket);

        // then
        verify(presenter).setReportTable(reportTable);
    }

    @Test
    public void shouldHideMenu_onPlayerEvent() {
        // given
        PlayerEvent playerEvent = mock(PlayerEvent.class);
        when(playerEvent.getType()).thenReturn(PlayerEventTypes.BEFORE_FLOW);

        testObj.initModule(element, moduleSocket, bodyGeneratorSocket);

        // when
        testObj.onPlayerEvent(playerEvent);

        // then
        verify(presenter).hide();
        verify(presenter).unmarkPage(currentPageIndex);
    }

    @Test
    public void shouldMarkRow_whenPageLoaded() {
        // given
        PlayerEvent playerEvent = mock(PlayerEvent.class);
        when(playerEvent.getType()).thenReturn(PlayerEventTypes.PAGE_LOADED);

        testObj.initModule(element, moduleSocket, bodyGeneratorSocket);

        // when
        testObj.onPlayerEvent(playerEvent);

        // then
        verify(presenter).markPage(currentPageIndex);
    }
}
@@ -2301,29 +2301,26 @@
 ideMenu_
-onPlayerEvent
+beforeFlow
 () %7B%0A   
@@ -2613,32 +2613,32 @@
         // then%0A
-
         verify(p
@@ -2655,16 +2655,386 @@
 hide();%0A
+    %7D%0A%0A    @Test%0A    public void shouldUnmarkPage_beforeFlow() %7B%0A        // given%0A        PlayerEvent playerEvent = mock(PlayerEvent.class);%0A        when(playerEvent.getType()).thenReturn(PlayerEventTypes.BEFORE_FLOW);%0A%0A        testObj.initModule(element, moduleSocket, bodyGeneratorSocket);%0A%0A        // when%0A        testObj.onPlayerEvent(playerEvent);%0A%0A        // then%0A
         

test refactor