package io.trustbuilder.mfa.android.demoapp;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;

import android.content.Intent;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.espresso.assertion.ViewAssertions;
import androidx.test.ext.junit.rules.ActivityScenarioRule;

import io.trustbuilder.mfa.android.demoapp.screen.PushIdRegistrationActivity;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class PushIdRegistrationActivityTest {


    @Rule
    public ActivityScenarioRule<PushIdRegistrationActivity> mLoginActivityTestRule =
    new ActivityScenarioRule<>(
        new Intent(ApplicationProvider.getApplicationContext(),
                   PushIdRegistrationActivity.class)
            .putExtra("FCM_TOKEN", "fake_token_123")
    );


    @org.junit.Test
    public void onCreate() {
        onView(withId(R.id.proceed_RegisterPushId)).check(ViewAssertions.matches(isDisplayed()));
        onView(withId(R.id.result_RegisterPushId)).check(ViewAssertions.matches(isDisplayed()));

    }

    @Test
    public void onStart() {
        onView(withId(R.id.result_RegisterPushId)).check(ViewAssertions.matches(withText("")));
        onView(withId(R.id.proceed_RegisterPushId)).perform(click());
        onView(withId(R.id.result_RegisterPushId)).check(ViewAssertions.matches(not(withText(""))));
    }

    @Test
    public void onStart_withInput() {
        onView(withId(R.id.proceed_RegisterPushId)).perform(click());
        onView(withId(R.id.result_RegisterPushId))
                .check(matches(withText(containsString("IW_TKN_IS_UNKNOWN_ERR"))));
    }
}