generated from vextorspace/KotlinMultiplatformTesting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9247c65
commit dc4d3f5
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
composeApp/src/desktopMain/kotlin/state/DesktopModelSaver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
composeApp/src/desktopTest/kotlin/state/DesktopModelSaverTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |