convert widget tests

pull/716/head
Quentin Hibon 5 years ago
parent 457c58a660
commit 228be95f9c

@ -1,95 +0,0 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets;
import android.widget.*;
import androidx.test.ext.junit.runners.*;
import androidx.test.filters.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.utils.*;
import org.junit.*;
import org.junit.runner.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.isoron.uhabits.core.models.Entry.*;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class CheckmarkWidgetTest extends BaseViewTest
{
private static final String PATH = "widgets/CheckmarkWidget/";
private Habit habit;
private EntryList entries;
private FrameLayout view;
private Timestamp today = DateUtils.getTodayWithOffset();
@Override
public void setUp()
{
super.setUp();
setTheme(R.style.WidgetTheme);
prefs.setWidgetOpacity(255);
prefs.setSkipEnabled(true);
habit = fixtures.createVeryLongHabit();
entries = habit.getComputedEntries();
CheckmarkWidget widget = new CheckmarkWidget(targetContext, 0, habit);
view = convertToView(widget, 150, 200);
assertThat(entries.get(today).getValue(), equalTo(YES_MANUAL));
}
@Test
public void testClick() throws Exception
{
Button button = (Button) view.findViewById(R.id.button);
assertThat(button, is(not(nullValue())));
// A better test would be to capture the intent, but it doesn't seem
// possible to capture intents sent to BroadcastReceivers.
button.performClick();
sleep(1000);
assertThat(entries.get(today).getValue(), equalTo(SKIP));
button.performClick();
sleep(1000);
assertThat(entries.get(today).getValue(), equalTo(NO));
}
@Test
public void testIsInstalled()
{
assertWidgetProviderIsInstalled(CheckmarkWidgetProvider.class);
}
@Test
public void testRender() throws Exception
{
assertRenders(view, PATH + "render.png");
}
}

@ -0,0 +1,89 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets
import android.view.View
import android.widget.Button
import android.widget.FrameLayout
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert
import org.isoron.uhabits.BaseViewTest
import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Entry
import org.isoron.uhabits.core.models.EntryList
import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.utils.DateUtils.Companion.getTodayWithOffset
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
@MediumTest
class CheckmarkWidgetTest : BaseViewTest() {
private lateinit var habit: Habit
private lateinit var entries: EntryList
private lateinit var view: FrameLayout
private val today = getTodayWithOffset()
override fun setUp() {
super.setUp()
setTheme(R.style.WidgetTheme)
prefs.widgetOpacity = 255
prefs.isSkipEnabled = true
habit = fixtures.createVeryLongHabit()
entries = habit.computedEntries
val widget = CheckmarkWidget(targetContext, 0, habit)
view = convertToView(widget, 150, 200)
MatcherAssert.assertThat(entries.get(today).value, CoreMatchers.equalTo(Entry.YES_MANUAL))
}
@Test
@Throws(Exception::class)
fun testClick() {
val button = view.findViewById<View>(R.id.button) as Button
MatcherAssert.assertThat(
button,
CoreMatchers.`is`(CoreMatchers.not(CoreMatchers.nullValue()))
)
// A better test would be to capture the intent, but it doesn't seem
// possible to capture intents sent to BroadcastReceivers.
button.performClick()
sleep(1000)
MatcherAssert.assertThat(entries.get(today).value, CoreMatchers.equalTo(Entry.SKIP))
button.performClick()
sleep(1000)
MatcherAssert.assertThat(entries.get(today).value, CoreMatchers.equalTo(Entry.NO))
}
@Test
fun testIsInstalled() {
assertWidgetProviderIsInstalled(CheckmarkWidgetProvider::class.java)
}
@Test
@Throws(Exception::class)
fun testRender() {
assertRenders(view, PATH + "render.png")
}
companion object {
private const val PATH = "widgets/CheckmarkWidget/"
}
}

