Implemented the Persisting the selected locale across launches on the ContentView view in the Sample app target.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user