mirror of https://github.com/iSoron/uhabits.git
parent
45574753c7
commit
c2d89c7a60
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* 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.activities.habits.show.views;
|
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
|
|
||||||
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.isoron.uhabits.core.models.Reminder;
|
|
||||||
import org.isoron.uhabits.core.models.WeekdayList;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
@MediumTest
|
|
||||||
public class NotesCardTest extends BaseViewTest
|
|
||||||
{
|
|
||||||
public static final String PATH = "habits/show/NotesCard/";
|
|
||||||
|
|
||||||
private NotesCard view;
|
|
||||||
|
|
||||||
private Habit habit;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
@Override
|
|
||||||
public void setUp()
|
|
||||||
{
|
|
||||||
super.setUp();
|
|
||||||
|
|
||||||
habit = fixtures.createLongHabit();
|
|
||||||
habit.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
|
|
||||||
|
|
||||||
view = LayoutInflater
|
|
||||||
.from(targetContext)
|
|
||||||
.inflate(R.layout.show_habit, null)
|
|
||||||
.findViewById(R.id.notesCard);
|
|
||||||
|
|
||||||
view.setHabit(habit);
|
|
||||||
view.refreshData();
|
|
||||||
|
|
||||||
measureView(view, 800, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRender() throws Exception
|
|
||||||
{
|
|
||||||
assertRenders(view, PATH + "render.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRenderEmptyDescription() throws Exception
|
|
||||||
{
|
|
||||||
habit.setDescription("");
|
|
||||||
view.refreshData();
|
|
||||||
assertRenders(view, PATH + "render-empty-description.png");
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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.activities.habits.show.views
|
||||||
|
|
||||||
|
import android.view.*
|
||||||
|
import androidx.test.ext.junit.runners.*
|
||||||
|
import androidx.test.filters.*
|
||||||
|
import org.isoron.uhabits.*
|
||||||
|
import org.isoron.uhabits.activities.habits.show.*
|
||||||
|
import org.junit.*
|
||||||
|
import org.junit.runner.*
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
@MediumTest
|
||||||
|
class NotesCardTest : BaseViewTest() {
|
||||||
|
val PATH = "habits/show/NotesCard"
|
||||||
|
private lateinit var view: NotesCard
|
||||||
|
|
||||||
|
@Before
|
||||||
|
override fun setUp() {
|
||||||
|
super.setUp()
|
||||||
|
view = LayoutInflater
|
||||||
|
.from(targetContext)
|
||||||
|
.inflate(R.layout.show_habit, null)
|
||||||
|
.findViewById(R.id.notesCard)
|
||||||
|
view.onData(ShowHabitViewModel(
|
||||||
|
description = "This is a test description",
|
||||||
|
))
|
||||||
|
measureView(view, 800f, 200f)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testRender() {
|
||||||
|
assertRenders(view, "$PATH/render.png")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testRenderEmptyDescription() {
|
||||||
|
view.onData(ShowHabitViewModel(
|
||||||
|
description = "",
|
||||||
|
))
|
||||||
|
assertRenders(view, "$PATH/render-empty-description.png")
|
||||||
|
}
|
||||||
|
}
|
@ -1,26 +1,37 @@
|
|||||||
package org.isoron.uhabits.activities.habits.show.views
|
package org.isoron.uhabits.activities.habits.show.views
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.*
|
||||||
import android.util.AttributeSet
|
import android.util.*
|
||||||
import android.view.View
|
import android.view.*
|
||||||
import android.widget.TextView
|
import android.widget.*
|
||||||
import org.isoron.uhabits.R
|
import org.isoron.uhabits.activities.habits.show.*
|
||||||
import org.isoron.uhabits.core.tasks.Task
|
import org.isoron.uhabits.databinding.*
|
||||||
|
|
||||||
class NotesCard(context: Context?, attrs: AttributeSet?) : HabitCard(context, attrs) {
|
class NotesCard(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet
|
||||||
|
) : LinearLayout(context, attrs), ShowHabitPresenter.Listener {
|
||||||
|
|
||||||
private val notesTextView: TextView
|
private val binding = ShowHabitNotesBinding.inflate(LayoutInflater.from(context), this)
|
||||||
|
lateinit var presenter: ShowHabitPresenter
|
||||||
|
|
||||||
init {
|
override fun onAttachedToWindow() {
|
||||||
View.inflate(getContext(), R.layout.show_habit_notes, this)
|
super.onAttachedToWindow()
|
||||||
notesTextView = findViewById(R.id.habitNotes)
|
presenter.addListener(this)
|
||||||
|
presenter.requestData(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun refreshData() {
|
override fun onDetachedFromWindow() {
|
||||||
notesTextView.text = habit.description
|
presenter.removeListener(this)
|
||||||
visibility = if(habit.description.isEmpty()) View.GONE else View.VISIBLE
|
super.onDetachedFromWindow()
|
||||||
notesTextView.visibility = visibility
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createRefreshTask(): Task = error("refresh task should never be called.")
|
override fun onData(data: ShowHabitViewModel) {
|
||||||
|
if (data.description.isEmpty()) {
|
||||||
|
visibility = GONE
|
||||||
|
} else {
|
||||||
|
visibility = VISIBLE
|
||||||
|
binding.habitNotes.text = data.description
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue