Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct SearchFeature {
}

enum Action: BindableAction, Equatable {
case onAppear
case alert(PresentationAction<Never>)
case binding(BindingAction<State>)
case addRecentQuery(String)
Expand Down Expand Up @@ -102,6 +103,14 @@ struct SearchFeature {
BindingReducer()
Reduce { state, action in
switch action {
case .onAppear:
return .run { send in
// `.searchable` 바인딩이 화면에 붙은 뒤 포커스를 요청하도록 main queue 다음 턴으로 넘긴다.
await withCheckedContinuation { continuation in
DispatchQueue.main.async { continuation.resume() }
}
await send(.binding(.set(\.isSearching, true)))
}
case .alert:
break
case .binding(\.isSearching):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct SearchView: View {
}
}
}
.onAppear { store.send(.binding(.set(\.isSearching, true))) }
.onAppear { store.send(.onAppear) }
.onChange(of: store.isSearching) { _, isSearching in
if !isSearching {
dismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ struct SearchStoreTestAdapter {
}
}

func onAppear() async {
await store.send(.onAppear)
await store.receive(.binding(.set(\.isSearching, true))) {
$0.isSearching = true
}
}

func setShowAllTodos(_ value: Bool) async {
await store.send(.setShowAllTodos(value)) {
$0.showAllTodos = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ struct SearchFeatureTests {
#expect(adapter.recentQueries == ["swift", "tca"])
}

@Test("onAppear는 검색 상태를 활성화한다")
func onAppear는_검색_상태를_활성화한다() async {
let adapter = SearchStoreTestAdapter()

await adapter.onAppear()

#expect(adapter.isSearching)
}

@Test("addRecentQuery는 공백을 제거하고 중복 제거 후 앞에 추가한다")
func addRecentQuery는_공백을_제거하고_중복_제거_후_앞에_추가한다() async {
let updateSpy = SearchUpdateRecentQueriesUseCaseSpy()
Expand Down
Loading