Chromium Code Reviews| 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 SuggestionsExpandableCellTest : SuggestionsExpandableCell | |
|
lpromero
2017/01/16 11:35:18
It should be called TestSuggestionsExpandableCell.
gambard
2017/01/16 13:26:03
Done.
| |
| 14 | |
| 15 @property(nonatomic) BOOL expandCalled; | |
| 16 @property(nonatomic) BOOL retractCalled; | |
| 17 | |
| 18 - (void)expand; | |
|
lpromero
2017/01/16 11:35:18
Make a category in the header for SuggestionsExpan
gambard
2017/01/16 13:26:03
Done.
| |
| 19 - (void)retract; | |
| 20 | |
| 21 @end | |
| 22 | |
| 23 @implementation SuggestionsExpandableCellTest | |
| 24 | |
| 25 @synthesize expandCalled; | |
| 26 @synthesize retractCalled; | |
| 27 | |
| 28 - (void)expand { | |
| 29 self.expandCalled = YES; | |
|
lpromero
2017/01/16 11:35:18
Call the parent implementation.
gambard
2017/01/16 13:26:03
Done.
| |
| 30 } | |
| 31 | |
| 32 - (void)retract { | |
| 33 self.retractCalled = YES; | |
|
lpromero
2017/01/16 11:35:18
Idem.
gambard
2017/01/16 13:26:03
Done.
| |
| 34 } | |
| 35 | |
| 36 @end | |
| 37 | |
| 38 namespace { | |
| 39 | |
| 40 // Tests that configureCell: set all the fields of the cell. | |
| 41 TEST(SuggestionsExpandableItemTest, CellIsConfigured) { | |
| 42 NSString* title = @"testTitle"; | |
| 43 NSString* subtitle = @"testSubtitle"; | |
| 44 UIImage* image = [[UIImage alloc] init]; | |
| 45 NSString* details = @"testDetails"; | |
| 46 id mockDelegate = [OCMockObject | |
| 47 mockForProtocol:@protocol(SuggestionsExpandableCellDelegate)]; | |
| 48 | |
| 49 SuggestionsExpandableItem* item = | |
| 50 [[SuggestionsExpandableItem alloc] initWithType:0 | |
| 51 title:title | |
| 52 subtitle:subtitle | |
| 53 image:image | |
| 54 detailText:details]; | |
| 55 item.delegate = mockDelegate; | |
| 56 SuggestionsExpandableCell* cell = [[[item cellClass] alloc] init]; | |
| 57 EXPECT_TRUE([cell isMemberOfClass:[SuggestionsExpandableCell class]]); | |
| 58 | |
| 59 [item configureCell:cell]; | |
| 60 EXPECT_EQ(title, cell.titleLabel.text); | |
| 61 EXPECT_EQ(subtitle, cell.subtitleLabel.text); | |
| 62 EXPECT_EQ(image, cell.imageView.image); | |
| 63 EXPECT_EQ(details, cell.detailLabel.text); | |
| 64 EXPECT_EQ(mockDelegate, cell.delegate); | |
| 65 } | |
| 66 | |
| 67 // Tests that if the expanded property of the item is YES, the |expand| method | |
| 68 // of the cell is called during configuration. | |
| 69 TEST(SuggestionsExpandableItemTest, CellIsExpanded) { | |
| 70 SuggestionsExpandableItem* item = | |
| 71 [[SuggestionsExpandableItem alloc] initWithType:0 | |
| 72 title:@"title" | |
| 73 subtitle:@"subtitle" | |
| 74 image:nil | |
| 75 detailText:@"detail"]; | |
| 76 SuggestionsExpandableCellTest* cell = | |
| 77 [[SuggestionsExpandableCellTest alloc] init]; | |
| 78 item.cellClass = [SuggestionsExpandableCellTest class]; | |
| 79 | |
| 80 item.expanded = YES; | |
| 81 [item configureCell:cell]; | |
| 82 ASSERT_TRUE(cell.expandCalled); | |
| 83 ASSERT_FALSE(cell.retractCalled); | |
| 84 } | |
| 85 | |
| 86 // Tests that if the expanded property of the item is NO, the |retract| method | |
| 87 // of the cell is called during configuration. | |
| 88 TEST(SuggestionsExpandableItemTest, CellIsRetracted) { | |
| 89 SuggestionsExpandableItem* item = | |
| 90 [[SuggestionsExpandableItem alloc] initWithType:0 | |
| 91 title:@"title" | |
| 92 subtitle:@"subtitle" | |
| 93 image:nil | |
| 94 detailText:@"detail"]; | |
| 95 SuggestionsExpandableCellTest* cell = | |
| 96 [[SuggestionsExpandableCellTest alloc] init]; | |
| 97 item.cellClass = [SuggestionsExpandableCellTest class]; | |
| 98 | |
| 99 item.expanded = NO; | |
| 100 [item configureCell:cell]; | |
| 101 ASSERT_TRUE(cell.retractCalled); | |
| 102 ASSERT_FALSE(cell.expandCalled); | |
| 103 } | |
| 104 | |
| 105 } // namespace | |
| OLD | NEW |