Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Task model tests #2039

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.habitrpg.android.habitica.models

import com.habitrpg.android.habitica.models.tasks.Task
import io.kotest.core.spec.style.WordSpec
import io.kotest.matchers.shouldBe
import java.util.Date
import java.time.ZonedDateTime
import java.util.Calendar

class TaskTest : WordSpec({
val task = Task()

fun date(
year: Int = 1989,
month: Int = 1,
day: Int = 2,
hourOfDay: Int = 3,
minute: Int = 4,
second: Int = 5
) : Date {
val calendar = Calendar.getInstance()
calendar.set(year, month, day, hourOfDay, minute, second)

return calendar.time
}

"isDueToday" should {
"false if the day of year is before today" {
val now = ZonedDateTime.now()
task.dueDate = date(day= now.dayOfYear - 1, year = now.year)

task.isDueToday() shouldBe false
}

"false if the year is before today" {
val now = ZonedDateTime.now()
task.dueDate = date(day= now.dayOfYear, year = now.year - 1)

task.isDueToday() shouldBe false
}

"true if the day of year is after today" {
val now = ZonedDateTime.now()
task.dueDate = date(day= now.dayOfYear + 1, year = now.year)

task.isDueToday() shouldBe true
}

"true if the year is after today" {
val now = ZonedDateTime.now()
task.dueDate = date(day= now.dayOfYear, year = now.year + 1)

task.isDueToday() shouldBe true
}

"true if it is today" {
val now = ZonedDateTime.now()
task.dueDate = date(day= now.dayOfYear, year = now.year)

task.isDueToday() shouldBe true
}
}
})
Loading