Skip to content

Commit

Permalink
Merge pull request #2243 from CruGlobal/GT-2425-Lesson-Filter-set-to-…
Browse files Browse the repository at this point in the history
…App-Language-Test

GT-2425 lesson filter set to app language test
  • Loading branch information
rachaelblue authored Aug 7, 2024
2 parents 8f675f5 + 2697eb3 commit 89b8fe7
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
4 changes: 4 additions & 0 deletions godtools.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,7 @@
D4C14E9229411A35001465F1 /* MobileContentAuthTokenDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C14E9129411A35001465F1 /* MobileContentAuthTokenDataModel.swift */; };
D4C26CA62C518EF70082B479 /* ToolFilterAnyCategoryDomainModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C26CA52C518EF70082B479 /* ToolFilterAnyCategoryDomainModel.swift */; };
D4C26CAA2C529C090082B479 /* ToolFilterAnyLanguageDomainModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C26CA92C529C090082B479 /* ToolFilterAnyLanguageDomainModel.swift */; };
D4C26CB22C5D1EAB0082B479 /* SetUserPreferredAppLanguageRepositoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C26CB12C5D1EAB0082B479 /* SetUserPreferredAppLanguageRepositoryTests.swift */; };
D4C2A5532C2E31C10035AB4D /* LessonFilterLanguageSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C2A5522C2E31C10035AB4D /* LessonFilterLanguageSelectionView.swift */; };
D4C2A5552C2E32030035AB4D /* LessonFilterLanguageSelectionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C2A5542C2E32030035AB4D /* LessonFilterLanguageSelectionViewModel.swift */; };
D4C2A5602C30906C0035AB4D /* ViewLessonFilterLanguagesUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C2A55F2C30906C0035AB4D /* ViewLessonFilterLanguagesUseCase.swift */; };
Expand Down Expand Up @@ -3320,6 +3321,7 @@
D4C14E9129411A35001465F1 /* MobileContentAuthTokenDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MobileContentAuthTokenDataModel.swift; sourceTree = "<group>"; };
D4C26CA52C518EF70082B479 /* ToolFilterAnyCategoryDomainModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolFilterAnyCategoryDomainModel.swift; sourceTree = "<group>"; };
D4C26CA92C529C090082B479 /* ToolFilterAnyLanguageDomainModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolFilterAnyLanguageDomainModel.swift; sourceTree = "<group>"; };
D4C26CB12C5D1EAB0082B479 /* SetUserPreferredAppLanguageRepositoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetUserPreferredAppLanguageRepositoryTests.swift; sourceTree = "<group>"; };
D4C2A5522C2E31C10035AB4D /* LessonFilterLanguageSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LessonFilterLanguageSelectionView.swift; sourceTree = "<group>"; };
D4C2A5542C2E32030035AB4D /* LessonFilterLanguageSelectionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LessonFilterLanguageSelectionViewModel.swift; sourceTree = "<group>"; };
D4C2A55F2C30906C0035AB4D /* ViewLessonFilterLanguagesUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewLessonFilterLanguagesUseCase.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -8808,6 +8810,7 @@
45D85C172BE0E9700003CE32 /* GetLanguageSettingsInterfaceStringsRepositoryTests.swift */,
45AE8FB32BDFFA7D0065D6B4 /* SearchAppLanguageInAppLanguagesListRepositoryTests.swift */,
45D85C152BE0E5050003CE32 /* SearchLanguageInDownloadableLanguagesRepositoryTests.swift */,
D4C26CB12C5D1EAB0082B479 /* SetUserPreferredAppLanguageRepositoryTests.swift */,
457719A82BE00EC900E7E4D8 /* StoreInitialAppLanguageTests.swift */,
);
path = "Data-DomainInterface";
Expand Down Expand Up @@ -13770,6 +13773,7 @@
45CC42F92C38981F00B0D82B /* MockLocalizationLanguageNameRepository.swift in Sources */,
458539322C57C08000748BAF /* MockRealmResource.swift in Sources */,
450FB88C2BFBA0F80015D945 /* SearchAppLanguageInAppLanguagesListRepositoryTests.swift in Sources */,
D4C26CB22C5D1EAB0082B479 /* SetUserPreferredAppLanguageRepositoryTests.swift in Sources */,
450FB88D2BFBA0F80015D945 /* GetAppLanguagesInterfaceStringsRepositoryTests.swift in Sources */,
450FB88E2BFBA0F80015D945 /* SearchLanguageInDownloadableLanguagesRepositoryTests.swift in Sources */,
45CC43022C38982800B0D82B /* MockLocaleLanguageScriptName.swift in Sources */,
Expand Down
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()
}
}

0 comments on commit 89b8fe7

Please sign in to comment.