From 7cc4b66dfdcc645effedd402bd413a1dbbe408a0 Mon Sep 17 00:00:00 2001 From: Bindu <56578479+vbh@users.noreply.github.com> Date: Tue, 21 Sep 2021 02:35:30 -0700 Subject: [PATCH] Update HabitBullCSV test to accept notes --- uhabits-core/assets/test/habitbull.csv | 2 +- uhabits-core/assets/test/habitbull2.csv | 4 ++-- .../org/isoron/uhabits/core/io/HabitBullCSVImporter.kt | 4 +++- .../java/org/isoron/uhabits/core/io/ImportTest.kt | 10 ++++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/uhabits-core/assets/test/habitbull.csv b/uhabits-core/assets/test/habitbull.csv index 977a8e8df..014b7d656 100644 --- a/uhabits-core/assets/test/habitbull.csv +++ b/uhabits-core/assets/test/habitbull.csv @@ -1,5 +1,5 @@ HabitName,HabitDescription,HabitCategory,CalendarDate,Value,CommentText -Breed dragons,with love and fire,Diet & Food,2016-03-18,1, +Breed dragons,with love and fire,Diet & Food,2016-03-18,1,text Breed dragons,with love and fire,Diet & Food,2016-03-19,1, Breed dragons,with love and fire,Diet & Food,2016-03-21,1, Reduce sleep,only 2 hours per day,Time Management,2016-03-15,1, diff --git a/uhabits-core/assets/test/habitbull2.csv b/uhabits-core/assets/test/habitbull2.csv index 890632bbd..9296b1ebc 100644 --- a/uhabits-core/assets/test/habitbull2.csv +++ b/uhabits-core/assets/test/habitbull2.csv @@ -1,7 +1,7 @@ HabitName,HabitDescription,HabitCategory,CalendarDate,Value,CommentText H1,,C1,11/5/2020,1, H2,,C2,11/5/2020,-2150000000, -H3,Habit 3,C3,4/11/2019,1, +H3,Habit 3,C3,4/11/2019,1,text H3,Habit 3,C3,4/12/2019,1, H3,Habit 3,C3,4/13/2019,0, H3,Habit 3,C3,4/14/2019,1, @@ -65,7 +65,7 @@ H3,Habit 3,C3,6/10/2019,1, H3,Habit 3,C3,6/11/2019,1, H3,Habit 3,C3,6/12/2019,1, H3,Habit 3,C3,6/13/2019,1, -H3,Habit 3,C3,6/14/2019,0, +H3,Habit 3,C3,6/14/2019,0,Habit 3 notes H3,Habit 3,C3,6/15/2019,1, H4,Habit 4,C4,11/6/2020,1, H4,Habit 4,C4,11/9/2020,1, diff --git a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/io/HabitBullCSVImporter.kt b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/io/HabitBullCSVImporter.kt index ee94cdbd0..140122db7 100644 --- a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/io/HabitBullCSVImporter.kt +++ b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/io/HabitBullCSVImporter.kt @@ -76,9 +76,11 @@ class HabitBullCSVImporter map[name] = h logger.info("Creating habit: $name") } + val notes = cols[5] ?: "" if (parseInt(cols[4]) == 1) { - val notes = cols[5] ?: "" h.originalEntries.add(Entry(timestamp, Entry.YES_MANUAL, notes)) + } else { + h.originalEntries.add(Entry(timestamp, Entry.NO, notes)) } } } diff --git a/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/io/ImportTest.kt b/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/io/ImportTest.kt index 6a8bd0c4f..daad1784e 100644 --- a/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/io/ImportTest.kt +++ b/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/io/ImportTest.kt @@ -54,6 +54,7 @@ class ImportTest : BaseUnitTest() { assertTrue(isChecked(habit, 2016, 3, 18)) assertTrue(isChecked(habit, 2016, 3, 19)) assertFalse(isChecked(habit, 2016, 3, 20)) + assertTrue(isNotesEqual(habit, 2016, 3, 18, "text")) } @Test @@ -68,6 +69,8 @@ class ImportTest : BaseUnitTest() { assertTrue(isChecked(habit, 2019, 4, 11)) assertTrue(isChecked(habit, 2019, 5, 7)) assertFalse(isChecked(habit, 2019, 6, 14)) + assertTrue(isNotesEqual(habit, 2019, 4, 11, "text")) + assertTrue(isNotesEqual(habit, 2019, 6, 14, "Habit 3 notes")) } @Test @@ -127,6 +130,13 @@ class ImportTest : BaseUnitTest() { return h.originalEntries.get(timestamp).value == Entry.YES_MANUAL } + private fun isNotesEqual(h: Habit, year: Int, month: Int, day: Int, notes: String): Boolean { + val date = getStartOfTodayCalendar() + date.set(year, month - 1, day) + val timestamp = Timestamp(date) + return h.originalEntries.get(timestamp).notes == notes + } + @Throws(IOException::class) private fun importFromFile(assetFilename: String) { val file = File.createTempFile("asset", "")