From 7f0e810e3a9694f6dfe6ac90b94fec8f83d20d3f Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Fri, 16 Dec 2022 11:05:45 +0700 Subject: [PATCH] [#22] Rebase fix test --- iosApp/Survey.xcodeproj/project.pbxproj | 4 ++ .../Modules/Login/LoginView+DataSource.swift | 4 +- .../Splash/SplashView+DataSource.swift | 4 +- .../SurveySelection/SurveySelectionView.swift | 2 +- .../ViewModifiers/ViewDidLoadModifier.swift | 36 +++++++++++++++ .../AutoMockable/Shared+AutoMockable.swift | 2 + .../Helpers/KMM/DI/Koin/KoinApplication.swift | 2 +- .../Login/LoginViewDataSourceSpec.swift | 2 +- .../Modules/Login/LoginSpec.swift | 4 +- .../SurveySelection/SurveySelectionSpec.swift | 44 +++++++++++++------ .../network/core/TokenizedNetworkClient.kt | 5 --- .../repository/DeviceInfoRepositoryTest.kt | 2 +- .../SurveySelectionViewModelTest.kt | 17 +++++-- 13 files changed, 96 insertions(+), 32 deletions(-) create mode 100644 iosApp/Survey/Sources/Presentation/ViewModifiers/ViewDidLoadModifier.swift diff --git a/iosApp/Survey.xcodeproj/project.pbxproj b/iosApp/Survey.xcodeproj/project.pbxproj index 986ca544..1f3d9182 100644 --- a/iosApp/Survey.xcodeproj/project.pbxproj +++ b/iosApp/Survey.xcodeproj/project.pbxproj @@ -91,6 +91,7 @@ 09CE773428E2ED2300EAA9EE /* Typealias+Koin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09CE773128E2ED2300EAA9EE /* Typealias+Koin.swift */; }; 09FE26CD294B1EE3005A7F85 /* SurveySelectionView+DataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09FE26CC294B1EE3005A7F85 /* SurveySelectionView+DataSource.swift */; }; 09FE26D1294B26A0005A7F85 /* SurveySelectionViewDataSourceSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09FE26CF294B264B005A7F85 /* SurveySelectionViewDataSourceSpec.swift */; }; + 09FE26D3294C1906005A7F85 /* ViewDidLoadModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09FE26D2294C1905005A7F85 /* ViewDidLoadModifier.swift */; }; 351F5715D07BB9ED3F8B15F8 /* Pods_Survey.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 315DBBA2E56D199C3AC672B5 /* Pods_Survey.framework */; }; 3D0ADA9FBBF8D55D5F00610F /* OptionalUnwrapSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1EE1175F99D55A95E0995E9 /* OptionalUnwrapSpec.swift */; }; 5BBBFAF49689F25A8C1D57AB /* AutoMockable.generated.swift in Sources */ = {isa = PBXBuildFile; fileRef = A88CA60577ABA5F7885E1DE7 /* AutoMockable.generated.swift */; }; @@ -231,6 +232,7 @@ 09CE773128E2ED2300EAA9EE /* Typealias+Koin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Typealias+Koin.swift"; sourceTree = ""; }; 09FE26CC294B1EE3005A7F85 /* SurveySelectionView+DataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SurveySelectionView+DataSource.swift"; sourceTree = ""; }; 09FE26CF294B264B005A7F85 /* SurveySelectionViewDataSourceSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveySelectionViewDataSourceSpec.swift; sourceTree = ""; }; + 09FE26D2294C1905005A7F85 /* ViewDidLoadModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewDidLoadModifier.swift; sourceTree = ""; }; 122A6B9F6217729620D91A43 /* DebugProduction.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = DebugProduction.xcconfig; sourceTree = ""; }; 15C39F2CB60CF0314258019E /* Pods-Survey.debug production.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Survey.debug production.xcconfig"; path = "Target Support Files/Pods-Survey/Pods-Survey.debug production.xcconfig"; sourceTree = ""; }; 16E10E52E1F7EAF6527F4E27 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; @@ -444,6 +446,7 @@ 09636AFF28D4860F00A5CB97 /* PrimaryTextField.swift */, 09636B0128D4876100A5CB97 /* PrimaryButton.swift */, 09636B0C28D4917200A5CB97 /* OverlayButton.swift */, + 09FE26D2294C1905005A7F85 /* ViewDidLoadModifier.swift */, ); path = ViewModifiers; sourceTree = ""; @@ -1492,6 +1495,7 @@ buildActionMask = 2147483647; files = ( 0982A80729278E9000FC1976 /* SurveyHeaderLoading.swift in Sources */, + 09FE26D3294C1906005A7F85 /* ViewDidLoadModifier.swift in Sources */, 09CE772728E2C44D00EAA9EE /* View+BackButton.swift in Sources */, 0982A80329278E9000FC1976 /* SurveyHeaderView.swift in Sources */, 09636B0D28D4917200A5CB97 /* OverlayButton.swift in Sources */, diff --git a/iosApp/Survey/Sources/Presentation/Modules/Login/LoginView+DataSource.swift b/iosApp/Survey/Sources/Presentation/Modules/Login/LoginView+DataSource.swift index e05e128b..a5c5e7ec 100644 --- a/iosApp/Survey/Sources/Presentation/Modules/Login/LoginView+DataSource.swift +++ b/iosApp/Survey/Sources/Presentation/Modules/Login/LoginView+DataSource.swift @@ -14,7 +14,7 @@ import Shared protocol LoginCoordinator { func showResetPassword() - func showHomeLoading() + func showHome() } extension LoginView { @@ -73,7 +73,7 @@ extension LoginView { showingLoading = state.isLoading showingErrorAlert = !state.error.string.isEmpty if state.isSuccess { - coordinator.showHomeLoading() + coordinator.showHome() } } } diff --git a/iosApp/Survey/Sources/Presentation/Modules/Splash/SplashView+DataSource.swift b/iosApp/Survey/Sources/Presentation/Modules/Splash/SplashView+DataSource.swift index b4492fad..a82416a0 100644 --- a/iosApp/Survey/Sources/Presentation/Modules/Splash/SplashView+DataSource.swift +++ b/iosApp/Survey/Sources/Presentation/Modules/Splash/SplashView+DataSource.swift @@ -15,7 +15,7 @@ import SwiftUI protocol SplashCoordinator { func showLogin() - func showHomeLoading() + func showHome() } extension SplashView { @@ -58,7 +58,7 @@ extension SplashView { guard !viewState.isLoading else { return } withAnimation(.linear(duration: .fast)) { if viewState.isLogin { - coordinator.showHomeLoading() + coordinator.showHome() } else { coordinator.showLogin() } diff --git a/iosApp/Survey/Sources/Presentation/Modules/SurveySelection/SurveySelectionView.swift b/iosApp/Survey/Sources/Presentation/Modules/SurveySelection/SurveySelectionView.swift index 187c9367..c3d73739 100644 --- a/iosApp/Survey/Sources/Presentation/Modules/SurveySelection/SurveySelectionView.swift +++ b/iosApp/Survey/Sources/Presentation/Modules/SurveySelection/SurveySelectionView.swift @@ -46,7 +46,7 @@ struct SurveySelectionView: View { } .accessibilityElement(children: .contain) .accessibility(.surveySelection(.view)) - .onAppear { + .onLoad { dataSource.fetch() } } diff --git a/iosApp/Survey/Sources/Presentation/ViewModifiers/ViewDidLoadModifier.swift b/iosApp/Survey/Sources/Presentation/ViewModifiers/ViewDidLoadModifier.swift new file mode 100644 index 00000000..723aeaa8 --- /dev/null +++ b/iosApp/Survey/Sources/Presentation/ViewModifiers/ViewDidLoadModifier.swift @@ -0,0 +1,36 @@ +// +// ViewDidLoadModifier.swift +// Survey +// +// Created by Bliss on 16/12/22. +// Copyright © 2022 Nimble. All rights reserved. +// + +import SwiftUI + +struct ViewDidLoadModifier: ViewModifier { + + @State private var didLoad = false + + private let action: (() -> Void)? + + init(perform action: (() -> Void)? = nil) { + self.action = action + } + + func body(content: Content) -> some View { + content.onAppear { + if didLoad == false { + didLoad = true + action?() + } + } + } +} + +extension View { + + func onLoad(perform action: (() -> Void)? = nil) -> some View { + modifier(ViewDidLoadModifier(perform: action)) + } +} diff --git a/iosApp/Survey/Sources/Supports/Helpers/KMM/AutoMockable/Shared+AutoMockable.swift b/iosApp/Survey/Sources/Supports/Helpers/KMM/AutoMockable/Shared+AutoMockable.swift index ed63bc4d..4a4c4279 100644 --- a/iosApp/Survey/Sources/Supports/Helpers/KMM/AutoMockable/Shared+AutoMockable.swift +++ b/iosApp/Survey/Sources/Supports/Helpers/KMM/AutoMockable/Shared+AutoMockable.swift @@ -38,6 +38,8 @@ protocol CheckLoginUseCaseKMM: CheckLoginUseCase { @escaping (Error?, KotlinUnit) -> KotlinUnit ) -> () -> KotlinUnit } + +// sourcery: AutoMockable protocol GetCurrentDateUseCaseKMM: GetCurrentDateUseCase { func invoke() -> Kotlinx_coroutines_coreFlow diff --git a/iosApp/Survey/Sources/Supports/Helpers/KMM/DI/Koin/KoinApplication.swift b/iosApp/Survey/Sources/Supports/Helpers/KMM/DI/Koin/KoinApplication.swift index 94f5168d..dab1b270 100644 --- a/iosApp/Survey/Sources/Supports/Helpers/KMM/DI/Koin/KoinApplication.swift +++ b/iosApp/Survey/Sources/Supports/Helpers/KMM/DI/Koin/KoinApplication.swift @@ -23,7 +23,7 @@ extension KoinApplication { private static let keyPaths: [PartialKeyPath] = [ \.logInViewModel, \.resetPasswordViewModel, - \.splashViewModel + \.splashViewModel, \.surveySelectionViewModel ] diff --git a/iosApp/SurveyTests/Sources/Specs/Presentation/Modules/Login/LoginViewDataSourceSpec.swift b/iosApp/SurveyTests/Sources/Specs/Presentation/Modules/Login/LoginViewDataSourceSpec.swift index 5ec18ab8..06ab982a 100644 --- a/iosApp/SurveyTests/Sources/Specs/Presentation/Modules/Login/LoginViewDataSourceSpec.swift +++ b/iosApp/SurveyTests/Sources/Specs/Presentation/Modules/Login/LoginViewDataSourceSpec.swift @@ -93,7 +93,7 @@ final class LoginViewDataSourceSpec: QuickSpec { it("coordinator shows home") { try self.awaitPublisher(dataSource.$viewState.collectNext(3)) - expect(loginCoordinator.showHomeLoadingCallsCount) == 1 + expect(loginCoordinator.showHomeCallsCount) == 1 } } diff --git a/iosApp/SurveyUITests/Sources/Specs/Presentation/Modules/Login/LoginSpec.swift b/iosApp/SurveyUITests/Sources/Specs/Presentation/Modules/Login/LoginSpec.swift index e8f875e4..9e49e247 100644 --- a/iosApp/SurveyUITests/Sources/Specs/Presentation/Modules/Login/LoginSpec.swift +++ b/iosApp/SurveyUITests/Sources/Specs/Presentation/Modules/Login/LoginSpec.swift @@ -55,8 +55,8 @@ final class LoginSpec: QuickSpec { } it("shows home screen") { - let surveyLoadingScreen = SurveyLoadingScreen(in: app) - surveyLoadingScreen.waitForExistence(timeout: .default, with: .view) + let surveySelectionScreen = SurveySelectionScreen(in: app) + surveySelectionScreen.waitForExistence(timeout: .default, with: .view) } } diff --git a/iosApp/SurveyUITests/Sources/Specs/Presentation/Modules/SurveySelection/SurveySelectionSpec.swift b/iosApp/SurveyUITests/Sources/Specs/Presentation/Modules/SurveySelection/SurveySelectionSpec.swift index 941a7b48..46dd6c2c 100644 --- a/iosApp/SurveyUITests/Sources/Specs/Presentation/Modules/SurveySelection/SurveySelectionSpec.swift +++ b/iosApp/SurveyUITests/Sources/Specs/Presentation/Modules/SurveySelection/SurveySelectionSpec.swift @@ -36,20 +36,36 @@ final class SurveySelectionSpec: QuickSpec { } it("it shows its ui components") { - let mainImage = surveySelectionScreen.find(\.images, with: .mainImage) - expect(mainImage.exists) == true - - let titleText = surveySelectionScreen.find(\.staticTexts, with: .titleText) - expect(titleText.exists) == true - - let detailText = surveySelectionScreen.find(\.staticTexts, with: .detailText) - expect(detailText.exists) == true - - let nextButton = surveySelectionScreen.find(\.buttons, with: .nextButton) - expect(nextButton.exists) == true - - let headerView = surveySelectionScreen.find(\.staticTexts, with: .header) - expect(headerView.exists) == true + surveySelectionScreen.waitForExistence( + timeout: .default, + \.images, + with: .mainImage + ) + surveySelectionScreen.waitForExistence( + timeout: .instant, + \.staticTexts, + with: .titleText + ) + surveySelectionScreen.waitForExistence( + timeout: .instant, + \.staticTexts, + with: .detailText + ) + surveySelectionScreen.waitForExistence( + timeout: .instant, + \.buttons, + with: .nextButton + ) + surveySelectionScreen.waitForExistence( + timeout: .instant, + \.staticTexts, + with: .header + ) + surveySelectionScreen.waitForExistence( + timeout: .instant, + \.images, + with: .header + ) } } } diff --git a/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/data/network/core/TokenizedNetworkClient.kt b/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/data/network/core/TokenizedNetworkClient.kt index 1e635f5a..4f96372f 100644 --- a/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/data/network/core/TokenizedNetworkClient.kt +++ b/shared/src/commonMain/kotlin/co/nimblehq/blisskmmic/data/network/core/TokenizedNetworkClient.kt @@ -44,11 +44,6 @@ class TokenizedNetworkClient: NetworkClient { BearerTokens(accessToken, refreshToken) } } - sendWithoutRequest { request -> - val builder = HttpRequestBuilder() - builder.url("${BuildKonfig.BASE_URL}") - request.url.host != builder.url.host - } } } } diff --git a/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/data/repository/DeviceInfoRepositoryTest.kt b/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/data/repository/DeviceInfoRepositoryTest.kt index bf9e178a..dbf4f3b4 100644 --- a/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/data/repository/DeviceInfoRepositoryTest.kt +++ b/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/data/repository/DeviceInfoRepositoryTest.kt @@ -15,7 +15,7 @@ private const val TIME: Long = 100_000 @UsesMocks(Clock::class) @ExperimentalCoroutinesApi class DeviceInfoRepositoryTest { - + private val mocker = Mocker() private val clock = MockClock(mocker) private val instant = Instant.fromEpochSeconds(TIME) diff --git a/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/presentation/modules/surveyselection/SurveySelectionViewModelTest.kt b/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/presentation/modules/surveyselection/SurveySelectionViewModelTest.kt index 4d8051bd..5befe7fe 100644 --- a/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/presentation/modules/surveyselection/SurveySelectionViewModelTest.kt +++ b/shared/src/commonTest/kotlin/co/nimblehq/blisskmmic/presentation/modules/surveyselection/SurveySelectionViewModelTest.kt @@ -7,9 +7,11 @@ import co.nimblehq.blisskmmic.domain.model.User import co.nimblehq.blisskmmic.domain.platform.datetime.DateTimeFormatter import co.nimblehq.blisskmmic.domain.usecase.GetCurrentDateUseCase import co.nimblehq.blisskmmic.domain.usecase.GetProfileUseCase +import co.nimblehq.blisskmmic.helpers.constant.FLOW_DELAY import io.kotest.matchers.shouldBe import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.newSingleThreadContext @@ -93,7 +95,10 @@ class SurveySelectionViewModelTest : TestsWithMocks() { fun `When calling fetch with fail date and success user- it changes viewState with correct item`() = runTest { mocker.every { getCurrentDateUseCase() - } returns flow { error("") } + } returns flow { + delay(FLOW_DELAY) + error("") + } mocker.every { getProfileUseCase() } returns flowOf(user) @@ -120,7 +125,10 @@ class SurveySelectionViewModelTest : TestsWithMocks() { } returns flowOf(dateComponent) mocker.every { getProfileUseCase() - } returns flow { error("") } + } returns flow { + delay(FLOW_DELAY) + error("") + } surveySelectionViewModel.fetch() @@ -144,7 +152,10 @@ class SurveySelectionViewModelTest : TestsWithMocks() { } returns flow { error("") } mocker.every { getProfileUseCase() - } returns flow { error("") } + } returns flow { + delay(FLOW_DELAY) + error("") + } surveySelectionViewModel.fetch()