mirror of https://github.com/iSoron/uhabits.git
parent
5ea19c9475
commit
d463bb55d7
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2019 Á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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Workaround until Kotlin adds support for testing suspend functions
|
||||||
|
* https://youtrack.jetbrains.com/issue/KT-22228
|
||||||
|
*/
|
||||||
|
expect fun asyncTest(block: suspend () -> Unit)
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2019 Á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
|
||||||
|
|
||||||
|
import org.isoron.platform.gui.*
|
||||||
|
import org.isoron.platform.io.*
|
||||||
|
|
||||||
|
interface CanvasHelper {
|
||||||
|
fun createCanvas(width: Int, height: Int): Canvas
|
||||||
|
fun exportCanvas(canvas: Canvas, filename: String)
|
||||||
|
}
|
||||||
|
|
||||||
|
expect object DependencyResolver {
|
||||||
|
suspend fun getFileOpener(): FileOpener
|
||||||
|
suspend fun getDatabase(): Database
|
||||||
|
fun getCanvasHelper(): CanvasHelper
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2019 Á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
|
||||||
|
|
||||||
|
import org.isoron.platform.io.*
|
||||||
|
|
||||||
|
actual object DependencyResolver {
|
||||||
|
actual suspend fun getFileOpener(): FileOpener = IosFileOpener()
|
||||||
|
|
||||||
|
// IosDatabase and IosCanvas are currently implemented in Swift, so we
|
||||||
|
// cannot test these classes here.
|
||||||
|
actual suspend fun getDatabase(): Database = TODO()
|
||||||
|
actual fun getCanvasHelper(): CanvasHelper = TODO()
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2019 Á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
|
||||||
|
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Workaround until Kotlin adds support for testing suspend functions
|
||||||
|
* https://youtrack.jetbrains.com/issue/KT-22228
|
||||||
|
*/
|
||||||
|
actual fun asyncTest(block: suspend () -> Unit): dynamic = GlobalScope.promise { block() }
|
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016-2019 Á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
|
|
||||||
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import org.isoron.platform.io.*
|
|
||||||
import org.isoron.uhabits.*
|
|
||||||
import org.isoron.uhabits.models.*
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
class JsAsyncTests {
|
|
||||||
var fs: JsFileStorage? = null
|
|
||||||
|
|
||||||
suspend fun getFileOpener(): FileOpener {
|
|
||||||
if (fs == null) {
|
|
||||||
fs = JsFileStorage()
|
|
||||||
fs?.init()
|
|
||||||
}
|
|
||||||
return JsFileOpener(fs!!)
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getDatabase(): Database {
|
|
||||||
val nativeDB = eval("new SQL.Database()")
|
|
||||||
val db = JsDatabase(nativeDB)
|
|
||||||
db.migrateTo(LOOP_DATABASE_VERSION, getFileOpener(), StandardLog())
|
|
||||||
return db
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testFiles() = GlobalScope.promise {
|
|
||||||
FilesTest(getFileOpener()).testLines()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testDatabase() = GlobalScope.promise {
|
|
||||||
DatabaseTest(getDatabase()).testUsage()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testCheckmarkRepository() = GlobalScope.promise {
|
|
||||||
CheckmarkRepositoryTest(getDatabase()).testCRUD()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testHabitRepository() = GlobalScope.promise {
|
|
||||||
HabitRepositoryTest(getDatabase()).testCRUD()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testPreferencesRepository() = GlobalScope.promise {
|
|
||||||
PreferencesRepositoryTest(getDatabase()).testUsage()
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue