r3bl-org / shortlink

This Chrome extension provides a browser action that simply allows the user to create a shortlink for all the selected tabs in the current window. It can be activated via a keyboard shortcut Alt + L. To use it, in the omnibar, type go then press Tab, then type the phrase you have created a shortlink for earlier & it will open the tab(s).
https://chrome.google.com/webstore/detail/shorty/ffhfkgcfbjoadmhdmdcmigopbfkddial?hl=en-US&gl=US
MIT License
11 stars 13 forks source link

Create comprehensive tests to check the logic of the entire extension #32

Open nazmulidris opened 11 months ago

nazmulidris commented 11 months ago

Currently storage.ts isn't well tested. It is not trivial to test the logic here since a lot of the work gets delegated to chrome.storage.

We should introduce dependency injection to solve this issue by passing something that wraps chrome.storage or whatever other storage provider we decide to use in the future. We can also introduce an interface type for this storage provider.

Here's a great video on DI: https://www.youtube.com/watch?v=J1f5b4vcxCQ

In tests, we can then pass a fixture for the storage provider that we can use to verify our tests.

superbahbi commented 11 months ago

We could use browser.storage.sync instead of the Chrome storage API. It works similarly, except it supports Chrome, Firefox, and Edge. https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/sync

nazmulidris commented 11 months ago

@superbahbi This refactor makes it possible to totally abstract any browser implementation details using DI: https://github.com/r3bl-org/shortlink/blob/main/src/storage/storage_provider_api.ts

This opens the doors for writing comprehensive tests and supporting other browsers and electron environments, etc.