From 228be95f9c104e105161ac01afa2daa7e2da118e Mon Sep 17 00:00:00 2001 From: Quentin Hibon Date: Wed, 20 Jan 2021 22:00:35 +0100 Subject: [PATCH] convert widget tests --- .../uhabits/widgets/CheckmarkWidgetTest.java | 95 ------------------- .../uhabits/widgets/CheckmarkWidgetTest.kt | 89 +++++++++++++++++ .../uhabits/widgets/FrequencyWidgetTest.java | 67 ------------- .../uhabits/widgets/FrequencyWidgetTest.kt | 59 ++++++++++++ .../uhabits/widgets/HistoryWidgetTest.java | 65 ------------- .../uhabits/widgets/HistoryWidgetTest.kt | 58 +++++++++++ .../uhabits/widgets/ScoreWidgetTest.java | 65 ------------- .../isoron/uhabits/widgets/ScoreWidgetTest.kt | 58 +++++++++++ .../uhabits/widgets/StreakWidgetTest.java | 65 ------------- .../uhabits/widgets/StreakWidgetTest.kt | 58 +++++++++++ .../uhabits/widgets/TargetWidgetTest.java | 68 ------------- .../uhabits/widgets/TargetWidgetTest.kt | 63 ++++++++++++ .../views/CheckmarkWidgetViewTest.java | 79 --------------- .../widgets/views/CheckmarkWidgetViewTest.kt | 73 ++++++++++++++ 14 files changed, 458 insertions(+), 504 deletions(-) delete mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/CheckmarkWidgetTest.java create mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/CheckmarkWidgetTest.kt delete mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/FrequencyWidgetTest.java create mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/FrequencyWidgetTest.kt delete mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/HistoryWidgetTest.java create mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/HistoryWidgetTest.kt delete mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/ScoreWidgetTest.java create mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/ScoreWidgetTest.kt delete mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/StreakWidgetTest.java create mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/StreakWidgetTest.kt delete mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/TargetWidgetTest.java create mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/TargetWidgetTest.kt delete mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/views/CheckmarkWidgetViewTest.java create mode 100644 uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/views/CheckmarkWidgetViewTest.kt diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/CheckmarkWidgetTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/CheckmarkWidgetTest.java deleted file mode 100644 index a76efadec..000000000 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/CheckmarkWidgetTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2016-2021 Álinson Santos Xavier - * - * 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 . - */ - -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"); - } -} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/CheckmarkWidgetTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/CheckmarkWidgetTest.kt new file mode 100644 index 000000000..0a5823bbf --- /dev/null +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/CheckmarkWidgetTest.kt @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2016-2021 Álinson Santos Xavier + * + * 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 . + */ +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(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/" + } +} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/FrequencyWidgetTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/FrequencyWidgetTest.java deleted file mode 100644 index 29f0befda..000000000 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/FrequencyWidgetTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2016-2021 Álinson Santos Xavier - * - * 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 . - */ - -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"); - } -} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/FrequencyWidgetTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/FrequencyWidgetTest.kt new file mode 100644 index 000000000..721aefdf7 --- /dev/null +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/FrequencyWidgetTest.kt @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2016-2021 Álinson Santos Xavier + * + * 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 . + */ +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/" + } +} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/HistoryWidgetTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/HistoryWidgetTest.java deleted file mode 100644 index ea9c60ea9..000000000 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/HistoryWidgetTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2016-2021 Álinson Santos Xavier - * - * 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 . - */ - -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"); - } -} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/HistoryWidgetTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/HistoryWidgetTest.kt new file mode 100644 index 000000000..d75ca3219 --- /dev/null +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/HistoryWidgetTest.kt @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2016-2021 Álinson Santos Xavier + * + * 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 . + */ +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/" + } +} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/ScoreWidgetTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/ScoreWidgetTest.java deleted file mode 100644 index 74516a754..000000000 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/ScoreWidgetTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2016-2021 Álinson Santos Xavier - * - * 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 . - */ - -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"); - } -} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/ScoreWidgetTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/ScoreWidgetTest.kt new file mode 100644 index 000000000..88826399e --- /dev/null +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/ScoreWidgetTest.kt @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2016-2021 Álinson Santos Xavier + * + * 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 . + */ +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/" + } +} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/StreakWidgetTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/StreakWidgetTest.java deleted file mode 100644 index 8be405687..000000000 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/StreakWidgetTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2016-2021 Álinson Santos Xavier - * - * 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 . - */ - -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"); - } -} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/StreakWidgetTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/StreakWidgetTest.kt new file mode 100644 index 000000000..9bfe2742f --- /dev/null +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/StreakWidgetTest.kt @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2016-2021 Álinson Santos Xavier + * + * 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 . + */ +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/" + } +} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/TargetWidgetTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/TargetWidgetTest.java deleted file mode 100644 index d4109c3fb..000000000 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/TargetWidgetTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2016-2021 Álinson Santos Xavier - * - * 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 . - */ - -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"); - } -} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/TargetWidgetTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/TargetWidgetTest.kt new file mode 100644 index 000000000..fd49a0eb1 --- /dev/null +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/TargetWidgetTest.kt @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2016-2021 Álinson Santos Xavier + * + * 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 . + */ +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/" + } +} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/views/CheckmarkWidgetViewTest.java b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/views/CheckmarkWidgetViewTest.java deleted file mode 100644 index 05a5e3265..000000000 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/views/CheckmarkWidgetViewTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2016-2021 Álinson Santos Xavier - * - * 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 . - */ - -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"); - } - -} diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/views/CheckmarkWidgetViewTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/views/CheckmarkWidgetViewTest.kt new file mode 100644 index 000000000..9cd494152 --- /dev/null +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/widgets/views/CheckmarkWidgetViewTest.kt @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2016-2021 Álinson Santos Xavier + * + * 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 . + */ +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/" + } +}