Commit edef68dc authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] Added deleteAllItemsFromSection to list_model

Added a function to remove all items from a section, so that only
that section can be regenerated dynamically.

Bug: 826094
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ia873e56b0bbb8d9527b719d665ed536dddf83d41
Reviewed-on: https://chromium-review.googlesource.com/1186401
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585750}
parent b921d3fe
...@@ -96,6 +96,10 @@ const NSInteger kItemTypeEnumZero = 100; ...@@ -96,6 +96,10 @@ const NSInteger kItemTypeEnumZero = 100;
// left in the section, they are removed. // left in the section, they are removed.
- (void)removeSectionWithIdentifier:(NSInteger)sectionIdentifier; - (void)removeSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Deletes all items from |sectionIdentifier|, |sectionIdentifier| won't be
// removed from the model.
- (void)deleteAllItemsFromSectionWithIdentifier:(NSInteger)sectionIdentifier;
// Sets the header item for the section with the given |sectionIdentifier|. // Sets the header item for the section with the given |sectionIdentifier|.
- (void)setHeader:(SupplementalType)header - (void)setHeader:(SupplementalType)header
forSectionWithIdentifier:(NSInteger)sectionIdentifier; forSectionWithIdentifier:(NSInteger)sectionIdentifier;
......
...@@ -114,6 +114,12 @@ typedef NSMutableArray<ListItem*> SectionItems; ...@@ -114,6 +114,12 @@ typedef NSMutableArray<ListItem*> SectionItems;
[_collapsedKeys removeObjectForKey:@(sectionIdentifier)]; [_collapsedKeys removeObjectForKey:@(sectionIdentifier)];
} }
- (void)deleteAllItemsFromSectionWithIdentifier:(NSInteger)sectionIdentifier {
NSInteger section = [self sectionForSectionIdentifier:sectionIdentifier];
SectionItems* items = [_sections objectAtIndex:section];
[items removeAllObjects];
}
- (void)setHeader:(ListItem*)header - (void)setHeader:(ListItem*)header
forSectionWithIdentifier:(NSInteger)sectionIdentifier { forSectionWithIdentifier:(NSInteger)sectionIdentifier {
NSNumber* key = [NSNumber numberWithInteger:sectionIdentifier]; NSNumber* key = [NSNumber numberWithInteger:sectionIdentifier];
......
...@@ -384,6 +384,70 @@ TEST_F(ListModelTest, RemoveItems) { ...@@ -384,6 +384,70 @@ TEST_F(ListModelTest, RemoveItems) {
EXPECT_EQ(2, indexPath.item); EXPECT_EQ(2, indexPath.item);
} }
TEST_F(ListModelTest, RemoveAllItems) {
ListModel* model = [[ListModel alloc] init];
[model addSectionWithIdentifier:SectionIdentifierCheese];
[model addItemWithType:ItemTypeCheesePepperJack
toSectionWithIdentifier:SectionIdentifierCheese];
[model addItemWithType:ItemTypeCheeseGouda
toSectionWithIdentifier:SectionIdentifierCheese];
[model addSectionWithIdentifier:SectionIdentifierWeasley];
[model addItemWithType:ItemTypeWeasleyGinny
toSectionWithIdentifier:SectionIdentifierWeasley];
[model addItemWithType:ItemTypeWeasleyArthur
toSectionWithIdentifier:SectionIdentifierWeasley];
[model deleteAllItemsFromSectionWithIdentifier:SectionIdentifierCheese];
// Check we still have two sections.
EXPECT_EQ(2, [model numberOfSections]);
// Check we have no more items in first section.
EXPECT_EQ(0, [model numberOfItemsInSection:0]);
EXPECT_EQ(2, [model numberOfItemsInSection:1]);
// Check the index path retrieval method for a single item.
NSIndexPath* indexPath =
[model indexPathForItemType:ItemTypeWeasleyGinny
sectionIdentifier:SectionIdentifierWeasley];
EXPECT_EQ(1, indexPath.section);
EXPECT_EQ(0, indexPath.item);
[model addItemWithType:ItemTypeCheeseGouda
toSectionWithIdentifier:SectionIdentifierCheese];
// Check we could still add to the section.
EXPECT_EQ(1, [model numberOfItemsInSection:0]);
EXPECT_EQ(2, [model numberOfItemsInSection:1]);
}
TEST_F(ListModelTest, RemoveAllItemsFromAnEmptySection) {
ListModel* model = [[ListModel alloc] init];
[model addSectionWithIdentifier:SectionIdentifierCheese];
[model addSectionWithIdentifier:SectionIdentifierWeasley];
[model addItemWithType:ItemTypeWeasleyGinny
toSectionWithIdentifier:SectionIdentifierWeasley];
[model addItemWithType:ItemTypeWeasleyArthur
toSectionWithIdentifier:SectionIdentifierWeasley];
// Check we have no more items in first section.
EXPECT_EQ(0, [model numberOfItemsInSection:0]);
EXPECT_EQ(2, [model numberOfItemsInSection:1]);
[model deleteAllItemsFromSectionWithIdentifier:SectionIdentifierCheese];
// Check we still have two sections.
EXPECT_EQ(2, [model numberOfSections]);
// Check we still have no items in first section.
EXPECT_EQ(0, [model numberOfItemsInSection:0]);
EXPECT_EQ(2, [model numberOfItemsInSection:1]);
}
TEST_F(ListModelTest, RemoveSections) { TEST_F(ListModelTest, RemoveSections) {
ListModel* model = [[ListModel alloc] init]; ListModel* model = [[ListModel alloc] init];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment