package com.cottondb.notesimport org.json.JSONObjectimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertTrueimport org.junit.Testimport java.io.FileclassNotesFlavourTest {privateval repo = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "apps/registry.json").isFile }privatefun json(path: String) = JSONObject(File(repo, path).readText())privateval writing get() = json("crates/cotton-core/kits/notes/writing.json")/** The core's theme [id], [appearance] `light` or `dark`. */privatefun colours(id: String, appearance: String): JSONObject {val themes = writing.getJSONArray("themes")return (0 until themes.length()).map { themes.getJSONObject(it) }.first { it.getString("id") == id }.getJSONObject(appearance) }/** * Notes launches on its own flat ground, never the felt: the window, the launch screen and the core's default * light theme are one colour, and the dark launch is the default dark theme's ground (DECISIONS.md "Build"). */ @Testfun notes_launches_on_its_own_ground() {val notes = json("apps/android/app/flavours.json").getJSONObject("notes")val flat = notes.getJSONObject("flatLaunch")val defaults = writing.getJSONObject("defaults") assertEquals(NotesLook.LAUNCH_LIGHT, notes.getString("windowGround")) assertEquals(NotesLook.LAUNCH_LIGHT, flat.getString("light")) assertEquals(NotesLook.LAUNCH_DARK, flat.getString("dark")) assertEquals(NotesLook.LAUNCH_LIGHT, colours(defaults.getString("light_theme"), "light").getString("ground")) assertEquals(NotesLook.LAUNCH_DARK, colours(defaults.getString("dark_theme"), "dark").getString("ground")) }/** Every theme the core keeps is named in the notes lines, so none is written in Kotlin. */ @Testfun every_theme_is_named_in_the_lines() {val names = json("crates/cotton-core/kits/shell/lines/notes.json").getJSONObject("theme").getJSONObject("names")val themes = writing.getJSONArray("themes") (0 until themes.length()).map { themes.getJSONObject(it).getString("id") }.forEach { assertTrue(it, names.optString(it).isNotBlank()) } }}