Skip to content
This repository was archived by the owner on Jun 12, 2025. It is now read-only.

Commit 26a2147

Browse files
[iOS] Add workaround for using Moko in tests and previews (#114)
* [iOS] Add workaround for using Moko in tests and previews * [iOS] Remove no longer needed hack for .module
1 parent caa5068 commit 26a2147

16 files changed

Lines changed: 92 additions & 80 deletions

File tree

android/shared/src/main/res/values-en/generated_strings.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- Android Strings File -->
3-
<!-- Generated by Twine 1.1.2 -->
3+
<!-- Generated by Twine 1.1.3 -->
44
<!-- Language: en -->
55
<resources>
66
<!-- SECTION: General -->
@@ -249,9 +249,7 @@
249249
<string name="recipe_tipkit_popover_tip_title">This tip is floating, you can define arrow anchors</string>
250250
<string name="recipe_tipkit_popover_tip_message">This message is optional</string>
251251
<string name="recipe_tipkit_rule_tip_title">This tip has rule that appears the tip after 3 taps on button</string>
252-
<string name="recipe_tipkit_rule_tip_message">If you close the tip you will have to restart the app for appear tip
253-
again
254-
</string>
252+
<string name="recipe_tipkit_rule_tip_message">If you close the tip you will have to restart the app for appear tip again</string>
255253
<string name="recipe_tipkit_title">Example of TipKit</string>
256254
<string name="recipe_tipkit_inline_tip">Inline tip</string>
257255
<string name="recipe_tipkit_rule_tip">Rule tip</string>

android/shared/src/main/res/values-sk/generated_strings.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- Android Strings File -->
3-
<!-- Generated by Twine 1.1.2 -->
3+
<!-- Generated by Twine 1.1.3 -->
44
<!-- Language: sk -->
55
<resources>
66
<!-- SECTION: General -->
@@ -248,11 +248,8 @@
248248
<string name="recipe_tipkit_inline_tip_message">Táto správa je nepovinná</string>
249249
<string name="recipe_tipkit_popover_tip_title">Tento tip je plávajúci, môžete definovať kotvy šípok</string>
250250
<string name="recipe_tipkit_popover_tip_message">Táto správa je nepovinná</string>
251-
<string name="recipe_tipkit_rule_tip_title">Tento tip má pravidlo, že sa tip zobrazí po 3 ťuknutiach na tlačidlo
252-
</string>
253-
<string name="recipe_tipkit_rule_tip_message">Ak tip zatvoríte, budete musieť reštartovať aplikáciu, aby sa tip opäť
254-
zobrazil
255-
</string>
251+
<string name="recipe_tipkit_rule_tip_title">Tento tip má pravidlo, že sa tip zobrazí po 3 ťuknutiach na tlačidlo</string>
252+
<string name="recipe_tipkit_rule_tip_message">Ak tip zatvoríte, budete musieť reštartovať aplikáciu, aby sa tip opäť zobrazil</string>
256253
<string name="recipe_tipkit_title">Príklady TipKita</string>
257254
<string name="recipe_tipkit_inline_tip">Inline tip</string>
258255
<string name="recipe_tipkit_rule_tip">Rule tip</string>

android/shared/src/main/res/values/generated_strings.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- Android Strings File -->
3-
<!-- Generated by Twine 1.1.2 -->
3+
<!-- Generated by Twine 1.1.3 -->
44
<!-- Language: cs -->
55
<resources>
66
<!-- SECTION: General -->
@@ -248,11 +248,8 @@
248248
<string name="recipe_tipkit_inline_tip_message">Tahle zpráva je nepovinná</string>
249249
<string name="recipe_tipkit_popover_tip_title">Tento tip je plovoucí, můžete definovat kotvy šipek</string>
250250
<string name="recipe_tipkit_popover_tip_message">Tahle zpráva je nepovinná</string>
251-
<string name="recipe_tipkit_rule_tip_title">Tento tip má pravidlo, že se tip objeví po 3 klepnutích na tlačítko
252-
</string>
253-
<string name="recipe_tipkit_rule_tip_message">Pokud tip zavřete, budete muset aplikaci restartovat, aby se tip znovu
254-
objevil.
255-
</string>
251+
<string name="recipe_tipkit_rule_tip_title">Tento tip má pravidlo, že se tip objeví po 3 klepnutích na tlačítko</string>
252+
<string name="recipe_tipkit_rule_tip_message">Pokud tip zavřete, budete muset aplikaci restartovat, aby se tip znovu objevil.</string>
256253
<string name="recipe_tipkit_title">Příklady TipKitu</string>
257254
<string name="recipe_tipkit_inline_tip">Inline tip</string>
258255
<string name="recipe_tipkit_rule_tip">Rule tip</string>

ios/PresentationLayer/Onboarding/Sources/Onboarding/Errors/ValidationError.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ extension ValidationError: LocalizedError {
1313
switch self {
1414
case .email(let reason):
1515
switch reason {
16-
#warning("TODO: Use MR strings when issue [https://github.com/icerockdev/moko-resources/issues/714] is resolved")
17-
case .isEmpty: "Invalid email format" // MR.strings().invalid_email.desc().localized()
16+
case .isEmpty: return MR.strings().invalid_email.desc().localized()
1817
}
1918
case .password(let reason):
2019
switch reason {
21-
#warning("TODO: Use MR strings when issue [https://github.com/icerockdev/moko-resources/issues/714] is resolved")
22-
case .isEmpty: "Invalid password" // MR.strings().invalid_password.desc().localized()
20+
case .isEmpty: return MR.strings().invalid_password.desc().localized()
2321
}
2422
}
2523
}

ios/PresentationLayer/Onboarding/Tests/OnboardingTests/LoginViewModelTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ final class LoginViewModelTests: XCTestCase {
102102
func testLoginInvalidPassword() async {
103103
let vm = createViewModel()
104104
let errorResult = AuthError.InvalidLoginCredentials(throwable: nil)
105-
#warning("TODO: Use localizedMessage when issue [https://github.com/icerockdev/moko-resources/issues/714] is resolved")
105+
fixMokoResourcesForTests()
106106
loginUseCase.executeThrowableError = KmmLocalizedError(
107107
errorResult: errorResult,
108-
localizedMessage: "" // errorResult.localizedMessage(nil)
108+
localizedMessage: errorResult.localizedMessage(nil)
109109
)
110110

111111
vm.onIntent(.changeEmail(LoginData.stubValid.email))

ios/PresentationLayer/Onboarding/Tests/OnboardingTests/RegistrationViewModelTests.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ final class RegistrationViewModelTests: XCTestCase {
3030
// MARK: Tests
3131

3232
func testRegisterEmptyEmail() async {
33+
fixMokoResourcesForTests()
3334
let vm = createViewModel()
3435
registrationUseCase.executeThrowableError = ValidationError.email(.isEmpty)
3536

@@ -39,14 +40,13 @@ final class RegistrationViewModelTests: XCTestCase {
3940
await vm.awaitAllTasks()
4041

4142
XCTAssert(!vm.state.isLoading)
42-
#warning("TODO: Use MR strings when issue [https://github.com/icerockdev/moko-resources/issues/714] is resolved")
43-
// XCTAssertEqual(vm.state.alert, AlertData(title: MR.strings().invalid_email.desc().localized()))
44-
XCTAssertEqual(vm.state.alert, AlertData(title: "Invalid email format"))
43+
XCTAssertEqual(vm.state.alert, AlertData(title: MR.strings().invalid_email.desc().localized()))
4544
XCTAssertEqual(fc.handleFlowValue, nil)
4645
XCTAssert(registrationUseCase.executeReceivedInvocations == [.stubEmptyEmail])
4746
}
4847

4948
func testRegisterEmptyPassword() async {
49+
fixMokoResourcesForTests()
5050
let vm = createViewModel()
5151
registrationUseCase.executeThrowableError = ValidationError.password(.isEmpty)
5252

@@ -56,9 +56,7 @@ final class RegistrationViewModelTests: XCTestCase {
5656
await vm.awaitAllTasks()
5757

5858
XCTAssert(!vm.state.isLoading)
59-
#warning("TODO: Use MR strings when issue [https://github.com/icerockdev/moko-resources/issues/714] is resolved")
60-
// XCTAssertEqual(vm.state.alert, AlertData(title: MR.strings().invalid_password.desc().localized()))
61-
XCTAssertEqual(vm.state.alert, AlertData(title: "Invalid password"))
59+
XCTAssertEqual(vm.state.alert, AlertData(title: MR.strings().invalid_password.desc().localized()))
6260
XCTAssertEqual(fc.handleFlowValue, nil)
6361
XCTAssert(registrationUseCase.executeReceivedInvocations == [.stubEmptyPassword])
6462
}

ios/PresentationLayer/UIToolkit/Sources/UIToolkit/Extensions/Bundle+Extensions.swift

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Created by Petr Chmelar on 30.05.2022
3+
// Copyright © 2022 Matee. All rights reserved.
4+
//
5+
6+
import Foundation
7+
8+
private final class BundleToken {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Created by Julia Jakubcova on 23/09/2024
3+
// Copyright © 2024 Matee. All rights reserved.
4+
//
5+
6+
import DevstackKmpShared
7+
8+
#warning("TODO: Remove this workaround when issue [https://github.com/icerockdev/moko-resources/issues/714] is resolved")
9+
public func fixMokoResourcesForTests() {
10+
if ProcessInfo.processInfo.processName == "xctest" {
11+
MokoResourcesPreviewWorkaroundKt.nsBundle = Bundle.init(for: KotlinBase.self)
12+
}
13+
}
14+
15+
#warning("TODO: Remove this workaround when issue [https://github.com/icerockdev/moko-resources/issues/714] is resolved")
16+
public func fixMokoResourcesForPreviews() {
17+
if ProcessInfo.processInfo.processName == "XCPreviewAgent" {
18+
MokoResourcesPreviewWorkaroundKt.nsBundle = Bundle.init(for: KotlinBase.self)
19+
}
20+
}

ios/PresentationLayer/UIToolkit/Sources/UIToolkit/Utilities/Plurals.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ public enum Plurals: String {
2222

2323
func stringForCount(_ count: Int) -> String {
2424
if count == 0 { // swiftlint:disable:this empty_count
25-
return String(format: NSLocalizedString("zero_\(rawValue)", bundle: .myModule, comment: ""), count)
25+
return String(format: NSLocalizedString("zero_\(rawValue)", bundle: .module, comment: ""), count)
2626
} else if abs(count) == 1 {
27-
return String(format: NSLocalizedString("one_\(rawValue)", bundle: .myModule, comment: ""), count)
27+
return String(format: NSLocalizedString("one_\(rawValue)", bundle: .module, comment: ""), count)
2828
} else if abs(count) > 1 && abs(count) < 5 {
29-
return String(format: NSLocalizedString("few_\(rawValue)", bundle: .myModule, comment: ""), count)
29+
return String(format: NSLocalizedString("few_\(rawValue)", bundle: .module, comment: ""), count)
3030
} else if abs(count) >= 5 {
31-
return String(format: NSLocalizedString("many_\(rawValue)", bundle: .myModule, comment: ""), count)
31+
return String(format: NSLocalizedString("many_\(rawValue)", bundle: .module, comment: ""), count)
3232
} else {
33-
return String(format: NSLocalizedString("other_\(rawValue)", bundle: .myModule, comment: ""), count)
33+
return String(format: NSLocalizedString("other_\(rawValue)", bundle: .module, comment: ""), count)
3434
}
3535
}
3636
}

0 commit comments

Comments
 (0)