@@ -11,26 +11,115 @@ import XCTest
1111
1212class YBSlantedCollectionViewLayoutTests : XCTestCase {
1313
14+ var verticalSlantedViewLayout : YBSlantedCollectionViewLayout !
15+ var collectionViewController : CollectionViewController !
16+
17+ var horizontalSlantedViewLayout : YBSlantedCollectionViewLayout !
18+ var horizontalCollectionViewController : CollectionViewController !
19+
1420 override func setUp( ) {
1521 super. setUp ( )
1622 // Put setup code here. This method is called before the invocation of each test method in the class.
23+ verticalSlantedViewLayout = YBSlantedCollectionViewLayout ( )
24+ collectionViewController = CollectionViewController ( collectionViewLayout: verticalSlantedViewLayout)
25+ collectionViewController. view. frame = CGRect ( x: 0 , y: 0 , width: 600 , height: 600 )
26+
27+ horizontalSlantedViewLayout = YBSlantedCollectionViewLayout ( )
28+ horizontalSlantedViewLayout. scrollDirection = UICollectionViewScrollDirection . Horizontal
29+ horizontalSlantedViewLayout. lineSpacing = 3
30+ horizontalSlantedViewLayout. itemSizeOptions = YBSlantedCollectionViewLayoutSizeOptions ( VerticalSize: 100 , HorizontalSize: 210 )
31+ horizontalSlantedViewLayout. reverseSlantingAngle = true
32+ horizontalCollectionViewController = CollectionViewController ( collectionViewLayout: horizontalSlantedViewLayout)
33+ horizontalCollectionViewController. view. frame = CGRect ( x: 0 , y: 0 , width: 600 , height: 600 )
1734 }
1835
1936 override func tearDown( ) {
2037 // Put teardown code here. This method is called after the invocation of each test method in the class.
2138 super. tearDown ( )
2239 }
2340
24- func testExample( ) {
25- // This is an example of a functional test case.
26- // Use XCTAssert and related functions to verify your tests produce the correct results.
41+ func testSlantedViewLayoutHasDefaultValues( ) {
42+ XCTAssertEqual ( verticalSlantedViewLayout. slantingDelta, 50 )
43+ XCTAssertEqual ( verticalSlantedViewLayout. reverseSlantingAngle, false )
44+ XCTAssertEqual ( verticalSlantedViewLayout. firstCellSlantingEnabled, true )
45+ XCTAssertEqual ( verticalSlantedViewLayout. lastCellSlantingEnabled, true )
46+ XCTAssertEqual ( verticalSlantedViewLayout. lineSpacing, 10 )
47+ XCTAssertEqual ( verticalSlantedViewLayout. scrollDirection, UICollectionViewScrollDirection . Vertical)
48+ XCTAssertEqual ( verticalSlantedViewLayout. itemSizeOptions. VerticalSize, 220 )
49+ XCTAssertEqual ( verticalSlantedViewLayout. itemSizeOptions. HorizontalSize, 290 )
50+ }
51+
52+ func testLayoutContentViewSizeUsesController( ) {
53+ collectionViewController. items = [ 0 , 1 , 2 , 3 , 5 , 6 , 7 , 8 , 9 ]
54+ collectionViewController. view. layoutIfNeeded ( )
55+
56+ let verticalSlantedViewLayoutSize = self . verticalSlantedViewLayout. collectionViewContentSize ( )
57+ let collectionViewControllerSize = self . collectionViewController. view. frame. size
58+
59+ let size = verticalSlantedViewLayout. itemSizeOptions. VerticalSize
60+ let lineSpicing = verticalSlantedViewLayout. lineSpacing
61+ let slantingDelta = CGFloat ( verticalSlantedViewLayout. slantingDelta)
62+
63+ let contentSize = CGFloat ( collectionViewController. items. count) * ( size - slantingDelta + lineSpicing ) + slantingDelta - lineSpicing
64+ XCTAssertEqual ( verticalSlantedViewLayoutSize. width, collectionViewControllerSize. width)
65+ XCTAssertEqual ( verticalSlantedViewLayoutSize. height, contentSize)
66+ }
67+
68+ func testHorizontalLayoutContentViewSizeUsesController( ) {
69+ horizontalCollectionViewController. items = [ 0 , 1 , 2 , 3 , 5 , 6 , 7 , 8 , 9 ]
70+ horizontalCollectionViewController. view. layoutIfNeeded ( )
71+
72+ let verticalSlantedViewLayoutSize = horizontalSlantedViewLayout. collectionViewContentSize ( )
73+ let collectionViewControllerSize = horizontalCollectionViewController. view. frame. size
74+
75+ let size = horizontalSlantedViewLayout. itemSizeOptions. HorizontalSize
76+ let lineSpicing = horizontalSlantedViewLayout. lineSpacing
77+ let slantingDelta = CGFloat ( horizontalSlantedViewLayout. slantingDelta)
78+
79+ let contentSize = CGFloat ( horizontalCollectionViewController. items. count) * ( size - slantingDelta + lineSpicing ) + slantingDelta - lineSpicing
80+ XCTAssertEqual ( verticalSlantedViewLayoutSize. width, contentSize)
81+ XCTAssertEqual ( verticalSlantedViewLayoutSize. height, collectionViewControllerSize. height)
82+ }
83+
84+
85+ func testLayoutHasSmoothScrolling( ) {
86+ let proposedOffset = verticalSlantedViewLayout. targetContentOffsetForProposedContentOffset ( CGPoint ( ) , withScrollingVelocity: CGPoint ( ) )
87+
88+ XCTAssertEqual ( proposedOffset. x, 0 )
89+ XCTAssertEqual ( proposedOffset. y, 0 )
90+ }
91+
92+ func testLayoutHasCachedLayoutAttributes( ) {
93+ collectionViewController. items = [ 0 ]
94+
95+ collectionViewController. view. layoutIfNeeded ( )
96+
97+ XCTAssertEqual ( verticalSlantedViewLayout. cached. count, 1 ) ;
98+ }
99+
100+ func testLayoutAttributeIsCached( ) {
101+ collectionViewController. items = [ 0 ]
102+
103+ collectionViewController. view. layoutIfNeeded ( )
104+
105+ let attributes = verticalSlantedViewLayout. layoutAttributesForElementsInRect ( CGRect ( ) ) !
106+
107+ XCTAssertEqual ( verticalSlantedViewLayout. cached, attributes)
108+ }
109+
110+ func testLayoutHasLayoutAttributesAtIndexPath( ) {
111+ collectionViewController. items = [ 0 , 1 , 2 ]
112+
113+ collectionViewController. view. layoutIfNeeded ( )
114+
115+ let indexPath = NSIndexPath ( forItem: 0 , inSection: 0 )
116+ let attribute = verticalSlantedViewLayout. layoutAttributesForItemAtIndexPath ( indexPath)
117+
118+ XCTAssertEqual ( verticalSlantedViewLayout. cached [ 0 ] , attribute)
27119 }
28120
29- func testPerformanceExample( ) {
30- // This is an example of a performance test case.
31- self . measureBlock {
32- // Put the code you want to measure the time of here.
33- }
121+ func testLayoutShouldInvalidateLayoutForBoundsChange( ) {
122+ XCTAssertTrue ( verticalSlantedViewLayout. shouldInvalidateLayoutForBoundsChange ( CGRect ( ) ) )
34123 }
35124
36125}
0 commit comments