@@ -20,16 +20,29 @@ extension XCTestCase {
2020 @MainActor
2121 func fakeCollectionViewModel(
2222 id: String = . random,
23+ sectionId: ( Int ) -> String = { _ in . random } ,
24+ cellId: ( Int , Int ) -> String = { _, _ in . random } ,
25+ supplementaryViewId: ( Int , Int ) -> String = { _, _ in . random } ,
2326 numSections: Int = Int . random ( in: 2 ... 15 ) ,
2427 numCells: Int ? = nil ,
2528 useCellNibs: Bool = false ,
29+ includeHeader: Bool = false ,
30+ includeFooter: Bool = false ,
31+ includeSupplementaryViews: Bool = false ,
2632 expectDidSelectCell: Bool = false ,
2733 expectConfigureCell: Bool = false
2834 ) -> CollectionViewModel {
29- let sections = ( 0 ..< numSections) . map { _ in
35+ let sections = ( 0 ..< numSections) . map { sectionIndex in
3036 self . fakeSectionViewModel (
37+ id: sectionId ( sectionIndex) ,
38+ cellId: cellId,
39+ supplementaryViewId: supplementaryViewId,
40+ sectionIndex: sectionIndex,
3141 numCells: numCells ?? Int . random ( in: 3 ... 20 ) ,
3242 useCellNibs: useCellNibs,
43+ includeHeader: includeHeader,
44+ includeFooter: includeFooter,
45+ includeSupplementaryViews: includeSupplementaryViews,
3346 expectDidSelectCell: expectDidSelectCell,
3447 expectConfigureCell: expectConfigureCell
3548 )
@@ -40,40 +53,53 @@ extension XCTestCase {
4053 @MainActor
4154 func fakeSectionViewModel(
4255 id: String = . random,
56+ cellId: ( Int , Int ) -> String = { _, _ in . random } ,
57+ supplementaryViewId: ( Int , Int ) -> String = { _, _ in . random } ,
58+ sectionIndex: Int = 0 ,
4359 numCells: Int = Int . random ( in: 1 ... 20 ) ,
4460 useCellNibs: Bool = false ,
4561 includeHeader: Bool = false ,
4662 includeFooter: Bool = false ,
63+ includeSupplementaryViews: Bool = false ,
4764 expectDidSelectCell: Bool = false ,
4865 expectConfigureCell: Bool = false
4966 ) -> SectionViewModel {
5067 let cells = self . fakeCellViewModels (
68+ id: cellId,
69+ sectionIndex: sectionIndex,
5170 count: numCells,
5271 useNibs: useCellNibs,
5372 expectDidSelectCell: expectDidSelectCell,
5473 expectConfigureCell: expectConfigureCell
5574 )
5675 let header = includeHeader ? FakeHeaderViewModel ( ) : nil
5776 let footer = includeFooter ? FakeFooterViewModel ( ) : nil
77+ let supplementaryViews = includeSupplementaryViews
78+ ? ( 0 ..< numCells) . map { cellIndex in FakeSupplementaryViewModel ( title: supplementaryViewId ( sectionIndex, cellIndex) ) }
79+ : [ ]
5880 return SectionViewModel (
5981 id: " section_ \( id) " ,
6082 cells: cells,
6183 header: header,
62- footer: footer
84+ footer: footer,
85+ supplementaryViews: supplementaryViews
6386 )
6487 }
6588
6689 @MainActor
6790 func fakeCellViewModels(
91+ id: ( Int , Int ) -> String = { _, _ in . random } ,
92+ sectionIndex: Int = 0 ,
6893 count: Int = Int . random ( in: 3 ... 20 ) ,
6994 useNibs: Bool = false ,
7095 expectDidSelectCell: Bool = false ,
7196 expectConfigureCell: Bool = false
7297 ) -> [ AnyCellViewModel ] {
7398 var cells = [ AnyCellViewModel] ( )
74- for index in 0 ..< count {
99+ for cellIndex in 0 ..< count {
75100 let model = self . _fakeCellViewModel (
76- index: index,
101+ id: id ( sectionIndex, cellIndex) ,
102+ cellIndex: cellIndex,
77103 useNibs: useNibs,
78104 expectDidSelectCell: expectDidSelectCell,
79105 expectConfigureCell: expectConfigureCell
@@ -85,26 +111,27 @@ extension XCTestCase {
85111
86112 @MainActor
87113 private func _fakeCellViewModel(
88- index: Int ,
114+ id: String ,
115+ cellIndex: Int ,
89116 useNibs: Bool ,
90117 expectDidSelectCell: Bool ,
91118 expectConfigureCell: Bool
92119 ) -> AnyCellViewModel {
93120 if useNibs {
94- var viewModel = FakeCellNibViewModel ( )
121+ var viewModel = FakeCellNibViewModel ( id : id )
95122 viewModel. expectationDidSelect = self . _cellDidSelectExpectation ( expect: expectDidSelectCell, id: viewModel. id)
96123 viewModel. expectationConfigureCell = self . _cellConfigureExpectation ( expect: expectConfigureCell, id: viewModel. id)
97124 return viewModel. eraseToAnyViewModel ( )
98125 }
99126
100- if index . isMultiple ( of: 2 ) {
101- var viewModel = FakeNumberCellViewModel ( )
127+ if cellIndex . isMultiple ( of: 2 ) {
128+ var viewModel = FakeNumberCellViewModel ( model : . init ( id : id ) )
102129 viewModel. expectationDidSelect = self . _cellDidSelectExpectation ( expect: expectDidSelectCell, id: viewModel. id)
103130 viewModel. expectationConfigureCell = self . _cellConfigureExpectation ( expect: expectConfigureCell, id: viewModel. id)
104131 return viewModel. eraseToAnyViewModel ( )
105132 }
106133
107- var viewModel = FakeTextCellViewModel ( )
134+ var viewModel = FakeTextCellViewModel ( model : . init ( text : id ) )
108135 viewModel. expectationDidSelect = self . _cellDidSelectExpectation ( expect: expectDidSelectCell, id: viewModel. id)
109136 viewModel. expectationConfigureCell = self . _cellConfigureExpectation ( expect: expectConfigureCell, id: viewModel. id)
110137 return viewModel. eraseToAnyViewModel ( )
0 commit comments