|
| 1 | +// |
| 2 | +// RxCollectionViewSectionedDataSource+Test.swift |
| 3 | +// Tests |
| 4 | +// |
| 5 | +// Created by Krunoslav Zaher on 11/4/17. |
| 6 | +// Copyright © 2017 kzaher. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import Foundation |
| 10 | +import RxDataSources |
| 11 | +import XCTest |
| 12 | +import UIKit |
| 13 | + |
| 14 | +class RxCollectionViewSectionedDataSourceTest: XCTestCase { |
| 15 | +} |
| 16 | + |
| 17 | +// configureSupplementaryView not passed through init |
| 18 | +extension RxCollectionViewSectionedDataSourceTest { |
| 19 | + func testCollectionViewSectionedReloadDataSource_optionalConfigureSupplementaryView() { |
| 20 | + let dataSource = RxCollectionViewSectionedReloadDataSource<AnimatableSectionModel<String, String>>(configureCell: { _, _, _, _ in UICollectionViewCell() }) |
| 21 | + let layout = UICollectionViewFlowLayout() |
| 22 | + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) |
| 23 | + |
| 24 | + XCTAssertFalse(dataSource.responds(to: #selector(UICollectionViewDataSource.collectionView(_:viewForSupplementaryElementOfKind:at:)))) |
| 25 | + |
| 26 | + let sentinel = UICollectionReusableView() |
| 27 | + dataSource.configureSupplementaryView = { _, _, _, _ in return sentinel } |
| 28 | + |
| 29 | + let returnValue = dataSource.collectionView( |
| 30 | + collectionView, |
| 31 | + viewForSupplementaryElementOfKind: UICollectionElementKindSectionHeader, |
| 32 | + at: IndexPath(item: 0, section: 0) |
| 33 | + ) |
| 34 | + XCTAssertEqual(returnValue, sentinel) |
| 35 | + XCTAssertTrue(dataSource.responds(to: #selector(UICollectionViewDataSource.collectionView(_:viewForSupplementaryElementOfKind:at:)))) |
| 36 | + } |
| 37 | + |
| 38 | + func testCollectionViewSectionedDataSource_optionalConfigureSupplementaryView() { |
| 39 | + let dataSource = CollectionViewSectionedDataSource<AnimatableSectionModel<String, String>>(configureCell: { _, _, _, _ in UICollectionViewCell() }) |
| 40 | + let layout = UICollectionViewFlowLayout() |
| 41 | + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) |
| 42 | + |
| 43 | + XCTAssertFalse(dataSource.responds(to: #selector(UICollectionViewDataSource.collectionView(_:viewForSupplementaryElementOfKind:at:)))) |
| 44 | + |
| 45 | + let sentinel = UICollectionReusableView() |
| 46 | + dataSource.configureSupplementaryView = { _, _, _, _ in return sentinel } |
| 47 | + |
| 48 | + let returnValue = dataSource.collectionView( |
| 49 | + collectionView, |
| 50 | + viewForSupplementaryElementOfKind: UICollectionElementKindSectionHeader, |
| 51 | + at: IndexPath(item: 0, section: 0) |
| 52 | + ) |
| 53 | + XCTAssertEqual(returnValue, sentinel) |
| 54 | + XCTAssertTrue(dataSource.responds(to: #selector(UICollectionViewDataSource.collectionView(_:viewForSupplementaryElementOfKind:at:)))) |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +// configureSupplementaryView passed through init |
| 59 | +extension RxCollectionViewSectionedDataSourceTest { |
| 60 | + func testCollectionViewSectionedAnimatedDataSource_optionalConfigureSupplementaryView_initializer() { |
| 61 | + let sentinel = UICollectionReusableView() |
| 62 | + let dataSource = RxCollectionViewSectionedAnimatedDataSource<AnimatableSectionModel<String, String>>( |
| 63 | + configureCell: { _, _, _, _ in UICollectionViewCell() }, |
| 64 | + configureSupplementaryView: { _, _, _, _ in return sentinel } |
| 65 | + ) |
| 66 | + let layout = UICollectionViewFlowLayout() |
| 67 | + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) |
| 68 | + |
| 69 | + let returnValue = dataSource.collectionView( |
| 70 | + collectionView, |
| 71 | + viewForSupplementaryElementOfKind: UICollectionElementKindSectionHeader, |
| 72 | + at: IndexPath(item: 0, section: 0) |
| 73 | + ) |
| 74 | + XCTAssertEqual(returnValue, sentinel) |
| 75 | + XCTAssertTrue(dataSource.responds(to: #selector(UICollectionViewDataSource.collectionView(_:viewForSupplementaryElementOfKind:at:)))) |
| 76 | + } |
| 77 | + |
| 78 | + func testCollectionViewSectionedReloadDataSource_optionalConfigureSupplementaryView_initializer() { |
| 79 | + let sentinel = UICollectionReusableView() |
| 80 | + let dataSource = RxCollectionViewSectionedReloadDataSource<AnimatableSectionModel<String, String>>( |
| 81 | + configureCell: { _, _, _, _ in UICollectionViewCell() }, |
| 82 | + configureSupplementaryView: { _, _, _, _ in return sentinel } |
| 83 | + ) |
| 84 | + let layout = UICollectionViewFlowLayout() |
| 85 | + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) |
| 86 | + |
| 87 | + let returnValue = dataSource.collectionView( |
| 88 | + collectionView, |
| 89 | + viewForSupplementaryElementOfKind: UICollectionElementKindSectionHeader, |
| 90 | + at: IndexPath(item: 0, section: 0) |
| 91 | + ) |
| 92 | + XCTAssertEqual(returnValue, sentinel) |
| 93 | + XCTAssertTrue(dataSource.responds(to: #selector(UICollectionViewDataSource.collectionView(_:viewForSupplementaryElementOfKind:at:)))) |
| 94 | + } |
| 95 | + |
| 96 | + func testCollectionViewSectionedDataSource_optionalConfigureSupplementaryView_initializer() { |
| 97 | + let sentinel = UICollectionReusableView() |
| 98 | + let dataSource = CollectionViewSectionedDataSource<AnimatableSectionModel<String, String>>( |
| 99 | + configureCell: { _, _, _, _ in UICollectionViewCell() }, |
| 100 | + configureSupplementaryView: { _, _, _, _ in return sentinel } |
| 101 | + ) |
| 102 | + let layout = UICollectionViewFlowLayout() |
| 103 | + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) |
| 104 | + |
| 105 | + let returnValue = dataSource.collectionView( |
| 106 | + collectionView, |
| 107 | + viewForSupplementaryElementOfKind: UICollectionElementKindSectionHeader, |
| 108 | + at: IndexPath(item: 0, section: 0) |
| 109 | + ) |
| 110 | + XCTAssertEqual(returnValue, sentinel) |
| 111 | + XCTAssertTrue(dataSource.responds(to: #selector(UICollectionViewDataSource.collectionView(_:viewForSupplementaryElementOfKind:at:)))) |
| 112 | + } |
| 113 | +} |
| 114 | + |
0 commit comments