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

Side by Side Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_updater_unittest.mm

Issue 2775593002: Add a message to empty ContentSuggestions sections (Closed)
Patch Set: Change tests Created 3 years, 8 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/content_suggestions/content_suggestions_collectio n_updater.h"
6
7 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
8 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h"
9 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont roller.h"
10 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion _identifier.h"
11 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion s_section_information.h"
12 #include "testing/platform_test.h"
13 #import "third_party/ocmock/OCMock/OCMock.h"
14 #import "third_party/ocmock/gtest_support.h"
15
16 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support."
18 #endif
19
20 namespace {
21
22 TEST(ContentSuggestionsCollectionUpdaterTest, addEmptyItemToEmptySection) {
23 // Setup.
24 ContentSuggestionsCollectionUpdater* updater =
25 [[ContentSuggestionsCollectionUpdater alloc] initWithDataSource:nil];
26 CollectionViewModel* model = [[CollectionViewModel alloc] init];
27 id mockCollection = OCMClassMock([ContentSuggestionsViewController class]);
28 OCMStub([mockCollection collectionViewModel]).andReturn(model);
29 updater.collectionViewController = mockCollection;
30
31 ContentSuggestion* suggestion = [[ContentSuggestion alloc] init];
32 suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init];
33 suggestion.suggestionIdentifier.sectionInfo =
34 [[ContentSuggestionsSectionInformation alloc]
35 initWithSectionID:ContentSuggestionsSectionArticles];
36 suggestion.suggestionIdentifier.sectionInfo.showIfEmpty = YES;
37 [updater addSectionsForSuggestionsToModel:@[ suggestion ]];
38 ASSERT_EQ(0, [model numberOfItemsInSection:0]);
39
40 // Action.
41 NSIndexPath* addedItem = [updater addEmptyItemForSection:0];
42
43 // Test.
44 EXPECT_TRUE([[NSIndexPath indexPathForItem:0 inSection:0] isEqual:addedItem]);
45 ASSERT_EQ(1, [model numberOfItemsInSection:0]);
46 }
47
48 TEST(ContentSuggestionsCollectionUpdaterTest, addEmptyItemToSection) {
49 // Setup.
50 ContentSuggestionsCollectionUpdater* updater =
51 [[ContentSuggestionsCollectionUpdater alloc] initWithDataSource:nil];
52 CollectionViewModel* model = [[CollectionViewModel alloc] init];
53 id mockCollection = OCMClassMock([ContentSuggestionsViewController class]);
54 OCMStub([mockCollection collectionViewModel]).andReturn(model);
55 updater.collectionViewController = mockCollection;
56
57 ContentSuggestion* suggestion = [[ContentSuggestion alloc] init];
58 suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init];
59 suggestion.suggestionIdentifier.sectionInfo =
60 [[ContentSuggestionsSectionInformation alloc]
61 initWithSectionID:ContentSuggestionsSectionArticles];
62 suggestion.suggestionIdentifier.sectionInfo.showIfEmpty = YES;
63 [updater addSectionsForSuggestionsToModel:@[ suggestion ]];
64 [updater addSuggestionsToModel:@[ suggestion ]];
65 ASSERT_EQ(1, [model numberOfItemsInSection:0]);
66
67 // Action.
68 NSIndexPath* addedItem = [updater addEmptyItemForSection:0];
69
70 // Test.
71 EXPECT_TRUE([[NSIndexPath indexPathForItem:1 inSection:0] isEqual:addedItem]);
72 ASSERT_EQ(2, [model numberOfItemsInSection:0]);
73 }
74
75 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698