Skip to content

Commit d68aa97

Browse files
committed
refactor(Clock): add previews for each Styles
1 parent 9ffe788 commit d68aa97

File tree

6 files changed

+57
-15
lines changed

6 files changed

+57
-15
lines changed

telltime/App/App.swift

+9-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ enum App {
2525
}
2626
}
2727

28-
#if DEBUG
29-
static let previewStore = Store<App.State, App.Action>(initialState: App.State(), reducer: { _, _ in })
30-
#endif
28+
#if DEBUG
29+
static func previewStore(modifyState: (inout App.State) -> Void) -> Store<App.State, App.Action> {
30+
var state = App.State()
31+
modifyState(&state)
32+
return .init(initialState: state, reducer: { _, _ in })
33+
}
34+
35+
static let previewStore = App.previewStore { _ in }
36+
#endif
3137
}

telltime/Clock/ClockView.swift

+19-5
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,29 @@ struct ClockView_Previews: PreviewProvider {
6565
}
6666

6767
struct ClockViewWithFace_Previews: PreviewProvider {
68-
static var previewStoreWithShowFace: Store<App.State, App.Action> {
69-
var state = App.State()
70-
state.clock.isClockFaceShown = true
71-
return .init(initialState: state) { _, _ in }
68+
static var previews: some View {
69+
ClockView().padding()
70+
.environmentObject(App.previewStore {
71+
$0.clock.isClockFaceShown = true
72+
})
73+
}
74+
}
75+
76+
struct ClockViewArtNouveauStyle_Previews: PreviewProvider {
77+
static var previews: some View {
78+
ClockView().padding()
79+
.environmentObject(App.previewStore {
80+
$0.configuration.clockStyle = .artNouveau
81+
})
7282
}
83+
}
7384

85+
struct ClockViewDrawingStyle_Previews: PreviewProvider {
7486
static var previews: some View {
7587
ClockView().padding()
76-
.environmentObject(Self.previewStoreWithShowFace)
88+
.environmentObject(App.previewStore {
89+
$0.configuration.clockStyle = .drawing
90+
})
7791
}
7892
}
7993
#endif

telltime/Clock/Face/ClockFaceView.swift

+3-7
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@ struct ClockFaceView: View {
3535

3636
#if DEBUG
3737
struct ClockFaceSmiling_Previews: PreviewProvider {
38-
static var previewStoreWithShowFace: Store<App.State, App.Action> {
39-
var state = App.State()
40-
state.clock.isClockFaceShown = true
41-
return .init(initialState: state) { _, _ in }
42-
}
43-
4438
static var previews: some View {
4539
ClockFaceView()
46-
.environmentObject(Self.previewStoreWithShowFace)
40+
.environmentObject(App.previewStore {
41+
$0.clock.isClockFaceShown = true
42+
})
4743
}
4844
}
4945
#endif

telltimeTests/Clock/ClockTests.swift

+26
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,30 @@ class ClockTests: XCTestCase {
128128
let hostingController = UIHostingController(rootView: clockViews)
129129
assertSnapshot(matching: hostingController, as: .image(on: .iPhoneSe))
130130
}
131+
132+
func testClockViewArtNouveauStyle() {
133+
Current.isAnimationDisabled = true
134+
let clockViews = ClockViewArtNouveauStyle_Previews.previews
135+
let hostingController = UIHostingController(rootView: clockViews)
136+
assertSnapshot(matching: hostingController, as: .image(on: .iPhoneSe))
137+
}
138+
139+
func testClockViewDrawingStyle() {
140+
Current.isAnimationDisabled = true
141+
Current.clock.randomControlRatio = (
142+
leftX: { 0.5 },
143+
leftY: { 0.6 },
144+
rightX: { 0.7 },
145+
rightY: { 0.8 }
146+
)
147+
Current.clock.randomAngle = { .degrees(5) }
148+
Current.clock.randomScale = { 1 }
149+
Current.clock.randomBorderMarginRatio = (
150+
maxMargin: { $0 },
151+
angleMargin: { 1/3 }
152+
)
153+
let clockViews = ClockViewDrawingStyle_Previews.previews
154+
let hostingController = UIHostingController(rootView: clockViews)
155+
assertSnapshot(matching: hostingController, as: .image(on: .iPhoneSe))
156+
}
131157
}
Loading
Loading

0 commit comments

Comments
 (0)