@ -1,67 +0,0 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets;
import android.widget.*;
import androidx.test.ext.junit.runners.*;
import androidx.test.filters.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
import org.junit.*;
import org.junit.runner.*;
import java.util.*;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class FrequencyWidgetTest extends BaseViewTest
{
private static final String PATH = "widgets/FrequencyWidget/";
private Habit habit;
private FrameLayout view;
@Override
public void setUp()
{
super.setUp();
setTheme(R.style.WidgetTheme);
prefs.setWidgetOpacity(255);
habit = fixtures.createVeryLongHabit();
FrequencyWidget widget = new FrequencyWidget(targetContext, 0, habit, Calendar.SUNDAY);
view = convertToView(widget, 400, 400);
}
@Test
public void testIsInstalled()
{
assertWidgetProviderIsInstalled(FrequencyWidgetProvider.class);
}
@Test
public void testRender() throws Exception
{
assertRenders(view, PATH + "render.png");
}
}

@ -0,0 +1,59 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets
import android.widget.FrameLayout
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.isoron.uhabits.BaseViewTest
import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Habit
import org.junit.Test
import org.junit.runner.RunWith
import java.util.Calendar
@RunWith(AndroidJUnit4::class)
@MediumTest
class FrequencyWidgetTest : BaseViewTest() {
private lateinit var habit: Habit
private lateinit var view: FrameLayout
override fun setUp() {
super.setUp()
setTheme(R.style.WidgetTheme)
prefs.widgetOpacity = 255
habit = fixtures.createVeryLongHabit()
val widget = FrequencyWidget(targetContext, 0, habit, Calendar.SUNDAY)
view = convertToView(widget, 400, 400)
}
@Test
fun testIsInstalled() {
assertWidgetProviderIsInstalled(FrequencyWidgetProvider::class.java)
}
@Test
@Throws(Exception::class)
fun testRender() {
assertRenders(view, PATH + "render.png")
}
companion object {
private const val PATH = "widgets/FrequencyWidget/"
}
}

@ -1,65 +0,0 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets;
import android.widget.*;
import androidx.test.ext.junit.runners.*;
import androidx.test.filters.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
import org.junit.*;
import org.junit.runner.*;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class HistoryWidgetTest extends BaseViewTest
{
private static final String PATH = "widgets/HistoryWidget/";
private Habit habit;
private FrameLayout view;
@Override
public void setUp()
{
super.setUp();
setTheme(R.style.WidgetTheme);
prefs.setWidgetOpacity(255);
habit = fixtures.createVeryLongHabit();
HistoryWidget widget = new HistoryWidget(targetContext, 0, habit);
view = convertToView(widget, 400, 400);
}
@Test
public void testIsInstalled()
{
assertWidgetProviderIsInstalled(HistoryWidgetProvider.class);
}
@Test
public void testRender() throws Exception
{
assertRenders(view, PATH + "render.png");
}
}

@ -0,0 +1,58 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets
import android.widget.FrameLayout
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.isoron.uhabits.BaseViewTest
import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Habit
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
@MediumTest
class HistoryWidgetTest : BaseViewTest() {
private lateinit var habit: Habit
private lateinit var view: FrameLayout
override fun setUp() {
super.setUp()
setTheme(R.style.WidgetTheme)
prefs.widgetOpacity = 255
habit = fixtures.createVeryLongHabit()
val widget = HistoryWidget(targetContext, 0, habit)
view = convertToView(widget, 400, 400)
}
@Test
fun testIsInstalled() {
assertWidgetProviderIsInstalled(HistoryWidgetProvider::class.java)
}
@Test
@Throws(Exception::class)
fun testRender() {
assertRenders(view, PATH + "render.png")
}
companion object {
private const val PATH = "widgets/HistoryWidget/"
}
}

@ -1,65 +0,0 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets;
import android.widget.*;
import androidx.test.ext.junit.runners.*;
import androidx.test.filters.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
import org.junit.*;
import org.junit.runner.*;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class ScoreWidgetTest extends BaseViewTest
{
private static final String PATH = "widgets/ScoreWidget/";
private Habit habit;
private FrameLayout view;
@Override
public void setUp()
{
super.setUp();
setTheme(R.style.WidgetTheme);
prefs.setWidgetOpacity(255);
habit = fixtures.createVeryLongHabit();
ScoreWidget widget = new ScoreWidget(targetContext, 0, habit);
view = convertToView(widget, 400, 400);
}
@Test
public void testIsInstalled()
{
assertWidgetProviderIsInstalled(ScoreWidgetProvider.class);
}
@Test
public void testRender() throws Exception
{
assertRenders(view, PATH + "render.png");
}
}

