Fix last tab is undefined

jh-changes
Shin'ya Ueoka 6 years ago
parent b3dafedf88
commit 691e9ca8f2
  1. 6
      src/background/infrastructures/memory-storage.js
  2. 2
      src/background/usecases/operation.js
  3. 5
      test/background/infrastructures/memory-storage.test.js

@ -10,6 +10,10 @@ export default class MemoryStorage {
} }
get(name) { get(name) {
return JSON.parse(db[name]); let data = db[name];
if (!data) {
return undefined;
}
return JSON.parse(data);
} }
} }

@ -183,7 +183,9 @@ export default class OperationInteractor {
onTabSelected(tabId) { onTabSelected(tabId) {
let lastId = this.cache.get(CURRENT_SELECTED_KEY); let lastId = this.cache.get(CURRENT_SELECTED_KEY);
if (lastId) {
this.cache.set(LAST_SELECTED_KEY, lastId); this.cache.set(LAST_SELECTED_KEY, lastId);
}
this.cache.set(CURRENT_SELECTED_KEY, tabId); this.cache.set(CURRENT_SELECTED_KEY, tabId);
} }
} }

@ -15,6 +15,11 @@ describe("background/infrastructures/memory-storage", () => {
expect(cache.get('object')).to.deep.equal({ hello: '123' }); expect(cache.get('object')).to.deep.equal({ hello: '123' });
}); });
it('returns undefined if no keys', () => {
let cache = new MemoryStorage();
expect(cache.get('no-keys')).to.be.undefined;
})
it('stored on shared memory', () => { it('stored on shared memory', () => {
let cache = new MemoryStorage(); let cache = new MemoryStorage();
cache.set('red', 'apple'); cache.set('red', 'apple');