Skip to content

Commit

Permalink
DesktopModelSaver saves file
Browse files Browse the repository at this point in the history
  • Loading branch information
vextorspace committed Jul 11, 2024
1 parent 9247c65 commit dc4d3f5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions composeApp/src/desktopMain/kotlin/state/DesktopModelSaver.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package state

import resources.AppFile
import viewmodel.DewItViewModel

class DesktopModelSaver(private val fileName: String, private val model: DewItViewModel) : ModelSaver {
override fun save() {
val appFile = AppFile(fileName)
appFile.writeText(model.toJson())
}
}
33 changes: 33 additions & 0 deletions composeApp/src/desktopTest/kotlin/state/DesktopModelSaverTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package state

import io.kotest.matchers.booleans.shouldBeFalse
import io.kotest.matchers.booleans.shouldBeTrue
import resources.AppFile
import viewmodel.GtdModel
import kotlin.test.BeforeTest
import kotlin.test.Test

const val fileName = "testSave.json"

class DesktopModelSaverTest {
val saveFile = AppFile(fileName)
val model = GtdModel.createModel()

@BeforeTest
fun setup() {
if(saveFile.exists()) {
saveFile.delete()
}
}

@Test
fun androidModelSaverCreatesASaveFile() {
val modelSaver: ModelSaver = DesktopModelSaver(fileName, model)

saveFile.exists().shouldBeFalse()

modelSaver.save()

saveFile.exists().shouldBeTrue()
}
}

0 comments on commit dc4d3f5

Please sign in to comment.