package com.sw_ss16.lc_app.ui.tests;

import android.test.ActivityInstrumentationTestCase2;

import com.robotium.solo.Solo;
import com.sw_ss16.lc_app.R;
import com.sw_ss16.lc_app.ui.learning_center_list.ListActivity;

/**
 * Starts from the ListActivity, but opens the StudyRoomDetailActivity
 */
public class StudyRoomDetailTest extends ActivityInstrumentationTestCase2<ListActivity> {

    private Solo mySolo;

    public StudyRoomDetailTest() {
        super(ListActivity.class);
    }

    public void setUp() throws Exception {
        super.setUp();
        mySolo = new Solo(getInstrumentation(), getActivity());

    }

    public void tearDown() throws Exception {
        mySolo.finishOpenedActivities();
        super.tearDown();
    }

    public void testStudyRoomDetailFavorite() {
        mySolo.sleep(500);
        // If there are any items in the list
        // The second argument of searchText means it searches only for visible text (not hidden)
        if (!mySolo.searchText(getActivity().getString(R.string.no_fav), true)) {
            // Click on first list item
            mySolo.clickInList(1);

            // Look for text in study room detail activity
            mySolo.waitForActivity("StudyRoomDetailActivity");
            boolean text_found = mySolo.searchText("Statistics");
            assertEquals("Required text not found", true, text_found);

            boolean already_fav = mySolo.getCurrentActivity().getResources().getDrawable(R.drawable.ic_remove_white_24dp).isVisible();
            // Click on floating action button
            mySolo.clickOnView(mySolo.getView(R.id.fav_fab_btn));
            boolean image_shown = false;
            if (already_fav) {
                image_shown = mySolo.getCurrentActivity().getResources().getDrawable(R.drawable.ic_add_white_24dp).isVisible();
            }
            else {
                image_shown = mySolo.getCurrentActivity().getResources().getDrawable(R.drawable.ic_remove_white_24dp).isVisible();
            }

            assertEquals("Required image not found", true, image_shown);
        }
    }
}

@@ -146,16 +146,184 @@
 _app.R;%0A
+import com.sw_ss16.lc_app.content.LearningCenter;%0Aimport com.sw_ss16.lc_app.content.LearningCenterDefroster;%0Aimport com.sw_ss16.lc_app.content.LearningCenterDefroster;%0A
 import c
@@ -379,16 +379,40 @@
 ivity;%0A%0A
+import java.util.List;%0A%0A
 /**%0A * S
@@ -2271,16 +2271,1332 @@
 shown);%0A
+        %7D%0A        else %7B%0A            mySolo.clickOnImageButton(0);%0A%0A            LearningCenterDefroster lc_contentmanager = new LearningCenterDefroster();%0A            lc_contentmanager.setApplicationContext(getActivity().getApplicationContext());%0A            List%3CString%3E listOfLcIds = lc_contentmanager.getListOfLcIds();%0A%0A            LearningCenter LC = lc_contentmanager.getLcObject(listOfLcIds.get(0));%0A%0A            System.out.println(%22Click on: %22 + LC.name);%0A%0A            //mySolo.clickOnMenuItem(LC.name.toString());%0A            //mySolo.clickOnButton(LC.name.toString());%0A            mySolo.clickOnText(LC.name.toString());%0A            mySolo.sleep(500);%0A%0A            mySolo.clickOnView(mySolo.getView(R.id.fav_fab_btn));%0A            boolean image_shown = false;%0A            boolean already_fav = mySolo.getCurrentActivity().getResources().getDrawable(R.drawable.ic_remove_white_24dp).isVisible();%0A            if (already_fav) %7B%0A                image_shown = mySolo.getCurrentActivity().getResources().getDrawable(R.drawable.ic_add_white_24dp).isVisible();%0A            %7D%0A            else %7B%0A                image_shown = mySolo.getCurrentActivity().getResources().getDrawable(R.drawable.ic_remove_white_24dp).isVisible();%0A            %7D%0A%0A            assertEquals(%22Required image not found%22, true, image_shown);%0A%0A
         

add renaming in tests too