-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReaderTests.swift
120 lines (94 loc) · 3.81 KB
/
ReaderTests.swift
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
//
// ReaderTests.swift
//
//
// Created by Peter Larson on 8/3/23.
//
import XCTest
import ComposableArchitecture
import BibleCore
import DirectoryCore
@testable import ReaderCore
final class ReaderTests: XCTestCase {
@MainActor func testOpenBible() async {
let store = TestStore(initialState: Reader.State(isDirectoryOpen: false)) {
Reader()
} withDependencies: {
$0.defaults = .liveValue
}
await store.send(.openDirectory) {
$0.isDirectoryOpen = true
}
await store.send(.menuDirectory(.task))
await store.receive(.menuDirectory(.load(.success(.mock)))) {
$0.menuDirectory.sections = IdentifiedArray(uniqueElements: [Book].mock.map(Section.State.init(book:)))
}
}
@MainActor func testNextChapter() async {
let clock = TestClock()
let store = TestStore(
initialState: Reader.State(isDirectoryOpen: false)
) {
Reader()
._printChanges()
} withDependencies: {
$0.continuousClock = clock
$0.defaults = .liveValue
}
// Open menuDirectory
await store.send(.openDirectory) {
$0.isDirectoryOpen = true
}
// Load menuDirectory
await store.send(.menuDirectory(.task))
// Receive books
await store.receive(.menuDirectory(.load(.success(.mock)))) {
$0.menuDirectory.sections = IdentifiedArray(uniqueElements: [Book].mock.map(Section.State.init(book:)))
}
// Expand book
await store.send(.menuDirectory(.book(id: Book.genesis.id, action: .toggle))) {
$0.menuDirectory.sections[id: Book.genesis.id]?.isExpanded = true
$0.menuDirectory.focused = Book.genesis.id
}
// Load chapters from book
await store.receive(.menuDirectory(.book(id: Book.genesis.id, action: .load(.success(.mock))))) {
$0.menuDirectory.sections[id: Book.genesis.id]?.chapters = .mock
}
// Select chapter
await store.send(.menuDirectory(.book(id: Book.genesis.id, action: .openChapter(.mock)))) {
$0.menuDirectory.sections[id: Book.genesis.id]?.chapter = .mock
}
// Load verses from menuDirectory
await store.receive(.menuDirectory(.book(id: Book.genesis.id, action: .loadChapter(.success(.mock))))) {
$0.menuDirectory.sections[id: Book.genesis.id]?.verses = .mock
}
// Select
await store.send(.menuDirectory(.book(id: Book.genesis.id, action: .select(.genesis, .mock, .mock, nil)))) {
$0.isDirectoryOpen = false
}
// Open page
await store.receive(.page(.open(.genesis, .mock, [.mock], focused: nil, save: true))) {
$0.page = .init(book: .genesis, chapter: .mock, verses: nil, verse: nil)
}
await clock.advance(by: .seconds(10))
await store.receive(.page(.add(.mock))) {
$0.page.verses = [.mock]
}
await store.send(.page(.paginateChapter(forward: true)))
await clock.advance(by: .seconds(10))
await store.receive(.page(.clear)) {
$0.page.verses = nil
}
await store.receive(.page(.paginateBook(forward: true)))
await store.receive(.page(.open(.exodus, .mock, .mock, focused: nil, save: true))) {
$0.page.book = .exodus
$0.page.chapter = .mock
$0.page.verses = nil
$0.page.verse = nil
}
await clock.advance(by: .seconds(10))
await store.receive(.page(.add(.mock))) {
$0.page.verses = [.mock]
}
}
}