diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /browser/components/newtab/test/unit/lib/SystemTickFeed.test.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/newtab/test/unit/lib/SystemTickFeed.test.js')
-rw-r--r-- | browser/components/newtab/test/unit/lib/SystemTickFeed.test.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/browser/components/newtab/test/unit/lib/SystemTickFeed.test.js b/browser/components/newtab/test/unit/lib/SystemTickFeed.test.js new file mode 100644 index 0000000000..4dd5febdb2 --- /dev/null +++ b/browser/components/newtab/test/unit/lib/SystemTickFeed.test.js @@ -0,0 +1,76 @@ +import { SYSTEM_TICK_INTERVAL, SystemTickFeed } from "lib/SystemTickFeed.jsm"; +import { actionTypes as at } from "common/Actions.sys.mjs"; +import { GlobalOverrider } from "test/unit/utils"; + +describe("System Tick Feed", () => { + let globals; + let instance; + let clock; + + beforeEach(() => { + globals = new GlobalOverrider(); + clock = sinon.useFakeTimers(); + + instance = new SystemTickFeed(); + instance.store = { + getState() { + return {}; + }, + dispatch() {}, + }; + }); + afterEach(() => { + globals.restore(); + clock.restore(); + }); + it("should create a SystemTickFeed", () => { + assert.instanceOf(instance, SystemTickFeed); + }); + it("should fire SYSTEM_TICK events at configured interval", () => { + globals.set("ChromeUtils", { + idleDispatch: f => f(), + }); + let expectation = sinon + .mock(instance.store) + .expects("dispatch") + .twice() + .withExactArgs({ type: at.SYSTEM_TICK }); + + instance.onAction({ type: at.INIT }); + clock.tick(SYSTEM_TICK_INTERVAL * 2); + expectation.verify(); + }); + it("should not fire SYSTEM_TICK events after UNINIT", () => { + let expectation = sinon.mock(instance.store).expects("dispatch").never(); + + instance.onAction({ type: at.UNINIT }); + clock.tick(SYSTEM_TICK_INTERVAL * 2); + expectation.verify(); + }); + it("should not fire SYSTEM_TICK events while the user is away", () => { + let expectation = sinon.mock(instance.store).expects("dispatch").never(); + + instance.onAction({ type: at.INIT }); + instance._idleService = { idleTime: SYSTEM_TICK_INTERVAL + 1 }; + clock.tick(SYSTEM_TICK_INTERVAL * 3); + expectation.verify(); + instance.onAction({ type: at.UNINIT }); + }); + it("should fire SYSTEM_TICK immediately when the user is active again", () => { + globals.set("ChromeUtils", { + idleDispatch: f => f(), + }); + let expectation = sinon + .mock(instance.store) + .expects("dispatch") + .once() + .withExactArgs({ type: at.SYSTEM_TICK }); + + instance.onAction({ type: at.INIT }); + instance._idleService = { idleTime: SYSTEM_TICK_INTERVAL + 1 }; + clock.tick(SYSTEM_TICK_INTERVAL * 3); + instance.observe(); + expectation.verify(); + instance.onAction({ type: at.UNINIT }); + }); +}); |