Implement JsFiles

This commit is contained in:
2019-04-10 04:39:52 -05:00
parent 7d169d8053
commit e88c58916a
16 changed files with 717 additions and 44 deletions

View File

@@ -0,0 +1,35 @@
/*
* 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.platform.io
import kotlin.test.*
class FilesTest(val fileOpener: FileOpener) {
fun testReadLines() {
val hello = fileOpener.openResourceFile("hello.txt")
var lines = hello.readLines()
assertEquals("Hello World!", lines[0])
assertEquals("This is a resource.", lines[1])
val migration = fileOpener.openResourceFile("migrations/012.sql")
lines = migration.readLines()
assertEquals("delete from Score", lines[0])
}
}

View File

@@ -19,22 +19,18 @@
package org.isoron.uhabits.models
import junit.framework.Assert.*
import org.isoron.platform.gui.*
import org.isoron.uhabits.*
import org.junit.*
import org.isoron.platform.io.*
import kotlin.test.*
class HabitRepositoryTest(val db: Database) {
class HabitRepositoryTest : BaseTest() {
lateinit var repository: HabitRepository
lateinit private var original0: Habit
lateinit private var original1: Habit
lateinit private var original2: Habit
@Before
override fun setUp() {
super.setUp()
fun setUp() {
original0 = Habit(id = 0,
name = "Wake up early",
description = "Did you wake up before 6am?",
@@ -71,7 +67,6 @@ class HabitRepositoryTest : BaseTest() {
repository = HabitRepository(db)
}
@Test
fun testFindAll() {
var habits = repository.findAll()
assertEquals(0, repository.nextId())

View File

@@ -0,0 +1,54 @@
/*
* 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.platform.io
import org.w3c.dom.events.*
import org.w3c.xhr.*
class JsFileOpener : FileOpener {
override fun openUserFile(filename: String): UserFile {
return JsUserFile(filename)
}
override fun openResourceFile(filename: String): ResourceFile {
return JsResourceFile(filename)
}
}
class JsUserFile(filename: String) : UserFile {
override fun delete() {
}
override fun exists(): Boolean {
return false
}
}
class JsResourceFile(val filename: String) : ResourceFile {
override fun readLines(): List<String> {
val xhr = XMLHttpRequest()
xhr.open("GET", "/assets/$filename", false)
xhr.send()
return xhr.responseText.lines()
}
override fun copyTo(dest: UserFile) {
}
}

View File

@@ -0,0 +1,29 @@
/*
* 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.platform.io
import kotlin.test.*
class JsFilesTest {
@Test
fun testReadLines() {
FilesTest(JsFileOpener()).testReadLines()
}
}

View File

@@ -0,0 +1,35 @@
/*
* 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.uhabits.models
import org.isoron.platform.io.*
import kotlin.test.*
class JsHabitRepositoryTest {
val db = JsDatabase(eval("new SQL.Database()"))
val commonTest = HabitRepositoryTest(db)
@Test
fun testFindAll() {
// commonTest.setUp()
// commonTest.testFindAll()
}
}

View File

@@ -19,20 +19,13 @@
package org.isoron.platform
import org.isoron.uhabits.BaseTest
import org.junit.Test
import kotlin.test.assertEquals
import org.isoron.platform.io.*
import org.isoron.uhabits.*
import org.junit.*
class JavaFilesTest : BaseTest() {
@Test
fun testReadLines() {
val hello = fileOpener.openResourceFile("hello.txt")
var lines = hello.readLines()
assertEquals("Hello World!", lines[0])
assertEquals("This is a resource.", lines[1])
val migration = fileOpener.openResourceFile("migrations/012.sql")
lines = migration.readLines()
assertEquals("delete from Score", lines[0])
FilesTest(fileOpener).testReadLines()
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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.uhabits.models
import org.isoron.uhabits.*
import org.junit.*
class JavaHabitRepositoryTest : BaseTest() {
lateinit var commonTest: HabitRepositoryTest
@Before
override fun setUp() {
super.setUp()
commonTest = HabitRepositoryTest(db)
commonTest.setUp()
}
@Test
fun testFindAll() {
commonTest.testFindAll()
}
}