Skip to content

Commit

Permalink
Adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
levieggertcru committed Sep 13, 2024
1 parent 2be235b commit e40e6b5
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:Tests/LocalizationServicesTests/LocalizationServices copy.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"configurations" : [
{
"id" : "AC3E41B3-57AC-410E-B023-A247A5081F79",
"name" : "Test Scheme Action",
"options" : {

}
}
],
"defaultOptions" : {
"language" : "es"
},
"testTargets" : [
{
"target" : {
"containerPath" : "container:",
"identifier" : "LocalizationServicesTests",
"name" : "LocalizationServicesTests"
}
}
],
"version" : 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ class LocalizableStringsBundleTests: XCTestCase {

func testEmptyKeyReturnsNil() {

XCTAssertNil(stringsBundle.stringForKey(key: ""), "Value returned should be nil.")
XCTAssertNil(stringsBundle.stringForKey(key: ""))
}

func testExistingPhraseReturnsAValue() {

XCTAssertEqual(stringsBundle.stringForKey(key: LocalizableStringsKeys.testValueYes.key), "yes", "Value should equal yes.")
// Expects System to be in Spanish. Configured in tests.

XCTAssertEqual(stringsBundle.stringForKey(key: LocalizableStringsKeys.testValueYes.key), "")
}

func testMissingPhraseReturnsANilValue() {

XCTAssertNil(stringsBundle.stringForKey(key: LocalizableStringsBundleTests.missingStringPhraseKey), "Value returned should be nil.")
XCTAssertNil(stringsBundle.stringForKey(key: LocalizableStringsBundleTests.missingStringPhraseKey))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ class LocalizableStringsRepositoryTests: XCTestCase {
XCTAssertEqual(localizedString, "")
}

func testStringForLocaleElseEnglishReturnsLocale() {

XCTAssertTrue(stringsRepository.stringForLocaleElseEnglish(localeIdentifier: LocaleId.spanish.id, key: "test.value.yes") == "")
}

func testStringForLocaleElseSystemElseEnglishReturnsLocale() {

XCTAssertTrue(stringsRepository.stringForLocaleElseSystemElseEnglish(localeIdentifier: LocaleId.spanish.id, key: "test.value.yes") == "")
}

func testStringForLocaleElseSystemElseEnglishReturnsEnglish() {

let localizedString: String? = stringsRepository.stringForLocaleElseSystemElseEnglish(localeIdentifier: LocaleId.spanish.id, key: "test.value.englishOnly")

XCTAssertTrue(localizedString == "English Only")
}

func testStringForLocaleReturnsNil() {

XCTAssertNil(stringsRepository.stringForLocale(localeIdentifier: nil, key: "test.value.yes"))
XCTAssertNil(stringsRepository.stringForLocale(localeIdentifier: "", key: "test.value.yes"))
}

func testStringForLocaleDoesNotExist() {

let localizedString: String? = stringsRepository.stringForLocale(
Expand Down Expand Up @@ -87,4 +110,21 @@ class LocalizableStringsRepositoryTests: XCTestCase {

XCTAssertNotNil(localizedString)
}

// MARK: - System

func testStringForSystemReturnsSpanishTranslationWhenSystemIsSpanish() {

// Expects System to be in Spanish. Configured in tests.

XCTAssertTrue(stringsRepository.stringForSystem(key: "test.value.yes") == "")
XCTAssertTrue(stringsRepository.stringForSystemElseEnglish(key: "test.value.yes") == "")
}

func testStringForSystemReturnsEnglishTranslationWhenSystemTranslationDoesNotExist() {

// Expects System to be in Spanish. Configured in tests.

XCTAssertTrue(stringsRepository.stringForSystemElseEnglish(key: "test.value.englishOnly") == "English Only")
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
"test.value.yes" = "yes";
"test.value.englishOnly" = "English Only";

0 comments on commit e40e6b5

Please sign in to comment.