Initial commit
This commit is contained in:
36
app/src/test/java/com/keeply/pantry/DateUtilsTest.kt
Normal file
36
app/src/test/java/com/keeply/pantry/DateUtilsTest.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.keeply.pantry
|
||||
|
||||
import com.keeply.pantry.data.ExpiryTone
|
||||
import com.keeply.pantry.data.daysUntil
|
||||
import com.keeply.pantry.data.expiryLabel
|
||||
import com.keeply.pantry.data.expiryTone
|
||||
import com.keeply.pantry.data.formatAmount
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import java.time.LocalDate
|
||||
|
||||
class DateUtilsTest {
|
||||
private val today = LocalDate.of(2026, 7, 22)
|
||||
|
||||
@Test
|
||||
fun expiryLabelsMatchPantryRules() {
|
||||
assertEquals("Expired 2d ago", expiryLabel("2026-07-20T00:00:00", today))
|
||||
assertEquals("Expires today", expiryLabel("2026-07-22T00:00:00", today))
|
||||
assertEquals("Expires tomorrow", expiryLabel("2026-07-23T00:00:00", today))
|
||||
assertEquals("No expiry set", expiryLabel(null, today))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun expiryTonesUseThreeDayWarningWindow() {
|
||||
assertEquals(ExpiryTone.Danger, expiryTone("2026-07-21", today))
|
||||
assertEquals(ExpiryTone.Warning, expiryTone("2026-07-25", today))
|
||||
assertEquals(ExpiryTone.Good, expiryTone("2026-07-26", today))
|
||||
assertEquals(3L, daysUntil("2026-07-25", today))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun quantitiesDoNotShowUnnecessaryDecimalPlaces() {
|
||||
assertEquals("1", formatAmount(1.0))
|
||||
assertEquals("1.5", formatAmount(1.5))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.keeply.pantry
|
||||
|
||||
import com.keeply.pantry.data.InventoryItemRequest
|
||||
import com.keeply.pantry.data.asIndividualEntries
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class InventoryItemRequestTest {
|
||||
@Test
|
||||
fun barcodeQuantityCreatesSeparateSingleItemRequests() {
|
||||
val request = InventoryItemRequest(barcode = "5012345678900", amount = 3.0, amountType = "item")
|
||||
|
||||
val entries = request.asIndividualEntries(3)
|
||||
|
||||
assertEquals(3, entries.size)
|
||||
assertEquals(listOf(1.0, 1.0, 1.0), entries.map { it.amount })
|
||||
assertEquals(listOf("5012345678900", "5012345678900", "5012345678900"), entries.map { it.barcode })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user