create simple tests for this file :

class AutoSaveViewmodel @Inject constructor(
    @ApplicationContext val context: Context,
    val settingsManager: SettingsManager,
) : ScreenModel {
    val mapper = jacksonObjectMapper().apply {
        configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
    }
    val gson = Gson()
    private val autoSaveState = MutableStateFlow(AutoSaveState(emptyList()))
    //expose the immutable state
    val  _autoSaveState = autoSaveState.map { it }.stateIn(screenModelScope, SharingStarted.Eagerly, AutoSaveState(emptyList()))
    val autoLoadState = MutableStateFlow<AutoSaveState?>(null)
    private val mutex = Mutex() // Mutex to ensure safe writes
    var writingJob: Job? = null
    fun saveState(openTabs: List<EditorTabState>) {
        //check if autosave is enabled
        screenModelScope.launchIO {
            if (settingsManager.settingsFlow.firstOrNull()?.autoSaveEnabled == false) {
                return@launchIO
            }
            //if the list is empty , just save the new list
            if (openTabs.isEmpty()) {
                autoSaveState.value = AutoSaveState(emptyList())
                writeToJsonFile()
                return@launchIO
            }
            autoSaveState.value = AutoSaveState(openTabs.flowMapNotNull {
                it.prepareForAutoSave()
            })
            writeToJsonFile()
        }

    }

    fun saveTabs(tabs: List<EditorTabState>) {
        screenModelScope.launchIO {
            if (settingsManager.settingsFlow.firstOrNull()?.autoSaveEnabled == false) {
                return@launchIO
            }
            val newTabs = autoSaveState.value.openTabs.toMutableList()
            val indicies = tabs.flowMap {
                val index = newTabs.indexOfFirst { tab -> tab.filePath == it.filePath }
                if (index != -1) {
                    newTabs[index] = it.prepareForAutoSave()
                } else {
                    newTabs.add(it.prepareForAutoSave())
                }
            }
            autoSaveState.value = AutoSaveState(newTabs)
            writeToJsonFile()
        }

    }

    fun saveTab(tab: EditorTabState) {

        saveTabs(listOf(tab))
    }

    fun deleteTab(
        tab: EditorTabState,
    ) {
        screenModelScope.launchIO {
            if (settingsManager.settingsFlow.firstOrNull()?.autoSaveEnabled == false) {
                return@launchIO
            }
            val newTabs = autoSaveState.value.openTabs.toMutableList()
            val index = newTabs.indexOfFirst { it.filePath == tab.filePath }
            if (index != -1) {
                newTabs.removeAt(index)
                autoSaveState.value = AutoSaveState(newTabs)
                writeToJsonFile()
            }
        }
    }


    fun writeToJsonFile() {
        screenModelScope.launchIO {
            if (settingsManager.settingsFlow.firstOrNull()?.autoSaveEnabled == false) {
                return@launchIO
            }
            writingJob?.cancelAndJoin() // Wait for the cancellation to complete
            // Convert the state to JSON
            val json = mapper.writeValueAsString(autoSaveState.value)
            // Get the app-specific external directory
            val appSpecificExternalDir = context.getExternalFilesDir(null)
            // Define the directory path for AutoSave
            val autoSaveDir = File(appSpecificExternalDir, "/AutoSave")
            // Ensure the AutoSave directory exists
            if (!autoSaveDir.exists()) {
                autoSaveDir.mkdirs()
            }
            // Create the file path for the autosave.json
            val file = File(autoSaveDir, "autosave.json")
            // Launch a coroutine for writing the file
            writingJob = launch {
                mutex.withLock {
                    try { // Write the JSON to the file
                        file.writeText(json)
                    } catch (e: CancellationException) {
                        // Handle cancellation and potential partial write issues
                        // Log or attempt recovery if necessary
                    }
                }
            }
        }
    }

    fun loadAutoSave() {
        screenModelScope.launchIO {
            if (settingsManager.settingsFlow.firstOrNull()?.autoSaveEnabled == false) {
                autoLoadState.update {
                    AutoSaveState(emptyList())
                }
                return@launchIO
            }
            val appSpecificExternalDir = context.getExternalFilesDir(null)
            // Define the directory path for AutoSave
            val autoSaveDir = File(appSpecificExternalDir, "/AutoSave")
            val file = File(autoSaveDir, "autosave.json")

            val autoSaveState = if (file.exists()) {
                file.bufferedReader().use { reader ->
                    val json = reader.readText()
                    if (json.isNullOrEmpty()) {
                        return@use AutoSaveState(emptyList())
                    }
                    //use Gson for deserialization
                    mapper.readValue(json, AutoSaveState::class.java)
                }
            } else {
                AutoSaveState(emptyList())
            }

            autoLoadState.update {
                autoSaveState
            }
        }
    }



}

data class AutoSaveState(
    val openTabs: List<EditorTabState>,
)