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