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