diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/components/newtab/test/unit/lib/NewTabInit.test.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/newtab/test/unit/lib/NewTabInit.test.js')
-rw-r--r-- | browser/components/newtab/test/unit/lib/NewTabInit.test.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/browser/components/newtab/test/unit/lib/NewTabInit.test.js b/browser/components/newtab/test/unit/lib/NewTabInit.test.js new file mode 100644 index 0000000000..68ab9d7821 --- /dev/null +++ b/browser/components/newtab/test/unit/lib/NewTabInit.test.js @@ -0,0 +1,81 @@ +import { + actionCreators as ac, + actionTypes as at, +} from "common/Actions.sys.mjs"; +import { NewTabInit } from "lib/NewTabInit.sys.mjs"; + +describe("NewTabInit", () => { + let instance; + let store; + let STATE; + const requestFromTab = portID => + instance.onAction( + ac.AlsoToMain({ type: at.NEW_TAB_STATE_REQUEST }, portID) + ); + beforeEach(() => { + STATE = {}; + store = { getState: sinon.stub().returns(STATE), dispatch: sinon.stub() }; + instance = new NewTabInit(); + instance.store = store; + }); + it("should reply with a copy of the state immediately", () => { + requestFromTab(123); + + const resp = ac.AlsoToOneContent( + { type: at.NEW_TAB_INITIAL_STATE, data: STATE }, + 123 + ); + assert.calledWith(store.dispatch, resp); + }); + describe("early / simulated new tabs", () => { + const simulateTabInit = portID => + instance.onAction({ + type: at.NEW_TAB_INIT, + data: { portID, simulated: true }, + }); + beforeEach(() => { + simulateTabInit("foo"); + }); + it("should dispatch if not replied yet", () => { + requestFromTab("foo"); + + assert.calledWith( + store.dispatch, + ac.AlsoToOneContent( + { type: at.NEW_TAB_INITIAL_STATE, data: STATE }, + "foo" + ) + ); + }); + it("should dispatch once for multiple requests", () => { + requestFromTab("foo"); + requestFromTab("foo"); + requestFromTab("foo"); + + assert.calledOnce(store.dispatch); + }); + describe("multiple tabs", () => { + beforeEach(() => { + simulateTabInit("bar"); + }); + it("should dispatch once to each tab", () => { + requestFromTab("foo"); + requestFromTab("bar"); + assert.calledTwice(store.dispatch); + requestFromTab("foo"); + requestFromTab("bar"); + + assert.calledTwice(store.dispatch); + }); + it("should clean up when tabs close", () => { + assert.propertyVal(instance._repliedEarlyTabs, "size", 2); + instance.onAction(ac.AlsoToMain({ type: at.NEW_TAB_UNLOAD }, "foo")); + assert.propertyVal(instance._repliedEarlyTabs, "size", 1); + instance.onAction(ac.AlsoToMain({ type: at.NEW_TAB_UNLOAD }, "foo")); + assert.propertyVal(instance._repliedEarlyTabs, "size", 1); + instance.onAction(ac.AlsoToMain({ type: at.NEW_TAB_UNLOAD }, "bar")); + assert.propertyVal(instance._repliedEarlyTabs, "size", 0); + }); + }); + }); +}); |