@ -0,0 +1,58 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets
import android.widget.FrameLayout
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.isoron.uhabits.BaseViewTest
import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Habit
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
@MediumTest
class ScoreWidgetTest : BaseViewTest() {
private lateinit var habit: Habit
private lateinit var view: FrameLayout
override fun setUp() {
super.setUp()
setTheme(R.style.WidgetTheme)
prefs.widgetOpacity = 255
habit = fixtures.createVeryLongHabit()
val widget = ScoreWidget(targetContext, 0, habit)
view = convertToView(widget, 400, 400)
}
@Test
fun testIsInstalled() {
assertWidgetProviderIsInstalled(ScoreWidgetProvider::class.java)
}
@Test
@Throws(Exception::class)
fun testRender() {
assertRenders(view, PATH + "render.png")
}
companion object {
private const val PATH = "widgets/ScoreWidget/"
}
}

@ -1,65 +0,0 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets;
import android.widget.*;
import androidx.test.ext.junit.runners.*;
import androidx.test.filters.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
import org.junit.*;
import org.junit.runner.*;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class StreakWidgetTest extends BaseViewTest
{
private static final String PATH = "widgets/StreakWidget/";
private Habit habit;
private FrameLayout view;
@Override
public void setUp()
{
super.setUp();
setTheme(R.style.WidgetTheme);
prefs.setWidgetOpacity(255);
habit = fixtures.createVeryLongHabit();
StreakWidget widget = new StreakWidget(targetContext, 0, habit);
view = convertToView(widget, 400, 400);
}
@Test
public void testIsInstalled()
{
assertWidgetProviderIsInstalled(StreakWidgetProvider.class);
}
@Test
public void testRender() throws Exception
{
assertRenders(view, PATH + "render.png");
}
}

@ -0,0 +1,58 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets
import android.widget.FrameLayout
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.isoron.uhabits.BaseViewTest
import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Habit
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
@MediumTest
class StreakWidgetTest : BaseViewTest() {
private lateinit var habit: Habit
private lateinit var view: FrameLayout
override fun setUp() {
super.setUp()
setTheme(R.style.WidgetTheme)
prefs.widgetOpacity = 255
habit = fixtures.createVeryLongHabit()
val widget = StreakWidget(targetContext, 0, habit)
view = convertToView(widget, 400, 400)
}
@Test
fun testIsInstalled() {
assertWidgetProviderIsInstalled(StreakWidgetProvider::class.java)
}
@Test
@Throws(Exception::class)
fun testRender() {
assertRenders(view, PATH + "render.png")
}
companion object {
private const val PATH = "widgets/StreakWidget/"
}
}

@ -1,68 +0,0 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets;
import android.widget.*;
import androidx.test.ext.junit.runners.*;
import androidx.test.filters.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
import org.junit.*;
import org.junit.runner.*;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class TargetWidgetTest extends BaseViewTest
{
private static final String PATH = "widgets/TargetWidget/";
private Habit habit;
private FrameLayout view;
@Override
public void setUp()
{
super.setUp();
setTheme(R.style.WidgetTheme);
prefs.setWidgetOpacity(255);
habit = fixtures.createLongNumericalHabit();
habit.setColor(new PaletteColor(11));
habit.setFrequency(Frequency.WEEKLY);
habit.recompute();
TargetWidget widget = new TargetWidget(targetContext, 0, habit);
view = convertToView(widget, 400, 400);
}
@Test
public void testIsInstalled()
{
assertWidgetProviderIsInstalled(TargetWidgetProvider.class);
}
@Test
public void testRender() throws Exception
{
assertRenders(view, PATH + "render.png");
}
}

