OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/suggestions/suggestions_expandable_item.h" |
| 6 |
| 7 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #import "third_party/ocmock/OCMock/OCMock.h" |
| 10 #include "third_party/ocmock/gtest_support.h" |
| 11 |
| 12 // Test subclass of the SuggestionsExpandableCell. |
| 13 @interface TestSuggestionsExpandableCell : SuggestionsExpandableCell |
| 14 |
| 15 @property(nonatomic) BOOL expandCalled; |
| 16 @property(nonatomic) BOOL collapseCalled; |
| 17 |
| 18 @end |
| 19 |
| 20 @implementation TestSuggestionsExpandableCell |
| 21 |
| 22 @synthesize expandCalled; |
| 23 @synthesize collapseCalled; |
| 24 |
| 25 - (void)expand { |
| 26 [super expand]; |
| 27 self.expandCalled = YES; |
| 28 } |
| 29 |
| 30 - (void)collapse { |
| 31 [super collapse]; |
| 32 self.collapseCalled = YES; |
| 33 } |
| 34 |
| 35 @end |
| 36 |
| 37 namespace { |
| 38 |
| 39 // Tests that configureCell: set all the fields of the cell. |
| 40 TEST(SuggestionsExpandableItemTest, CellIsConfigured) { |
| 41 NSString* title = @"testTitle"; |
| 42 NSString* subtitle = @"testSubtitle"; |
| 43 UIImage* image = [[UIImage alloc] init]; |
| 44 NSString* details = @"testDetails"; |
| 45 id mockDelegate = [OCMockObject |
| 46 mockForProtocol:@protocol(SuggestionsExpandableCellDelegate)]; |
| 47 |
| 48 SuggestionsExpandableItem* item = |
| 49 [[SuggestionsExpandableItem alloc] initWithType:0 |
| 50 title:title |
| 51 subtitle:subtitle |
| 52 image:image |
| 53 detailText:details]; |
| 54 item.delegate = mockDelegate; |
| 55 SuggestionsExpandableCell* cell = [[[item cellClass] alloc] init]; |
| 56 EXPECT_TRUE([cell isMemberOfClass:[SuggestionsExpandableCell class]]); |
| 57 |
| 58 [item configureCell:cell]; |
| 59 EXPECT_EQ(title, cell.titleLabel.text); |
| 60 EXPECT_EQ(subtitle, cell.subtitleLabel.text); |
| 61 EXPECT_EQ(image, cell.imageView.image); |
| 62 EXPECT_EQ(details, cell.detailLabel.text); |
| 63 EXPECT_EQ(mockDelegate, cell.delegate); |
| 64 } |
| 65 |
| 66 // Tests that if the expanded property of the item is YES, the |expand| method |
| 67 // of the cell is called during configuration. |
| 68 TEST(SuggestionsExpandableItemTest, CellIsExpanded) { |
| 69 SuggestionsExpandableItem* item = |
| 70 [[SuggestionsExpandableItem alloc] initWithType:0 |
| 71 title:@"title" |
| 72 subtitle:@"subtitle" |
| 73 image:nil |
| 74 detailText:@"detail"]; |
| 75 TestSuggestionsExpandableCell* cell = |
| 76 [[TestSuggestionsExpandableCell alloc] init]; |
| 77 item.cellClass = [TestSuggestionsExpandableCell class]; |
| 78 |
| 79 item.expanded = YES; |
| 80 [item configureCell:cell]; |
| 81 ASSERT_TRUE(cell.expandCalled); |
| 82 ASSERT_FALSE(cell.collapseCalled); |
| 83 } |
| 84 |
| 85 // Tests that if the expanded property of the item is NO, the |collapse| method |
| 86 // of the cell is called during configuration. |
| 87 TEST(SuggestionsExpandableItemTest, CellIsCollapsed) { |
| 88 SuggestionsExpandableItem* item = |
| 89 [[SuggestionsExpandableItem alloc] initWithType:0 |
| 90 title:@"title" |
| 91 subtitle:@"subtitle" |
| 92 image:nil |
| 93 detailText:@"detail"]; |
| 94 TestSuggestionsExpandableCell* cell = |
| 95 [[TestSuggestionsExpandableCell alloc] init]; |
| 96 item.cellClass = [TestSuggestionsExpandableCell class]; |
| 97 |
| 98 item.expanded = NO; |
| 99 [item configureCell:cell]; |
| 100 ASSERT_TRUE(cell.collapseCalled); |
| 101 ASSERT_FALSE(cell.expandCalled); |
| 102 } |
| 103 |
| 104 } // namespace |
OLD | NEW |