OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/collection_view/collection_view_model.h" | 5 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 [model addItemWithType:ItemTypeWeasleyArthur | 515 [model addItemWithType:ItemTypeWeasleyArthur |
516 toSectionWithIdentifier:SectionIdentifierWeasley]; | 516 toSectionWithIdentifier:SectionIdentifierWeasley]; |
517 // Repeated item added at index 4. | 517 // Repeated item added at index 4. |
518 CollectionViewItem* item4 = | 518 CollectionViewItem* item4 = |
519 [[CollectionViewItem alloc] initWithType:ItemTypeWeasleyArthur]; | 519 [[CollectionViewItem alloc] initWithType:ItemTypeWeasleyArthur]; |
520 [model addItem:item4 toSectionWithIdentifier:SectionIdentifierWeasley]; | 520 [model addItem:item4 toSectionWithIdentifier:SectionIdentifierWeasley]; |
521 [model addItemWithType:ItemTypeWeasleyArthur | 521 [model addItemWithType:ItemTypeWeasleyArthur |
522 toSectionWithIdentifier:SectionIdentifierWeasley]; | 522 toSectionWithIdentifier:SectionIdentifierWeasley]; |
523 [model addItemWithType:ItemTypeWeasleyArthur | 523 [model addItemWithType:ItemTypeWeasleyArthur |
524 toSectionWithIdentifier:SectionIdentifierWeasley]; | 524 toSectionWithIdentifier:SectionIdentifierWeasley]; |
| 525 // Item not added. |
| 526 CollectionViewItem* notAddedItem = |
| 527 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseGouda]; |
525 | 528 |
526 NSIndexPath* indexPath1 = [model indexPathForItem:item1 | 529 EXPECT_TRUE([model hasItem:item1]); |
527 inSectionWithIdentifier:SectionIdentifierWeasley]; | 530 NSIndexPath* indexPath1 = [model indexPathForItem:item1]; |
528 EXPECT_EQ(0, indexPath1.section); | 531 EXPECT_EQ(0, indexPath1.section); |
529 EXPECT_EQ(1, indexPath1.item); | 532 EXPECT_EQ(1, indexPath1.item); |
530 | 533 |
531 NSIndexPath* indexPath4 = [model indexPathForItem:item4 | 534 EXPECT_TRUE([model hasItem:item4]); |
532 inSectionWithIdentifier:SectionIdentifierWeasley]; | 535 NSIndexPath* indexPath4 = [model indexPathForItem:item4]; |
533 EXPECT_EQ(0, indexPath4.section); | 536 EXPECT_EQ(0, indexPath4.section); |
534 EXPECT_EQ(4, indexPath4.item); | 537 EXPECT_EQ(4, indexPath4.item); |
| 538 |
| 539 EXPECT_FALSE([model hasItem:notAddedItem]); |
535 } | 540 } |
536 | 541 |
537 TEST(CollectionViewModelTest, Headers) { | 542 TEST(CollectionViewModelTest, Headers) { |
538 CollectionViewModel* model = [[CollectionViewModel alloc] init]; | 543 CollectionViewModel* model = [[CollectionViewModel alloc] init]; |
539 | 544 |
540 [model addSectionWithIdentifier:SectionIdentifierCheese]; | 545 [model addSectionWithIdentifier:SectionIdentifierCheese]; |
541 CollectionViewItem* cheeseHeader = | 546 CollectionViewItem* cheeseHeader = |
542 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseHeader]; | 547 [[CollectionViewItem alloc] initWithType:ItemTypeCheeseHeader]; |
543 [model setHeader:cheeseHeader | 548 [model setHeader:cheeseHeader |
544 forSectionWithIdentifier:SectionIdentifierCheese]; | 549 forSectionWithIdentifier:SectionIdentifierCheese]; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 | 595 |
591 EXPECT_FALSE([model footerForSectionWithIdentifier:SectionIdentifierCheese]); | 596 EXPECT_FALSE([model footerForSectionWithIdentifier:SectionIdentifierCheese]); |
592 EXPECT_FALSE([model footerForSection:cheeseSection]); | 597 EXPECT_FALSE([model footerForSection:cheeseSection]); |
593 | 598 |
594 EXPECT_EQ(weasleyFooter, | 599 EXPECT_EQ(weasleyFooter, |
595 [model footerForSectionWithIdentifier:SectionIdentifierWeasley]); | 600 [model footerForSectionWithIdentifier:SectionIdentifierWeasley]); |
596 EXPECT_EQ(weasleyFooter, [model footerForSection:weasleySection]); | 601 EXPECT_EQ(weasleyFooter, [model footerForSection:weasleySection]); |
597 } | 602 } |
598 | 603 |
599 } // namespace | 604 } // namespace |
OLD | NEW |