Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: ios/chrome/browser/ui/suggestions/suggestions_expandable_item_unittest.mm

Issue 2644123003: Move ios/ui/suggestions to ios/ui/content_suggestions (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #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 SuggestionsExpandableCell.
16 @interface TestSuggestionsExpandableCell : SuggestionsExpandableCell
17
18 @property(nonatomic) BOOL expandCalled;
19 @property(nonatomic) BOOL collapseCalled;
20
21 @end
22
23 @implementation TestSuggestionsExpandableCell
24
25 @synthesize expandCalled;
26 @synthesize collapseCalled;
27
28 - (void)expand {
29 [super expand];
30 self.expandCalled = YES;
31 }
32
33 - (void)collapse {
34 [super collapse];
35 self.collapseCalled = YES;
36 }
37
38 @end
39
40 namespace {
41
42 // Tests that configureCell: set all the fields of the cell.
43 TEST(SuggestionsExpandableItemTest, CellIsConfigured) {
44 NSString* title = @"testTitle";
45 NSString* subtitle = @"testSubtitle";
46 UIImage* image = [[UIImage alloc] init];
47 NSString* details = @"testDetails";
48 id mockDelegate = [OCMockObject
49 mockForProtocol:@protocol(SuggestionsExpandableCellDelegate)];
50
51 SuggestionsExpandableItem* item =
52 [[SuggestionsExpandableItem alloc] initWithType:0
53 title:title
54 subtitle:subtitle
55 image:image
56 detailText:details];
57 item.delegate = mockDelegate;
58 SuggestionsExpandableCell* cell = [[[item cellClass] alloc] init];
59 EXPECT_TRUE([cell isMemberOfClass:[SuggestionsExpandableCell class]]);
60
61 [item configureCell:cell];
62 EXPECT_EQ(title, cell.titleLabel.text);
63 EXPECT_EQ(subtitle, cell.subtitleLabel.text);
64 EXPECT_EQ(image, cell.imageView.image);
65 EXPECT_EQ(details, cell.detailLabel.text);
66 EXPECT_EQ(mockDelegate, cell.delegate);
67 }
68
69 // Tests that if the expanded property of the item is YES, the |expand| method
70 // of the cell is called during configuration.
71 TEST(SuggestionsExpandableItemTest, CellIsExpanded) {
72 SuggestionsExpandableItem* item =
73 [[SuggestionsExpandableItem alloc] initWithType:0
74 title:@"title"
75 subtitle:@"subtitle"
76 image:nil
77 detailText:@"detail"];
78 TestSuggestionsExpandableCell* cell =
79 [[TestSuggestionsExpandableCell alloc] init];
80 item.cellClass = [TestSuggestionsExpandableCell class];
81
82 item.expanded = YES;
83 [item configureCell:cell];
84 ASSERT_TRUE(cell.expandCalled);
85 ASSERT_FALSE(cell.collapseCalled);
86 }
87
88 // Tests that if the expanded property of the item is NO, the |collapse| method
89 // of the cell is called during configuration.
90 TEST(SuggestionsExpandableItemTest, CellIsCollapsed) {
91 SuggestionsExpandableItem* item =
92 [[SuggestionsExpandableItem alloc] initWithType:0
93 title:@"title"
94 subtitle:@"subtitle"
95 image:nil
96 detailText:@"detail"];
97 TestSuggestionsExpandableCell* cell =
98 [[TestSuggestionsExpandableCell alloc] init];
99 item.cellClass = [TestSuggestionsExpandableCell class];
100
101 item.expanded = NO;
102 [item configureCell:cell];
103 ASSERT_TRUE(cell.collapseCalled);
104 ASSERT_FALSE(cell.expandCalled);
105 }
106
107 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698