@ -0,0 +1,63 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets
import android.widget.FrameLayout
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.isoron.uhabits.BaseViewTest
import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Frequency
import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.PaletteColor
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
@MediumTest
class TargetWidgetTest : BaseViewTest() {
private lateinit var habit: Habit
private lateinit var view: FrameLayout
override fun setUp() {
super.setUp()
setTheme(R.style.WidgetTheme)
prefs.widgetOpacity = 255
habit = fixtures.createLongNumericalHabit()
habit.color = PaletteColor(11)
habit.frequency = Frequency.WEEKLY
habit.recompute()
val widget = TargetWidget(targetContext, 0, habit)
view = convertToView(widget, 400, 400)
}
@Test
fun testIsInstalled() {
assertWidgetProviderIsInstalled(TargetWidgetProvider::class.java)
}
@Test
@Throws(Exception::class)
fun testRender() {
assertRenders(view, PATH + "render.png")
}
companion object {
private const val PATH = "widgets/TargetWidget/"
}
}

@ -1,79 +0,0 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets.views;
import androidx.test.ext.junit.runners.*;
import androidx.test.filters.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.utils.*;
import org.isoron.uhabits.utils.*;
import org.junit.*;
import org.junit.runner.*;
import java.io.*;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class CheckmarkWidgetViewTest extends BaseViewTest
{
private static final String PATH = "widgets/CheckmarkWidgetView/";
private CheckmarkWidgetView view;
@Override
@Before
public void setUp()
{
super.setUp();
setTheme(R.style.WidgetTheme);
Habit habit = fixtures.createShortHabit();
Timestamp today = DateUtils.getTodayWithOffset();
view = new CheckmarkWidgetView(targetContext);
double score = habit.getScores().get(today).getValue();
float percentage = (float) score;
view.setActiveColor(PaletteUtils.getAndroidTestColor(0));
view.setEntryState(habit.getComputedEntries().get(today).getValue());
view.setEntryValue(habit.getComputedEntries().get(today).getValue());
view.setPercentage(percentage);
view.setName(habit.getName());
view.refresh();
measureView(view, dpToPixels(100), dpToPixels(200));
}
@Test
public void testRender_checked() throws IOException
{
assertRenders(view, PATH + "checked.png");
}
@Test
public void testRender_largeSize() throws IOException
{
measureView(view, dpToPixels(300), dpToPixels(300));
assertRenders(view, PATH + "large_size.png");
}
}

@ -0,0 +1,73 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isoron.uhabits.widgets.views
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.isoron.uhabits.BaseViewTest
import org.isoron.uhabits.R
import org.isoron.uhabits.core.utils.DateUtils.Companion.getTodayWithOffset
import org.isoron.uhabits.utils.PaletteUtils.getAndroidTestColor
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.io.IOException
@RunWith(AndroidJUnit4::class)
@MediumTest
class CheckmarkWidgetViewTest : BaseViewTest() {
private var view: CheckmarkWidgetView? = null
@Before
override fun setUp() {
super.setUp()
setTheme(R.style.WidgetTheme)
val habit = fixtures.createShortHabit()
val name = habit.name
val computedEntries = habit.computedEntries
val scores = habit.scores
val today = getTodayWithOffset()
view = CheckmarkWidgetView(targetContext)
val score = scores[today].value
val percentage = score.toFloat()
view!!.activeColor = getAndroidTestColor(0)
view!!.entryState = computedEntries.get(today).value
view!!.entryValue = computedEntries.get(today).value
view!!.percentage = percentage
view!!.name = name
view!!.refresh()
measureView(view, dpToPixels(100), dpToPixels(200))
}
@Test
@Throws(IOException::class)
fun testRender_checked() {
assertRenders(view, PATH + "checked.png")
}
@Test
@Throws(IOException::class)
fun testRender_largeSize() {
measureView(view, dpToPixels(300), dpToPixels(300))
assertRenders(view, PATH + "large_size.png")
}
companion object {
private const val PATH = "widgets/CheckmarkWidgetView/"
}
}
Loading…
Cancel
Save