-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainTabFeatureDeeplinkTests.swift
More file actions
153 lines (127 loc) ยท 5.64 KB
/
MainTabFeatureDeeplinkTests.swift
File metadata and controls
153 lines (127 loc) ยท 5.64 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
import Foundation
import ComposableArchitecture
import CoreKit
import Domain
import FeatureContentDetail
import Testing
@testable import App
@MainActor
struct MainTabFeatureDeeplinkTests {
@Test("๋ฅ๋งํฌ 1/3: MainTab ์์ฑ ์ด์ ํ ์๋น + ๊ตฌ๋
์ค ์ค์๊ฐ ๋ฐฉ์ถ(alert)")
func alertRouteQueuedAndLiveEmittedByRouter() async throws {
let router = DeeplinkRouteClient.liveValue
await router.routeTo(URL(string: "pokit://alert"))
let store = TestStore(initialState: MainTabFeature.State()) {
MainTabFeature()
} withDependencies: {
$0[PasteboardClient.self] = .noop
$0[DeeplinkRouteClient.self] = router
}
store.exhaustivity = .off
await store.send(.view(.onAppear))
await store.receive(\.inner.๋ฅ๋งํฌ_์์ )
await store.receive(\.delegate.์๋ฆผํจ์ด๋)
await router.routeTo(URL(string: "pokit://alert"))
await store.receive(\.inner.๋ฅ๋งํฌ_์์ )
await store.receive(\.delegate.์๋ฆผํจ์ด๋)
await store.skipInFlightEffects()
}
@Test("๋ฅ๋งํฌ 2/3: pokit shared(categoryId+contentId) -> ์นดํ
๊ณ ๋ฆฌ ์ง์
ํ contentDetail ์คํ + ํญ ์ ์ง")
func sharedRouteWithContentOpensContentDetail() async throws {
let router = DeeplinkRouteClient.liveValue
var initialState = MainTabFeature.State()
initialState.selectedTab = .recommend
let store = TestStore(initialState: initialState) {
MainTabFeature()
} withDependencies: {
$0[PasteboardClient.self] = .noop
$0[CategoryClient.self] = .previewValue
$0[ContentClient.self] = .previewValue
$0[DeeplinkRouteClient.self] = router
}
store.exhaustivity = .off
await store.send(.view(.onAppear))
await router.routeTo(URL(string: "pokit://shared?categoryId=2&contentId=777"))
await store.receive(\.inner.๋ฅ๋งํฌ_์์ )
await store.receive(\.async.ํฌํท_๋ฅ๋งํฌ_์ฒ๋ฆฌ)
await store.receive(\.inner.ํฌํท_๋ฅ๋งํฌ_์ด๋) {
if case let .์นดํ
๊ณ ๋ฆฌ์์ธ(state) = $0.path.last, state.category.id == 2 {
// same category: no push
} else {
$0.path.append(.์นดํ
๊ณ ๋ฆฌ์์ธ(.init(type: .์ฐธ์ฌ, category: makeCategory(id: 2, name: "์นดํ
๊ณ ๋ฆฌ1"))))
}
$0.contentDetail = .init(contentId: 777)
}
await store.skipInFlightEffects()
}
@Test("๋ฅ๋งํฌ 3/3: pokit shared(categoryId+userId) -> ์นดํ
๊ณ ๋ฆฌ ์ง์
ํ ์ฐธ์ฌ์ธ์ ์ํธ ์คํ + ํญ ์ ์ง")
func sharedRouteWithUserOpensParticipantsSheet() async throws {
let router = DeeplinkRouteClient.liveValue
var initialState = MainTabFeature.State()
initialState.selectedTab = .recommend
let store = TestStore(initialState: initialState) {
MainTabFeature()
} withDependencies: {
$0[PasteboardClient.self] = .noop
$0[CategoryClient.self] = .previewValue
$0[ContentClient.self] = .previewValue
$0[DeeplinkRouteClient.self] = router
}
store.exhaustivity = .off
await store.send(.view(.onAppear))
await router.routeTo(URL(string: "pokit://shared?categoryId=2&userId=999"))
await store.receive(\.inner.๋ฅ๋งํฌ_์์ )
await store.receive(\.async.ํฌํท_๋ฅ๋งํฌ_์ฒ๋ฆฌ)
await store.receive(\.inner.ํฌํท_๋ฅ๋งํฌ_์ด๋) {
if case let .์นดํ
๊ณ ๋ฆฌ์์ธ(state) = $0.path.last, state.category.id == 2 {
// same category: no push
} else {
$0.path.append(.์นดํ
๊ณ ๋ฆฌ์์ธ(.init(type: .์ฐธ์ฌ, category: makeCategory(id: 2, name: "์นดํ
๊ณ ๋ฆฌ1"))))
}
}
guard let categoryPathID = store.state.path.ids.last else {
throw TestAssertionError("์นดํ
๊ณ ๋ฆฌ Path ID๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.")
}
await store.receive(\.path[id: categoryPathID].์นดํ
๊ณ ๋ฆฌ์์ธ.view.์ฐธ์ฌ์ธ์_๋ฒํผ_๋๋ ์๋)
await store.receive(\.path[id: categoryPathID].์นดํ
๊ณ ๋ฆฌ์์ธ.inner.์ฐธ์ฌ์ธ์_์ํธ_ํ์ฑํ)
await store.skipInFlightEffects()
}
@Test("๋ฏธ๋ถ๋ฅ ์นดํ
๊ณ ๋ฆฌ ์ด๋์ ํญ ์ ์ง + ๋ฏธ๋ถ๋ฅ ํ์ฑํ delegate ์ ๋ฌ")
func unclassifiedCategoryMoveKeepsTabAndActivatesUnclassified() async throws {
var initialState = MainTabFeature.State()
initialState.selectedTab = .recommend
initialState.path.append(.์นดํ
๊ณ ๋ฆฌ์์ธ(.init(category: makeCategory(id: 99, name: "๊ธฐ์กด"))))
let store = TestStore(initialState: initialState) {
MainTabFeature()
} withDependencies: {
$0[PasteboardClient.self] = .noop
$0[CategoryClient.self] = .previewValue
$0[ContentClient.self] = .previewValue
}
store.exhaustivity = .off
await store.send(.inner(.์นดํ
๊ณ ๋ฆฌ์์ธ_์ด๋(category: makeCategory(id: 0, name: "๋ฏธ๋ถ๋ฅ")))) {
$0.path.removeAll()
}
await store.receive(\.pokit.delegate.๋ฏธ๋ถ๋ฅ_์นดํ
๊ณ ๋ฆฌ_ํ์ฑํ)
}
}
private func makeCategory(id: Int, name: String) -> BaseCategoryItem {
.init(
id: id,
userId: 0,
categoryName: name,
categoryImage: .init(imageId: id, imageURL: ""),
contentCount: 0,
createdAt: "",
openType: .๊ณต๊ฐ,
keywordType: .default,
userCount: 0,
isFavorite: false
)
}
private struct TestAssertionError: Error, CustomStringConvertible {
let description: String
init(_ description: String) {
self.description = description
}
}