Skip to content

Commit

Permalink
[#10] Fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
blyscuit committed Dec 17, 2022
1 parent e92e175 commit d403c28
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ extension LoginView {
@Published private(set) var viewState = LoginViewState()
@Published var showingErrorAlert = false
@Published var showingLoading = false
@Published var showingEmailError = false
@Published var showingPasswordError = false

private var cancellables = Set<AnyCancellable>()

Expand Down Expand Up @@ -66,6 +68,8 @@ extension LoginView {

private func updateStates(_ state: LoginViewState) {
viewState = state
showingEmailError = state.isEmailError
showingPasswordError = state.isPasswordError
showingLoading = state.isLoading
showingErrorAlert = !state.error.string.isEmpty
if state.isSuccess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct LoginView: View {
.autocapitalization(.none)
.disableAutocorrection(true)
.keyboardType(.emailAddress)
.primaryTextField(error: dataSource.viewState.isEmailError)
.primaryTextField(error: $dataSource.showingEmailError)
.accessibility(.login(.emailField))
}

Expand All @@ -99,7 +99,7 @@ struct LoginView: View {
.accessibility(.login(.forgotButton))
}
}
.primaryTextField(error: dataSource.viewState.isPasswordError)
.primaryTextField(error: $dataSource.showingPasswordError)
.frame(maxHeight: 56.0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI

struct PrimaryTextField: ViewModifier {

let error: Bool
@Binding var error: Bool

func body(content: Content) -> some View {
ZStack {
Expand All @@ -31,7 +31,7 @@ struct PrimaryTextField: ViewModifier {

extension View {

func primaryTextField(error: Bool = false) -> some View {
func primaryTextField(error: Binding<Bool> = .constant(false)) -> some View {
modifier(PrimaryTextField(error: error))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ import Shared
protocol ResetPasswordUseCaseKMM: ResetPasswordUseCase {

func invoke(email: String) -> Kotlinx_coroutines_coreFlow
func invokeNative(email: String)
-> (
@escaping (String, KotlinUnit) -> KotlinUnit,
@escaping (Error?, KotlinUnit) -> KotlinUnit
) -> () -> KotlinUnit
func invokeNative(email: String) -> (
@escaping (String, KotlinUnit) -> KotlinUnit,
@escaping (Error?, KotlinUnit) -> KotlinUnit
) -> () -> KotlinUnit
}

// sourcery: AutoMockable
protocol LogInUseCaseKMM: LogInUseCase {

func invoke(email: String, password: String) -> Kotlinx_coroutines_coreFlow
func invokeNative(email: String, password: String)
-> (
@escaping (Token, KotlinUnit) -> KotlinUnit,
@escaping (Error?, KotlinUnit) -> KotlinUnit
) -> () -> KotlinUnit
func invokeNative(email: String, password: String) -> (
@escaping (Token, KotlinUnit) -> KotlinUnit,
@escaping (Error?, KotlinUnit) -> KotlinUnit
) -> () -> KotlinUnit
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,26 @@ final class LoginViewDataSourceSpec: QuickSpec {
expect(viewState?.isSuccess) == false
}

it("has no loading state") {
let viewState = try self.awaitPublisher(dataSource.$viewState.collectNext(1)).last
expect(viewState?.isLoading) == false
it("showingLoading is false") {
let showingLoading = try self.awaitPublisher(dataSource.$showingLoading.collectNext(1)).last
expect(showingLoading) == false
}

it("has no error state") {
let viewState = try self.awaitPublisher(dataSource.$viewState.collectNext(1)).last
expect(viewState?.error) == nil
it("showingErrorAlert is false") {
let showingErrorAlert = try self.awaitPublisher(dataSource.$showingErrorAlert.collectNext(1)).last
expect(showingErrorAlert) == false
}

it("has no email error state") {
let viewState = try self.awaitPublisher(dataSource.$viewState.collectNext(1)).last
expect(viewState?.isEmailError) == false
it("showingEmailError is false") {
let showingEmailError = try self.awaitPublisher(dataSource.$showingEmailError.collectNext(1)).last
expect(showingEmailError) == false
}

it("has no password error state") {
let viewState = try self.awaitPublisher(dataSource.$viewState.collectNext(1)).last
expect(viewState?.isPasswordError) == false
it("showingPasswordError is false") {
let showingPasswordError = try self.awaitPublisher(
dataSource.$showingPasswordError.collectNext(1)
).last
expect(showingPasswordError) == false
}
}

Expand All @@ -68,9 +70,9 @@ final class LoginViewDataSourceSpec: QuickSpec {
dataSource.login()
}

it("sets loading state") {
let viewState = try self.awaitPublisher(dataSource.$viewState.collectNext(2)).last
expect(viewState?.isLoading) == true
it("showingPasswordError is true") {
let showingPasswordError = try self.awaitPublisher(dataSource.$showingLoading.collectNext(2)).last
expect(showingPasswordError) == true
}

context("when it return token") {
Expand Down Expand Up @@ -106,9 +108,11 @@ final class LoginViewDataSourceSpec: QuickSpec {
dataSource.login()
}

it("sets showingErrorAlert to true") {
let showingError = try self.awaitPublisher(dataSource.$showingErrorAlert.collectNext(3)).last
expect(showingError) == true
it("showingErrorAlert is true") {
let showingErrorAlert = try self.awaitPublisher(
dataSource.$showingErrorAlert.collectNext(3)
).last
expect(showingErrorAlert) == true
}

it("sets correct error state") {
Expand Down
3 changes: 0 additions & 3 deletions iosApp/SurveyUITests/Sources/Flows/LoginFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ final class LoginFlow {
}

func execute() {
let uiTestConfig = SharedBuildConfig.UITestConfig()
let loginScreen = LoginScreen(in: app)
loginScreen.waitForExistence()
loginScreen.replaceInInField(.emailField, with: uiTestConfig.email())
loginScreen.replaceInSecuredField(.passwordField, with: uiTestConfig.password())
loginScreen.tapButton(.loginButton)
}
}
1 change: 1 addition & 0 deletions iosApp/fastlane/Managers/TestManager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def build_and_test(scheme:, targets:)
result_bundle: true,
only_testing: targets,
number_of_retries: 2,
output_remove_retry_attempts: true,
fail_build: false
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ fun String.isValidEmail(): Boolean {

val expression = "\\b[\\w\\.-]+@[\\w\\.-]+\\.\\w{2,4}\\b"
val regex = Regex(expression)
return this.isNotEmpty() && this.matches(regex)
return isNotEmpty() && matches(regex)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ class LoginViewModel(private val logInUseCase: LogInUseCase): BaseViewModel() {
val viewState: StateFlow<LoginViewState> = mutableViewState

fun login(email: String, password: String) {
if (!validInput(email, password)) {
return
}
if (!validInput(email, password)) return
setStateLoading()
viewModelScope.launch {
logInUseCase(email, password)
Expand Down

0 comments on commit d403c28

Please sign in to comment.