-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #434 from hogashi/chrome-storage
use chrome.storage as options storage
- Loading branch information
Showing
22 changed files
with
337 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ jobs: | |
run: yarn test | ||
env: | ||
CI: true | ||
# for jest | ||
FORCE_COLOR: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { chrome } from 'jest-chrome'; | ||
import { | ||
initialOptions, | ||
initialOptionsBool, | ||
isFalse, | ||
MIGRATED_TO_CHROME_STORAGE, | ||
SHOW_ON_TWEETDECK_TIMELINE, | ||
SHOW_ON_TIMELINE, | ||
SHOW_ON_TWEETDECK_TWEET_DETAIL, | ||
} from '../src/constants'; | ||
|
||
import { getOptions, setOptions } from '../src/extension-contexts/options'; | ||
|
||
let chromeStorage = {}; | ||
chrome.storage.sync.set.mockImplementation((items) => { | ||
chromeStorage = { ...chromeStorage, ...items }; | ||
}); | ||
chrome.storage.sync.get.mockImplementation((keys, callback) => { | ||
if (typeof keys === 'string') { | ||
callback({ [keys]: chromeStorage[keys] }); | ||
} else { | ||
callback(Object.fromEntries(Object.entries(chromeStorage).filter(([k, _]) => keys.find((key) => k === key)))); | ||
} | ||
}); | ||
beforeEach(() => { | ||
chromeStorage = {}; | ||
localStorage.clear(); | ||
}); | ||
|
||
describe('options', () => { | ||
describe('getOptions', () => { | ||
it('何もない状態で呼んだら, 初期値が返って, 初期値が保存されて, 移行済みになる', () => { | ||
expect(getOptions()).resolves.toMatchObject(initialOptionsBool); | ||
expect(chromeStorage).toMatchObject({ | ||
...initialOptionsBool, | ||
[MIGRATED_TO_CHROME_STORAGE]: true, | ||
}); | ||
}); | ||
it('未移行で, localStorageに設定があったら, localStorageの内容が移行されつつ返って, 移行済みになる', () => { | ||
Object.entries({ ...initialOptions, [SHOW_ON_TWEETDECK_TIMELINE]: isFalse }).map(([k, v]) => { | ||
localStorage.setItem(k, v); | ||
}); | ||
const expected = { ...initialOptionsBool, [SHOW_ON_TWEETDECK_TIMELINE]: false }; | ||
expect(getOptions()).resolves.toMatchObject(expected); | ||
expect(chromeStorage).toMatchObject({ | ||
...expected, | ||
[MIGRATED_TO_CHROME_STORAGE]: true, | ||
}); | ||
}); | ||
it('移行済みなら, 保存された設定が返る', () => { | ||
Object.entries({ ...initialOptions, [SHOW_ON_TWEETDECK_TIMELINE]: isFalse }).map(([k, v]) => { | ||
localStorage.setItem(k, v); | ||
}); | ||
chromeStorage = { | ||
...initialOptionsBool, | ||
[SHOW_ON_TIMELINE]: false, | ||
[MIGRATED_TO_CHROME_STORAGE]: true, | ||
}; | ||
const expected = { ...initialOptionsBool, [SHOW_ON_TIMELINE]: false }; | ||
expect(getOptions()).resolves.toMatchObject(expected); | ||
expect(chromeStorage).toMatchObject({ | ||
...expected, | ||
[MIGRATED_TO_CHROME_STORAGE]: true, | ||
}); | ||
}); | ||
}); | ||
describe('setOptions', () => { | ||
const expected = { ...initialOptionsBool, [SHOW_ON_TWEETDECK_TWEET_DETAIL]: false }; | ||
setOptions(expected); | ||
expect(chrome.storage.sync.set.mock.calls.length).toBe(1); | ||
expect(chrome.storage.sync.set.mock.lastCall[0]).toBe(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.