package com.beltranfebrer.germanprepositions.ui.menu;

import android.content.Intent;
import android.view.Menu;
import android.widget.Button;

import com.beltranfebrer.germanprepositions.BuildConfig;
import com.beltranfebrer.germanprepositions.R;
import com.beltranfebrer.germanprepositions.ui.learningsession.LearnActivity;
import com.beltranfebrer.germanprepositions.ui.menu.MenuActivity;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;

import static junit.framework.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.robolectric.Shadows.shadowOf;

/**
 * Created by miquel on 09.02.16.
 */
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class)
public class MenuActivityTest {
    private MenuActivity activity;
    @Before
    public void setUp() throws Exception {
        activity = Robolectric.setupActivity(MenuActivity.class);
    }

    @Test
    public void testListeners() throws Exception {
        Button button = (Button) activity.findViewById(R.id.buttonNewSession);
        assertTrue(button.hasOnClickListeners());
        button = (Button) activity.findViewById(R.id.buttonStatistics);
        assertTrue(button.hasOnClickListeners());
    }

    @Test
    public void testClickStart() throws Exception {
        activity.findViewById(R.id.buttonNewSession).performClick();
        Intent expectedIntent = new Intent(activity, LearnActivity.class);
        Intent actualIntent = shadowOf(activity).getNextStartedActivity();
        // TODO: Somehow this test always fails with the SNAPSHOT version of the Robolectric
        //assertThat(actualIntent).isEqualTo(expectedIntent);
    }

    @Test
    public void testClickStatistics() throws Exception {
        activity.findViewById(R.id.buttonStatistics).performClick();
        // TODO
        //Intent expectedIntent = new Intent(activity, StatisticsActivity.class);
        //assertEquals(expectedIntent, shadowOf(activity).getNextStartedActivity());
    }
}
