-
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.
Merge pull request #2243 from CruGlobal/GT-2425-Lesson-Filter-set-to-…
…App-Language-Test GT-2425 lesson filter set to app language test
- Loading branch information
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
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
129 changes: 129 additions & 0 deletions
129
...eatures/AppLanguage/Data-DomainInterface/SetUserPreferredAppLanguageRepositoryTests.swift
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,129 @@ | ||
// | ||
// SetUserPreferredAppLanguageRepositoryTests.swift | ||
// godtoolsTests | ||
// | ||
// Created by Rachael Skeath on 8/2/24. | ||
// Copyright © 2024 Cru. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
@testable import godtools | ||
import Combine | ||
import Quick | ||
import Nimble | ||
|
||
class SetUserPreferredAppLanguageRepositoryTests: QuickSpec { | ||
|
||
override class func spec() { | ||
|
||
var cancellables: Set<AnyCancellable> = Set() | ||
|
||
let allLanguages: [RealmLanguage] = SetUserPreferredAppLanguageRepositoryTests.getAllLanguages() | ||
|
||
let realmDatabase: RealmDatabase = TestsInMemoryRealmDatabase( | ||
addObjectsToDatabase: allLanguages | ||
) | ||
|
||
let testsDiContainer = TestsDiContainer(realmDatabase: realmDatabase) | ||
|
||
let setUserPreferredAppLanguageRepository = SetUserPreferredAppLanguageRepository( | ||
userAppLanguageRepository: testsDiContainer.feature.appLanguage.dataLayer.getUserAppLanguageRepository(), | ||
userLessonFiltersRepository: testsDiContainer.dataLayer.getUserLessonFiltersRepository(), | ||
languagesRepository: testsDiContainer.dataLayer.getLanguagesRepository() | ||
) | ||
|
||
let getUserLessonFiltersRepository = GetUserLessonFiltersRepository( | ||
userLessonFiltersRepository: testsDiContainer.dataLayer.getUserLessonFiltersRepository(), | ||
getLessonFilterLanguagesRepository: testsDiContainer.feature.lessonFilter.dataLayer.getLessonFilterLanguagesRepository() | ||
) | ||
|
||
describe("User is viewing the language settings.") { | ||
|
||
context("When the app language is switched from English to Spanish") { | ||
|
||
it("The user's lesson language filter should update to Spanish") { | ||
|
||
let appLanguageSpanish: AppLanguageDomainModel = LanguageCodeDomainModel.spanish.rawValue | ||
let realmLanguageSpanish = allLanguages.first(where: { $0.code == appLanguageSpanish.languageCode }) | ||
|
||
var lessonLanguageFilterRef: LessonFilterLanguageDomainModel? | ||
var sinkCompleted: Bool = false | ||
|
||
waitUntil { done in | ||
|
||
setUserPreferredAppLanguageRepository.setLanguagePublisher(appLanguage: appLanguageSpanish) | ||
.flatMap { _ in | ||
|
||
return getUserLessonFiltersRepository.getUserLessonLanguageFilterPublisher(translatedInAppLanguage: appLanguageSpanish) | ||
} | ||
.sink { lessonFilterLanguage in | ||
if sinkCompleted { | ||
return | ||
} | ||
|
||
sinkCompleted = true | ||
lessonLanguageFilterRef = lessonFilterLanguage | ||
|
||
done() | ||
} | ||
.store(in: &cancellables) | ||
} | ||
|
||
expect(realmLanguageSpanish).toNot(beNil()) | ||
expect(lessonLanguageFilterRef?.languageId).to(equal(realmLanguageSpanish?.id)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static func getAllLanguages() -> [RealmLanguage] { | ||
|
||
return [ | ||
getRealmLanguage(languageCode: .afrikaans), | ||
getRealmLanguage(languageCode: .arabic), | ||
getRealmLanguage(languageCode: .chinese), | ||
getRealmLanguage(languageCode: .czech), | ||
getRealmLanguage(languageCode: .english), | ||
getRealmLanguage(languageCode: .french), | ||
getRealmLanguage(languageCode: .hebrew), | ||
getRealmLanguage(languageCode: .latvian), | ||
getRealmLanguage(languageCode: .portuguese), | ||
getRealmLanguage(languageCode: .russian), | ||
getRealmLanguage(languageCode: .spanish), | ||
getRealmLanguage(languageCode: .vietnamese) | ||
] | ||
} | ||
|
||
private static func getRealmLanguage(languageCode: LanguageCodeDomainModel) -> RealmLanguage { | ||
|
||
return MockRealmLanguage.getLanguage(language: languageCode, name: languageCode.rawValue + " Name") | ||
} | ||
|
||
private static func getLocalizationServices() -> MockLocalizationServices { | ||
|
||
let localizableStrings: [MockLocalizationServices.LocaleId: [MockLocalizationServices.StringKey: String]] = [ | ||
LanguageCodeDomainModel.english.rawValue: [LessonFilterStringKeys.lessonsAvailableText.rawValue: "lessons available"] | ||
] | ||
|
||
return MockLocalizationServices.createLanguageNamesLocalizationServices( | ||
addAdditionalLocalizableStrings: localizableStrings | ||
) | ||
} | ||
|
||
private static func getTranslatedLanguageName() -> GetTranslatedLanguageName { | ||
|
||
let getTranslatedLanguageName = GetTranslatedLanguageName( | ||
localizationLanguageNameRepository: MockLocalizationLanguageNameRepository(localizationServices: SetUserPreferredAppLanguageRepositoryTests.getLocalizationServices()), | ||
localeLanguageName: MockLocaleLanguageName.defaultMockLocaleLanguageName(), | ||
localeRegionName: MockLocaleLanguageRegionName(regionNames: [:]), | ||
localeScriptName: MockLocaleLanguageScriptName(scriptNames: [:]) | ||
) | ||
|
||
return getTranslatedLanguageName | ||
} | ||
|
||
private static func getStringWithLocaleCount() -> StringWithLocaleCountInterface { | ||
|
||
return MockStringWithLocaleCount() | ||
} | ||
} |