Implemented the Persisting the selected locale across launches on the ContentView view in the Sample app target.

This commit is contained in:
2026-07-05 21:04:29 +02:00
parent 58a6ec217f
commit cbb5703751
5 changed files with 99 additions and 13 deletions
+24
View File
@@ -0,0 +1,24 @@
{
"configurations" : [
{
"id" : "D599315E-CE89-41A2-A181-811F9CF40731",
"name" : "Configuration 1",
"options" : {
}
}
],
"defaultOptions" : {
},
"testTargets" : [
{
"target" : {
"containerPath" : "container:Attendi.xcodeproj",
"identifier" : "0296F7992FFA954E00D2C5FC",
"name" : "AttendiTests"
}
}
],
"version" : 1
}
@@ -25,7 +25,7 @@ struct ContentViewModelTests {
let model = Model(preinstaller: preinstaller)
await model.load()
await model.load(identifier: "")
#expect(model.locale == .english)
#expect(model.locales.count == 2)
@@ -33,6 +33,34 @@ struct ContentViewModelTests {
#expect(model.locales.contains(.english))
}
@Test
func `load restores the persisted locale`() async {
let preinstaller = PreinstallingMock()
preinstaller.localesSupported = [.dutch, .english]
preinstaller.equivalents = [.dutch: .dutch]
let model = Model(preinstaller: preinstaller)
await model.load(identifier: Locale.dutch.identifier)
#expect(model.locale == .dutch)
}
@Test
func `load falls back to the default locale when the persisted locale is unsupported`() async {
let preinstaller = PreinstallingMock()
preinstaller.localesSupported = [.dutch, .english]
preinstaller.equivalents = [.byDefault: .english]
let model = Model(preinstaller: preinstaller)
await model.load(identifier: "fr-FR")
#expect(model.locale == .english)
}
@Test
func `load preinstalls the aligned locale`() async throws {
let preinstaller = PreinstallingMock()
@@ -42,7 +70,7 @@ struct ContentViewModelTests {
let model = Model(preinstaller: preinstaller)
await model.load()
await model.load(identifier: "")
try await Task.sleep(for: .seconds(0.1))
@@ -203,6 +231,8 @@ struct ContentViewModelTests {
// MARK: - Constants
private extension Locale {
/// The locale the model falls back to when no equivalent of the current locale is supported.
static let byDefault = Locale(identifier: "en_US")
/// A supported locale to preinstall in the tests.
static let dutch = Locale(identifier: "nl-NL")
/// Another supported locale to preinstall in the tests.