package com.mobify.astro.plugins.counterbadgeplugin;

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;

import com.mobify.astro.ActivityTestBase;
import com.mobify.astro.helpers.DimensionsServices;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;

public class BadgeViewTest extends ActivityTestBase {

    BadgeView badgeView;

    @Before
    public void setup() {
        badgeView = new BadgeView(getActivity());
    }

    @Test
    public void testContruction() {
        assertNotNull(badgeView.getBackground());
        assertEquals(DimensionsServices.spToPixels(getActivity(), 10.0f), badgeView.getTextSize(), .01);
    }

    @Test
    public void testSetBackgroundColor() {
        GradientDrawable mockGradientDrawable = mock(GradientDrawable.class);
        badgeView.badgeImage = mockGradientDrawable;

        int testColor = Color.parseColor("#112233");

        badgeView.setBackgroundColor(testColor);

        InOrder inOrder = inOrder(mockGradientDrawable);

        inOrder.verify(mockGradientDrawable, times(1)).mutate();
        inOrder.verify(mockGradientDrawable, times(1)).setColor(testColor);
    }

    @Test
    public void testSetCount() {
        String testCount = "134";
        badgeView.setCount(testCount);
        assertEquals(testCount, badgeView.getText());
    }
}
