From 6a95be9ddda5ccc3c2c81921a70b0221fa5cc37a Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Thu, 5 Dec 2019 12:04:53 +0100 Subject: [PATCH] Better name, better test --- .../hashed_item_store/hashed_item_store.test.ts | 10 ++++++++-- .../storage/hashed_item_store/hashed_item_store.ts | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/plugins/kibana_utils/public/storage/hashed_item_store/hashed_item_store.test.ts b/src/plugins/kibana_utils/public/storage/hashed_item_store/hashed_item_store.test.ts index a6e83ab45b293..f0ff77d516270 100644 --- a/src/plugins/kibana_utils/public/storage/hashed_item_store/hashed_item_store.test.ts +++ b/src/plugins/kibana_utils/public/storage/hashed_item_store/hashed_item_store.test.ts @@ -275,11 +275,17 @@ describe('hashedItemStore', () => { }); it('removes and returns an item', () => { - const removedItem = hashedItemStore.removeItem('1'); - expect(removedItem).toBe('a'); + const removedItem1 = hashedItemStore.removeItem('1'); + expect(removedItem1).toBe('a'); expect(hashedItemStore.getItem('1')).toBeNull(); expect(hashedItemStore.getItem('2')).not.toBeNull(); expect((hashedItemStore as any).getIndexedItems()).toHaveLength(1); + + const removedItem2 = hashedItemStore.removeItem('2'); + expect(removedItem2).toBe('b'); + expect(hashedItemStore.getItem('1')).toBeNull(); + expect(hashedItemStore.getItem('2')).toBeNull(); + expect((hashedItemStore as any).getIndexedItems()).toHaveLength(0); }); }); diff --git a/src/plugins/kibana_utils/public/storage/hashed_item_store/hashed_item_store.ts b/src/plugins/kibana_utils/public/storage/hashed_item_store/hashed_item_store.ts index 932ecb394a5ee..485aa643c4f01 100644 --- a/src/plugins/kibana_utils/public/storage/hashed_item_store/hashed_item_store.ts +++ b/src/plugins/kibana_utils/public/storage/hashed_item_store/hashed_item_store.ts @@ -114,10 +114,10 @@ export class HashedItemStore implements IStorage { removeItem(hash: string): string | null { const indexedItems = this.getIndexedItems(); const itemToRemove = this.storage.getItem(hash); - const indexToRemove = this.getIndexedItem(hash, indexedItems); + const indexedItemToRemove = this.getIndexedItem(hash, indexedItems); - if (indexToRemove) { - pull(indexedItems, indexToRemove); + if (indexedItemToRemove) { + pull(indexedItems, indexedItemToRemove); this.setIndexedItems(indexedItems); }