@@ -8,36 +8,54 @@ final class ComposedSectionProvider_Spec: QuickSpec {
8
8
9
9
override func spec( ) {
10
10
describe ( " ComposedSectionProvider " ) {
11
- let global = ComposedSectionProvider ( )
12
-
13
- let child1 = ComposedSectionProvider ( )
14
- let child1a = ArraySection < String > ( )
15
- let child1b = ArraySection < String > ( )
16
- let child2 = ComposedSectionProvider ( )
17
- let child2a = ComposedSectionProvider ( )
18
- let child2b = ArraySection < String > ( )
19
- let child2c = ArraySection < String > ( )
20
- let child2z = ComposedSectionProvider ( )
21
- let child2d = ArraySection < String > ( )
22
- let child2e = ComposedSectionProvider ( )
23
- let child2f = ArraySection < String > ( )
24
-
25
- child1. append ( child1a)
26
- child1. insert ( child1b, after: child1a)
27
-
28
- child2. append ( child2a)
29
- child2a. append ( child2c)
30
- child2a. insert ( child2b, before: child2c)
31
-
32
- child2. insert ( child2z, after: child2a)
33
- child2. append ( child2d)
34
- child2e. append ( child2f)
35
- child2. append ( child2e)
36
- global. append ( child1)
37
- global. append ( child2)
38
-
39
- it ( " should contain 2 global sections " ) {
40
- expect ( global. numberOfSections) == 6
11
+ var global : ComposedSectionProvider !
12
+ var child1 : ComposedSectionProvider !
13
+ var child1a : ArraySection < String > !
14
+ var child1b : ArraySection < String > !
15
+ var child2 : ComposedSectionProvider !
16
+ var child2a : ComposedSectionProvider !
17
+ var child2b : ArraySection < String > !
18
+ var child2c : ArraySection < String > !
19
+ var child2d : ArraySection < String > !
20
+ var child2e : ComposedSectionProvider !
21
+ var child2f : ArraySection < String > !
22
+ var child2g : ComposedSectionProvider !
23
+ var child2h : ArraySection < String > !
24
+
25
+ beforeEach {
26
+ global = ComposedSectionProvider ( )
27
+
28
+ child1 = ComposedSectionProvider ( )
29
+ child1a = ArraySection < String > ( )
30
+ child1b = ArraySection < String > ( )
31
+ child2 = ComposedSectionProvider ( )
32
+ child2a = ComposedSectionProvider ( )
33
+ child2b = ArraySection < String > ( )
34
+ child2c = ArraySection < String > ( )
35
+ child2d = ArraySection < String > ( )
36
+ child2e = ComposedSectionProvider ( )
37
+ child2f = ArraySection < String > ( )
38
+ child2g = ComposedSectionProvider ( )
39
+ child2h = ArraySection < String > ( )
40
+
41
+ child1. append ( child1a)
42
+ child1. insert ( child1b, after: child1a)
43
+
44
+ child2. append ( child2a)
45
+ child2a. append ( child2c)
46
+ child2a. insert ( child2b, before: child2c)
47
+ child2a. insert ( child2d, after: child2c)
48
+
49
+ child2. insert ( child2e, after: child2a)
50
+ child2. append ( child2f)
51
+ child2g. append ( child2h)
52
+ child2. append ( child2g)
53
+ global. append ( child1)
54
+ global. append ( child2)
55
+ }
56
+
57
+ it ( " should contain 7 global sections " ) {
58
+ expect ( global. numberOfSections) == 7
41
59
}
42
60
43
61
it ( " cache should contain 2 providers " ) {
@@ -46,25 +64,37 @@ final class ComposedSectionProvider_Spec: QuickSpec {
46
64
47
65
it ( " should return the right offsets " ) {
48
66
expect ( global. sectionOffset ( for: child1) ) == 0
67
+ expect ( global. sectionOffset ( for: child1a) ) == 0
68
+ expect ( global. sectionOffset ( for: child1b) ) == 1
49
69
expect ( global. sectionOffset ( for: child2) ) == 2
50
70
expect ( global. sectionOffset ( for: child2a) ) == 2
51
- expect ( global. sectionOffset ( for: child2z) ) == 4
71
+ expect ( global. sectionOffset ( for: child2b) ) == 2
72
+ expect ( global. sectionOffset ( for: child2c) ) == 3
73
+ expect ( global. sectionOffset ( for: child2d) ) == 4
52
74
expect ( global. sectionOffset ( for: child2e) ) == 5
75
+ expect ( global. sectionOffset ( for: child2f) ) == 5
76
+ expect ( global. sectionOffset ( for: child2g) ) == 6
77
+ expect ( global. sectionOffset ( for: child2h) ) == 6
53
78
54
79
expect ( child2. sectionOffset ( for: child2a) ) == 0
55
- expect ( child2. sectionOffset ( for: child2z) ) == 2
56
80
expect ( child2. sectionOffset ( for: child2e) ) == 3
81
+ expect ( child2. sectionOffset ( for: child2g) ) == 4
82
+
83
+ expect ( child2a. sectionOffset ( for: child2b) ) == 0
84
+ expect ( child2a. sectionOffset ( for: child2c) ) == 1
85
+ expect ( child2a. sectionOffset ( for: child2d) ) == 2
57
86
}
58
87
59
88
context ( " when a section is inserted after a section provider with multiple sections " ) {
60
89
var mockDelegate : MockSectionProviderUpdateDelegate !
61
90
var countBefore : Int !
91
+ var newSection : ArraySection < String > !
62
92
63
93
beforeEach {
64
94
mockDelegate = MockSectionProviderUpdateDelegate ( )
65
95
global. updateDelegate = mockDelegate
66
96
67
- let newSection = ArraySection < String > ( )
97
+ newSection = ArraySection < String > ( )
68
98
countBefore = global. numberOfSections
69
99
70
100
global. append ( newSection)
@@ -73,19 +103,38 @@ final class ComposedSectionProvider_Spec: QuickSpec {
73
103
it ( " should pass the correct indexes to the delegate " ) {
74
104
expect ( mockDelegate. didInsertSectionsCalls. last!. 2 ) == IndexSet ( integer: countBefore)
75
105
}
106
+
107
+ it ( " should update the sections count " ) {
108
+ expect ( global. numberOfSections) == 8
109
+ }
110
+
111
+ it ( " should contain the correct sections " ) {
112
+ expect ( global. sections [ 0 ] ) === child1a
113
+ expect ( global. sections [ 1 ] ) === child1b
114
+ expect ( global. sections [ 2 ] ) === child2b
115
+ expect ( global. sections [ 3 ] ) === child2c
116
+ expect ( global. sections [ 4 ] ) === child2d
117
+ expect ( global. sections [ 5 ] ) === child2f
118
+ expect ( global. sections [ 6 ] ) === child2h
119
+ expect ( global. sections [ 7 ] ) === newSection
120
+ }
76
121
}
77
122
78
123
context ( " when a section provider is inserted after a section provider with multiple sections " ) {
79
124
var mockDelegate : MockSectionProviderUpdateDelegate !
80
125
var countBefore : Int !
81
126
var sectionProvider : ComposedSectionProvider !
127
+ var newSection1 : ArraySection < String > !
128
+ var newSection2 : ArraySection < String > !
82
129
83
130
beforeEach {
84
131
mockDelegate = MockSectionProviderUpdateDelegate ( )
85
132
global. updateDelegate = mockDelegate
86
133
sectionProvider = ComposedSectionProvider ( )
87
- sectionProvider. append ( ArraySection < String > ( ) )
88
- sectionProvider. append ( ArraySection < String > ( ) )
134
+ newSection1 = ArraySection < String > ( )
135
+ newSection2 = ArraySection < String > ( )
136
+ sectionProvider. append ( newSection1)
137
+ sectionProvider. append ( newSection2)
89
138
90
139
countBefore = global. numberOfSections
91
140
@@ -95,6 +144,22 @@ final class ComposedSectionProvider_Spec: QuickSpec {
95
144
it ( " should pass the correct indexes to the delegate " ) {
96
145
expect ( mockDelegate. didInsertSectionsCalls. last!. 2 ) == IndexSet ( integersIn: countBefore..< ( countBefore + sectionProvider. numberOfSections) )
97
146
}
147
+
148
+ it ( " should update the sections count " ) {
149
+ expect ( global. numberOfSections) == 9
150
+ }
151
+
152
+ it ( " should contain the correct sections " ) {
153
+ expect ( global. sections [ 0 ] ) === child1a
154
+ expect ( global. sections [ 1 ] ) === child1b
155
+ expect ( global. sections [ 2 ] ) === child2b
156
+ expect ( global. sections [ 3 ] ) === child2c
157
+ expect ( global. sections [ 4 ] ) === child2d
158
+ expect ( global. sections [ 5 ] ) === child2f
159
+ expect ( global. sections [ 6 ] ) === child2h
160
+ expect ( global. sections [ 7 ] ) === newSection1
161
+ expect ( global. sections [ 8 ] ) === newSection2
162
+ }
98
163
}
99
164
100
165
context ( " when a section located after a section provider with multiple sections is removed " ) {
@@ -116,6 +181,49 @@ final class ComposedSectionProvider_Spec: QuickSpec {
116
181
it ( " should pass the correct indexes to the delegate " ) {
117
182
expect ( mockDelegate. didRemoveSectionsCalls. last!. 2 ) == IndexSet ( integer: countBefore - 1 )
118
183
}
184
+
185
+ it ( " should contain the correct sections " ) {
186
+ expect ( global. sections [ 0 ] ) === child1a
187
+ expect ( global. sections [ 1 ] ) === child1b
188
+ expect ( global. sections [ 2 ] ) === child2b
189
+ expect ( global. sections [ 3 ] ) === child2c
190
+ expect ( global. sections [ 4 ] ) === child2d
191
+ expect ( global. sections [ 5 ] ) === child2f
192
+ expect ( global. sections [ 6 ] ) === child2h
193
+ }
194
+ }
195
+
196
+ context ( " when multiple sections are removed " ) {
197
+ var mockDelegate : MockSectionProviderUpdateDelegate !
198
+ var countBefore : Int !
199
+
200
+ beforeEach {
201
+ mockDelegate = MockSectionProviderUpdateDelegate ( )
202
+ global. updateDelegate = mockDelegate
203
+
204
+ countBefore = global. numberOfSections
205
+
206
+ child2. remove ( child2a)
207
+ }
208
+
209
+ it ( " should pass through the removed indexes to the delegate " ) {
210
+ expect ( mockDelegate. didRemoveSectionsCalls. last!. 2 ) == IndexSet ( [ 0 , 1 , 2 ] )
211
+ }
212
+
213
+ it ( " should update the number of sections " ) {
214
+ expect ( global. numberOfSections) == countBefore - 3
215
+ }
216
+
217
+ it ( " should pass itself to the delegate " ) {
218
+ expect ( mockDelegate. didRemoveSectionsCalls. last!. 0 ) === child2
219
+ }
220
+
221
+ it ( " should contain the correct sections " ) {
222
+ expect ( global. sections [ 0 ] ) === child1a
223
+ expect ( global. sections [ 1 ] ) === child1b
224
+ expect ( global. sections [ 2 ] ) === child2f
225
+ expect ( global. sections [ 3 ] ) === child2h
226
+ }
119
227
}
120
228
}
121
229
}
0 commit comments