package io.trustbuilder.mfa.android.demoapp.utils;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import android.app.AlertDialog;
import android.content.Context;
import android.text.InputType;
import android.widget.EditText;
import android.widget.TextView;

import androidx.test.core.app.ApplicationProvider;

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

@RunWith(RobolectricTestRunner.class)
public class UiUtilsTest {

    private Context context;

    @Before
    public void setup() {
        context = ApplicationProvider.getApplicationContext();
    }

    @Test
    public void testCreateSecretCodeDefinitionAlertDialogBuilder() {
        AlertDialog dialog = UiUtils
                .createSecretCodeDefinitionAlertDialogBuilder(context)
                .create();

        dialog.show();

        TextView titleView = dialog.findViewById(
                context.getResources().getIdentifier("alertTitle", "id", "android")
        );

        assertNotNull(titleView);
        assertEquals("Define your secret code", titleView.getText().toString());
    }

    @Test
    public void testCreateSecretCodeValidationAlertDialogBuilder() {
        AlertDialog dialog = UiUtils
                .createSecretCodeValidationAlertDialogBuilder(context)
                .create();

        dialog.show();

        TextView titleView = dialog.findViewById(
                context.getResources().getIdentifier("alertTitle", "id", "android")
        );

        assertNotNull(titleView);
        assertEquals("Enter your secret code", titleView.getText().toString());
    }

    @Test
    public void testCreateSecretCodeEditText_inputType() {
        EditText editText = UiUtils.createSecretCodeEditText(context);

        int expected = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;

        assertEquals(expected, editText.getInputType());
    }
}
