Chromium Code Reviews| Index: ios/chrome/browser/ui/suggestions/suggestions_expandable_item_unittest.mm |
| diff --git a/ios/chrome/browser/ui/suggestions/suggestions_expandable_item_unittest.mm b/ios/chrome/browser/ui/suggestions/suggestions_expandable_item_unittest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..80671328f4150d4bfa31cae0be5cb3afa2ea1108 |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/suggestions/suggestions_expandable_item_unittest.mm |
| @@ -0,0 +1,105 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/chrome/browser/ui/suggestions/suggestions_expandable_item.h" |
| + |
| +#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#import "third_party/ocmock/OCMock/OCMock.h" |
| +#include "third_party/ocmock/gtest_support.h" |
| + |
| +// Test subclass of the SuggestionsExpandableCell. |
| +@interface SuggestionsExpandableCellTest : SuggestionsExpandableCell |
|
lpromero
2017/01/16 11:35:18
It should be called TestSuggestionsExpandableCell.
gambard
2017/01/16 13:26:03
Done.
|
| + |
| +@property(nonatomic) BOOL expandCalled; |
| +@property(nonatomic) BOOL retractCalled; |
| + |
| +- (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.
|
| +- (void)retract; |
| + |
| +@end |
| + |
| +@implementation SuggestionsExpandableCellTest |
| + |
| +@synthesize expandCalled; |
| +@synthesize retractCalled; |
| + |
| +- (void)expand { |
| + self.expandCalled = YES; |
|
lpromero
2017/01/16 11:35:18
Call the parent implementation.
gambard
2017/01/16 13:26:03
Done.
|
| +} |
| + |
| +- (void)retract { |
| + self.retractCalled = YES; |
|
lpromero
2017/01/16 11:35:18
Idem.
gambard
2017/01/16 13:26:03
Done.
|
| +} |
| + |
| +@end |
| + |
| +namespace { |
| + |
| +// Tests that configureCell: set all the fields of the cell. |
| +TEST(SuggestionsExpandableItemTest, CellIsConfigured) { |
| + NSString* title = @"testTitle"; |
| + NSString* subtitle = @"testSubtitle"; |
| + UIImage* image = [[UIImage alloc] init]; |
| + NSString* details = @"testDetails"; |
| + id mockDelegate = [OCMockObject |
| + mockForProtocol:@protocol(SuggestionsExpandableCellDelegate)]; |
| + |
| + SuggestionsExpandableItem* item = |
| + [[SuggestionsExpandableItem alloc] initWithType:0 |
| + title:title |
| + subtitle:subtitle |
| + image:image |
| + detailText:details]; |
| + item.delegate = mockDelegate; |
| + SuggestionsExpandableCell* cell = [[[item cellClass] alloc] init]; |
| + EXPECT_TRUE([cell isMemberOfClass:[SuggestionsExpandableCell class]]); |
| + |
| + [item configureCell:cell]; |
| + EXPECT_EQ(title, cell.titleLabel.text); |
| + EXPECT_EQ(subtitle, cell.subtitleLabel.text); |
| + EXPECT_EQ(image, cell.imageView.image); |
| + EXPECT_EQ(details, cell.detailLabel.text); |
| + EXPECT_EQ(mockDelegate, cell.delegate); |
| +} |
| + |
| +// Tests that if the expanded property of the item is YES, the |expand| method |
| +// of the cell is called during configuration. |
| +TEST(SuggestionsExpandableItemTest, CellIsExpanded) { |
| + SuggestionsExpandableItem* item = |
| + [[SuggestionsExpandableItem alloc] initWithType:0 |
| + title:@"title" |
| + subtitle:@"subtitle" |
| + image:nil |
| + detailText:@"detail"]; |
| + SuggestionsExpandableCellTest* cell = |
| + [[SuggestionsExpandableCellTest alloc] init]; |
| + item.cellClass = [SuggestionsExpandableCellTest class]; |
| + |
| + item.expanded = YES; |
| + [item configureCell:cell]; |
| + ASSERT_TRUE(cell.expandCalled); |
| + ASSERT_FALSE(cell.retractCalled); |
| +} |
| + |
| +// Tests that if the expanded property of the item is NO, the |retract| method |
| +// of the cell is called during configuration. |
| +TEST(SuggestionsExpandableItemTest, CellIsRetracted) { |
| + SuggestionsExpandableItem* item = |
| + [[SuggestionsExpandableItem alloc] initWithType:0 |
| + title:@"title" |
| + subtitle:@"subtitle" |
| + image:nil |
| + detailText:@"detail"]; |
| + SuggestionsExpandableCellTest* cell = |
| + [[SuggestionsExpandableCellTest alloc] init]; |
| + item.cellClass = [SuggestionsExpandableCellTest class]; |
| + |
| + item.expanded = NO; |
| + [item configureCell:cell]; |
| + ASSERT_TRUE(cell.retractCalled); |
| + ASSERT_FALSE(cell.expandCalled); |
| +} |
| + |
| +} // namespace |