| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" | 5 #import "ios/chrome/browser/ui/collection_view/collection_view_controller.h" |
| 6 | 6 |
| 7 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 7 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| 8 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 8 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 9 #import "ios/chrome/test/base/scoped_block_swizzler.h" | 9 #import "ios/chrome/test/base/scoped_block_swizzler.h" |
| 10 #include "ios/chrome/test/block_cleanup_test.h" | 10 #include "ios/chrome/test/block_cleanup_test.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 38 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 39 SectionIdentifierFoo = kSectionIdentifierEnumZero, | 39 SectionIdentifierFoo = kSectionIdentifierEnumZero, |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 typedef NS_ENUM(NSInteger, ItemType) { | 42 typedef NS_ENUM(NSInteger, ItemType) { |
| 43 ItemTypeFooBar = kItemTypeEnumZero, | 43 ItemTypeFooBar = kItemTypeEnumZero, |
| 44 ItemTypeFooBiz, | 44 ItemTypeFooBiz, |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 typedef void (^ReconfigureBlock)(CollectionViewController*, | 47 typedef void (^ReconfigureBlock)(CollectionViewController*, NSArray*); |
| 48 NSArray*, | |
| 49 SectionIdentifier); | |
| 50 | 48 |
| 51 class CollectionViewControllerTest : public BlockCleanupTest { | 49 class CollectionViewControllerTest : public BlockCleanupTest { |
| 52 public: | 50 public: |
| 53 void TestReconfigureBlock(ReconfigureBlock block) { | 51 void TestReconfigureBlock(ReconfigureBlock block) { |
| 54 // Setup. | 52 // Setup. |
| 55 CollectionViewController* controller = [[CollectionViewController alloc] | 53 CollectionViewController* controller = [[CollectionViewController alloc] |
| 56 initWithStyle:CollectionViewControllerStyleDefault]; | 54 initWithStyle:CollectionViewControllerStyleDefault]; |
| 57 [controller loadModel]; | 55 [controller loadModel]; |
| 58 | 56 |
| 59 CollectionViewModel* model = [controller collectionViewModel]; | 57 CollectionViewModel* model = [controller collectionViewModel]; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 ScopedBlockSwizzler swizzler([UICollectionView class], | 90 ScopedBlockSwizzler swizzler([UICollectionView class], |
| 93 @selector(cellForItemAtIndexPath:), | 91 @selector(cellForItemAtIndexPath:), |
| 94 ^(id self) { | 92 ^(id self) { |
| 95 return dummyCell; | 93 return dummyCell; |
| 96 }); | 94 }); |
| 97 | 95 |
| 98 NSArray* itemsToReconfigure = @[ | 96 NSArray* itemsToReconfigure = @[ |
| 99 firstReconfiguredItem, secondReconfiguredItem, thirdReconfiguredItem | 97 firstReconfiguredItem, secondReconfiguredItem, thirdReconfiguredItem |
| 100 ]; | 98 ]; |
| 101 // Action. | 99 // Action. |
| 102 block(controller, itemsToReconfigure, SectionIdentifierFoo); | 100 block(controller, itemsToReconfigure); |
| 103 } | 101 } |
| 104 | 102 |
| 105 // Tests. | 103 // Tests. |
| 106 EXPECT_TRUE([firstReconfiguredItem configureCellCalled]); | 104 EXPECT_TRUE([firstReconfiguredItem configureCellCalled]); |
| 107 EXPECT_TRUE([secondReconfiguredItem configureCellCalled]); | 105 EXPECT_TRUE([secondReconfiguredItem configureCellCalled]); |
| 108 EXPECT_TRUE([thirdReconfiguredItem configureCellCalled]); | 106 EXPECT_TRUE([thirdReconfiguredItem configureCellCalled]); |
| 109 | 107 |
| 110 EXPECT_FALSE([firstNonReconfiguredItem configureCellCalled]); | 108 EXPECT_FALSE([firstNonReconfiguredItem configureCellCalled]); |
| 111 EXPECT_FALSE([secondNonReconfiguredItem configureCellCalled]); | 109 EXPECT_FALSE([secondNonReconfiguredItem configureCellCalled]); |
| 112 } | 110 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 138 [[controller collectionViewModel] addItem:someItem | 136 [[controller collectionViewModel] addItem:someItem |
| 139 toSectionWithIdentifier:SectionIdentifierFoo]; | 137 toSectionWithIdentifier:SectionIdentifierFoo]; |
| 140 | 138 |
| 141 ASSERT_EQ(NO, [someItem configureCellCalled]); | 139 ASSERT_EQ(NO, [someItem configureCellCalled]); |
| 142 [controller collectionView:[controller collectionView] | 140 [controller collectionView:[controller collectionView] |
| 143 cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; | 141 cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; |
| 144 EXPECT_EQ(YES, [someItem configureCellCalled]); | 142 EXPECT_EQ(YES, [someItem configureCellCalled]); |
| 145 } | 143 } |
| 146 | 144 |
| 147 TEST_F(CollectionViewControllerTest, ReconfigureCells) { | 145 TEST_F(CollectionViewControllerTest, ReconfigureCells) { |
| 148 TestReconfigureBlock(^void(CollectionViewController* controller, | 146 TestReconfigureBlock( |
| 149 NSArray* itemsToReconfigure, | 147 ^void(CollectionViewController* controller, NSArray* itemsToReconfigure) { |
| 150 SectionIdentifier sectionIdentifier) { | 148 [controller reconfigureCellsForItems:itemsToReconfigure]; |
| 151 [controller reconfigureCellsForItems:itemsToReconfigure | 149 }); |
| 152 inSectionWithIdentifier:sectionIdentifier]; | |
| 153 }); | |
| 154 } | 150 } |
| 155 | 151 |
| 156 TEST_F(CollectionViewControllerTest, ReconfigureCellsWithIndexPath) { | 152 TEST_F(CollectionViewControllerTest, ReconfigureCellsWithIndexPath) { |
| 157 TestReconfigureBlock(^void(CollectionViewController* controller, | 153 TestReconfigureBlock( |
| 158 NSArray* itemsToReconfigure, | 154 ^void(CollectionViewController* controller, NSArray* itemsToReconfigure) { |
| 159 SectionIdentifier sectionIdentifier) { | 155 // More setup. |
| 160 // More setup. | 156 NSMutableArray* indexPaths = [NSMutableArray array]; |
| 161 NSMutableArray* indexPaths = [NSMutableArray array]; | 157 for (CollectionViewItem* item : itemsToReconfigure) { |
| 162 for (CollectionViewItem* item : itemsToReconfigure) { | 158 NSIndexPath* indexPath = |
| 163 NSIndexPath* indexPath = | 159 [controller.collectionViewModel indexPathForItem:item]; |
| 164 [controller.collectionViewModel indexPathForItem:item | 160 if (indexPath) { |
| 165 inSectionWithIdentifier:sectionIdentifier]; | 161 [indexPaths addObject:indexPath]; |
| 166 if (indexPath) { | 162 } |
| 167 [indexPaths addObject:indexPath]; | 163 } |
| 168 } | |
| 169 } | |
| 170 | 164 |
| 171 // Action. | 165 // Action. |
| 172 [controller reconfigureCellsAtIndexPaths:indexPaths]; | 166 [controller reconfigureCellsAtIndexPaths:indexPaths]; |
| 173 }); | 167 }); |
| 174 } | 168 } |
| OLD | NEW |