| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_updater.h" | 5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_updater.h" |
| 6 | 6 |
| 7 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 7 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 8 #import "ios/chrome/browser/ui/content_suggestions/content_suggestion.h" | 8 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_tex
t_item.h" |
| 9 #import "ios/chrome/browser/ui/content_suggestions/cells/suggested_content.h" |
| 9 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" | 10 #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
_identifier.h" |
| 11 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
s_section_information.h" | 12 #import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion
s_section_information.h" |
| 12 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
| 13 #import "third_party/ocmock/OCMock/OCMock.h" | 14 #import "third_party/ocmock/OCMock/OCMock.h" |
| 14 #import "third_party/ocmock/gtest_support.h" | 15 #import "third_party/ocmock/gtest_support.h" |
| 15 | 16 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 17 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." | 18 #error "This file requires ARC support." |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 TEST(ContentSuggestionsCollectionUpdaterTest, addEmptyItemToEmptySection) { | 23 TEST(ContentSuggestionsCollectionUpdaterTest, addEmptyItemToEmptySection) { |
| 23 // Setup. | 24 // Setup. |
| 24 ContentSuggestionsCollectionUpdater* updater = | 25 ContentSuggestionsCollectionUpdater* updater = |
| 25 [[ContentSuggestionsCollectionUpdater alloc] initWithDataSource:nil]; | 26 [[ContentSuggestionsCollectionUpdater alloc] initWithDataSource:nil]; |
| 26 CollectionViewModel* model = [[CollectionViewModel alloc] init]; | 27 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 27 id mockCollection = OCMClassMock([ContentSuggestionsViewController class]); | 28 id mockCollection = OCMClassMock([ContentSuggestionsViewController class]); |
| 28 OCMStub([mockCollection collectionViewModel]).andReturn(model); | 29 OCMStub([mockCollection collectionViewModel]).andReturn(model); |
| 29 updater.collectionViewController = mockCollection; | 30 updater.collectionViewController = mockCollection; |
| 30 | 31 |
| 31 ContentSuggestion* suggestion = [[ContentSuggestion alloc] init]; | 32 CollectionViewItem<SuggestedContent>* suggestion = |
| 33 [[ContentSuggestionsTextItem alloc] initWithType:kItemTypeEnumZero]; |
| 32 suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init]; | 34 suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init]; |
| 33 suggestion.suggestionIdentifier.sectionInfo = | 35 suggestion.suggestionIdentifier.sectionInfo = |
| 34 [[ContentSuggestionsSectionInformation alloc] | 36 [[ContentSuggestionsSectionInformation alloc] |
| 35 initWithSectionID:ContentSuggestionsSectionArticles]; | 37 initWithSectionID:ContentSuggestionsSectionArticles]; |
| 36 suggestion.suggestionIdentifier.sectionInfo.showIfEmpty = YES; | 38 suggestion.suggestionIdentifier.sectionInfo.showIfEmpty = YES; |
| 37 [updater addSectionsForSuggestionsToModel:@[ suggestion ]]; | 39 [updater addSectionsForSectionInfoToModel:@[ |
| 40 suggestion.suggestionIdentifier.sectionInfo |
| 41 ]]; |
| 38 ASSERT_EQ(0, [model numberOfItemsInSection:0]); | 42 ASSERT_EQ(0, [model numberOfItemsInSection:0]); |
| 39 | 43 |
| 40 // Action. | 44 // Action. |
| 41 NSIndexPath* addedItem = [updater addEmptyItemForSection:0]; | 45 NSIndexPath* addedItem = [updater addEmptyItemForSection:0]; |
| 42 | 46 |
| 43 // Test. | 47 // Test. |
| 44 EXPECT_TRUE([[NSIndexPath indexPathForItem:0 inSection:0] isEqual:addedItem]); | 48 EXPECT_TRUE([[NSIndexPath indexPathForItem:0 inSection:0] isEqual:addedItem]); |
| 45 ASSERT_EQ(1, [model numberOfItemsInSection:0]); | 49 ASSERT_EQ(1, [model numberOfItemsInSection:0]); |
| 46 } | 50 } |
| 47 | 51 |
| 48 TEST(ContentSuggestionsCollectionUpdaterTest, addEmptyItemToSection) { | 52 TEST(ContentSuggestionsCollectionUpdaterTest, addEmptyItemToSection) { |
| 49 // Setup. | 53 // Setup. |
| 50 ContentSuggestionsCollectionUpdater* updater = | 54 ContentSuggestionsCollectionUpdater* updater = |
| 51 [[ContentSuggestionsCollectionUpdater alloc] initWithDataSource:nil]; | 55 [[ContentSuggestionsCollectionUpdater alloc] initWithDataSource:nil]; |
| 52 CollectionViewModel* model = [[CollectionViewModel alloc] init]; | 56 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
| 53 id mockCollection = OCMClassMock([ContentSuggestionsViewController class]); | 57 id mockCollection = OCMClassMock([ContentSuggestionsViewController class]); |
| 54 OCMStub([mockCollection collectionViewModel]).andReturn(model); | 58 OCMStub([mockCollection collectionViewModel]).andReturn(model); |
| 55 updater.collectionViewController = mockCollection; | 59 updater.collectionViewController = mockCollection; |
| 56 | 60 |
| 57 ContentSuggestion* suggestion = [[ContentSuggestion alloc] init]; | 61 CollectionViewItem<SuggestedContent>* suggestion = |
| 62 [[ContentSuggestionsTextItem alloc] initWithType:kItemTypeEnumZero]; |
| 58 suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init]; | 63 suggestion.suggestionIdentifier = [[ContentSuggestionIdentifier alloc] init]; |
| 59 suggestion.suggestionIdentifier.sectionInfo = | 64 suggestion.suggestionIdentifier.sectionInfo = |
| 60 [[ContentSuggestionsSectionInformation alloc] | 65 [[ContentSuggestionsSectionInformation alloc] |
| 61 initWithSectionID:ContentSuggestionsSectionArticles]; | 66 initWithSectionID:ContentSuggestionsSectionArticles]; |
| 62 suggestion.suggestionIdentifier.sectionInfo.showIfEmpty = YES; | 67 suggestion.suggestionIdentifier.sectionInfo.showIfEmpty = YES; |
| 63 [updater addSectionsForSuggestionsToModel:@[ suggestion ]]; | 68 [updater addSectionsForSectionInfoToModel:@[ |
| 64 [updater addSuggestionsToModel:@[ suggestion ]]; | 69 suggestion.suggestionIdentifier.sectionInfo |
| 70 ]]; |
| 71 [updater addSuggestionsToModel:@[ suggestion ] |
| 72 withSectionInfo:suggestion.suggestionIdentifier.sectionInfo]; |
| 65 ASSERT_EQ(1, [model numberOfItemsInSection:0]); | 73 ASSERT_EQ(1, [model numberOfItemsInSection:0]); |
| 66 | 74 |
| 67 // Action. | 75 // Action. |
| 68 NSIndexPath* addedItem = [updater addEmptyItemForSection:0]; | 76 NSIndexPath* addedItem = [updater addEmptyItemForSection:0]; |
| 69 | 77 |
| 70 // Test. | 78 // Test. |
| 71 EXPECT_TRUE([[NSIndexPath indexPathForItem:1 inSection:0] isEqual:addedItem]); | 79 EXPECT_TRUE([[NSIndexPath indexPathForItem:1 inSection:0] isEqual:addedItem]); |
| 72 ASSERT_EQ(2, [model numberOfItemsInSection:0]); | 80 ASSERT_EQ(2, [model numberOfItemsInSection:0]); |
| 73 } | 81 } |
| 74 | 82 |
| 75 } // namespace | 83 } // namespace |
| OLD | NEW |