-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoginFeatureTests.swift
More file actions
200 lines (155 loc) · 5.29 KB
/
Copy pathLoginFeatureTests.swift
File metadata and controls
200 lines (155 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//
// LoginFeatureTests.swift
// DevLogPresentationTests
//
// Created by opfic on 6/5/26.
//
import Testing
import ComposableArchitecture
import Foundation
import DevLogDomain
@testable import DevLogPresentation
@MainActor
struct LoginFeatureTests {
@Test("로그인 버튼을 누르면 선택한 인증 제공자로 로그인 유스케이스가 호출된다")
func 로그인_버튼을_누르면_선택한_인증_제공자로_로그인_유스케이스가_호출된다() async {
let spy = SignInUseCaseSpy()
let driver = LoginTestDriver(useCase: spy)
driver.tapSignInButton(.github)
await waitUntil {
spy.calledProviders == [.github]
}
#expect(spy.calledProviders == [.github])
}
@Test("로그인 성공 후에도 메인 화면 전환 전까지 로딩 상태를 유지한다")
func 로그인_성공_후에도_메인_화면_전환_전까지_로딩_상태를_유지한다() async {
let spy = SignInUseCaseSpy()
spy.shouldSuspend = true
let driver = LoginTestDriver(useCase: spy)
driver.tapSignInButton(.google)
await waitUntil {
driver.isLoading
}
#expect(driver.isLoading)
spy.resume()
await waitUntil {
spy.successfulProviders == [.google]
}
#expect(driver.isLoading)
}
@Test("로그인 실패 후에도 로딩 상태가 꺼진다")
func 로그인_실패_후에도_로딩_상태가_꺼진다() async {
let spy = SignInUseCaseSpy()
spy.shouldSuspend = true
spy.error = AuthError.unsupportedProvider
let driver = LoginTestDriver(useCase: spy)
driver.tapSignInButton(.apple)
await waitUntil {
driver.isLoading
}
#expect(driver.isLoading)
spy.resume()
await waitUntil {
!driver.isLoading && driver.hasAlert
}
#expect(!driver.isLoading)
}
@Test("이메일을 가져오지 못하면 이메일 없음 알림을 표시한다")
func 이메일을_가져오지_못하면_이메일_없음_알림을_표시한다() async {
let spy = SignInUseCaseSpy()
spy.error = AuthError.emailNotFound
let driver = LoginTestDriver(useCase: spy)
driver.tapSignInButton(.google)
await waitUntil {
driver.hasAlert
}
#expect(driver.alert == expectedAlert(
title: String(localized: "login_alert_email_unavailable_title"),
message: String(localized: "login_alert_email_unavailable_message")
))
}
@Test("일반 로그인 에러가 발생하면 공통 에러 알림을 표시한다")
func 일반_로그인_에러가_발생하면_공통_에러_알림을_표시한다() async {
let spy = SignInUseCaseSpy()
spy.error = AuthError.unsupportedProvider
let driver = LoginTestDriver(useCase: spy)
driver.tapSignInButton(.apple)
await waitUntil {
driver.hasAlert
}
#expect(driver.alert == expectedAlert(
title: String(localized: "common_error_title"),
message: String(localized: "common_error_message")
))
}
@Test("소셜 로그인 취소 에러가 발생하면 알림을 표시하지 않는다")
func 소셜_로그인_취소_에러가_발생하면_알림을_표시하지_않는다() async {
let spy = SignInUseCaseSpy()
spy.error = NSError(domain: "com.google.GIDSignIn", code: -5)
let driver = LoginTestDriver(useCase: spy)
driver.tapSignInButton(.google)
await waitUntil {
spy.calledProviders == [.google] && !driver.isLoading
}
#expect(!driver.showAlert)
#expect(driver.alert == nil)
}
@Test("알림을 닫으면 알림 상태와 문구가 초기화된다")
func 알림을_닫으면_알림_상태와_문구가_초기화된다() async {
let spy = SignInUseCaseSpy()
spy.error = AuthError.emailNotFound
let driver = LoginTestDriver(useCase: spy)
driver.tapSignInButton(.google)
await waitUntil {
driver.hasAlert
}
driver.dismissAlert()
#expect(!driver.showAlert)
#expect(driver.alert == nil)
}
}
@MainActor
private struct LoginTestDriver {
private let feature: StoreOf<LoginFeature>
var isLoading: Bool {
feature.state.isLoading
}
var showAlert: Bool {
hasAlert
}
var hasAlert: Bool {
alert != nil
}
var alert: AlertState<Never>? {
feature.state.alert
}
init(useCase: SignInUseCase) {
feature = ComposableArchitecture.Store(
initialState: LoginFeature.State()
) {
LoginFeature()
} withDependencies: {
$0.signInUseCase = .live(useCase)
}
}
func tapSignInButton(_ provider: AuthProvider) {
feature.send(.tapSignInButton(provider))
}
func dismissAlert() {
feature.send(.alert(.dismiss))
}
}
private func expectedAlert(
title: String,
message: String
) -> AlertState<Never> {
AlertState {
TextState(title)
} actions: {
ButtonState(role: .cancel) {
TextState(String(localized: "common_close"))
}
} message: {
TextState(message)
}
}