From dc4d3f57eef7711fa8d907f45f9fc26fab71cb78 Mon Sep 17 00:00:00 2001 From: Douglas Ronne Date: Thu, 11 Jul 2024 08:57:44 -0400 Subject: [PATCH] DesktopModelSaver saves file --- .../kotlin/state/DesktopModelSaver.kt | 11 +++++++ .../kotlin/state/DesktopModelSaverTest.kt | 33 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 composeApp/src/desktopMain/kotlin/state/DesktopModelSaver.kt create mode 100644 composeApp/src/desktopTest/kotlin/state/DesktopModelSaverTest.kt diff --git a/composeApp/src/desktopMain/kotlin/state/DesktopModelSaver.kt b/composeApp/src/desktopMain/kotlin/state/DesktopModelSaver.kt new file mode 100644 index 0000000..82a87b1 --- /dev/null +++ b/composeApp/src/desktopMain/kotlin/state/DesktopModelSaver.kt @@ -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()) + } +} diff --git a/composeApp/src/desktopTest/kotlin/state/DesktopModelSaverTest.kt b/composeApp/src/desktopTest/kotlin/state/DesktopModelSaverTest.kt new file mode 100644 index 0000000..9285704 --- /dev/null +++ b/composeApp/src/desktopTest/kotlin/state/DesktopModelSaverTest.kt @@ -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() + } +} \ No newline at end of file