summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/node/store
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/client/framework/test/node/store
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/framework/test/node/store')
-rw-r--r--devtools/client/framework/test/node/store/targets.test.js142
1 files changed, 142 insertions, 0 deletions
diff --git a/devtools/client/framework/test/node/store/targets.test.js b/devtools/client/framework/test/node/store/targets.test.js
new file mode 100644
index 0000000000..5eb8d2b5ef
--- /dev/null
+++ b/devtools/client/framework/test/node/store/targets.test.js
@@ -0,0 +1,142 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Unit tests for targets management on the toolbox store.
+ */
+
+const createStore = require("resource://devtools/client/shared/redux/create-store.js");
+const reducer = require("resource://devtools/shared/commands/target/reducers/targets.js");
+const actions = require("resource://devtools/shared/commands/target/actions/targets.js");
+const {
+ getSelectedTarget,
+ getToolboxTargets,
+} = require("resource://devtools/shared/commands/target/selectors/targets.js");
+
+describe("Toolbox store - targets", () => {
+ describe("registerTarget", () => {
+ it("adds the target to the list", () => {
+ const store = createStore(reducer);
+
+ const targetFront1 = {
+ actorID: "target/1",
+ };
+
+ store.dispatch(actions.registerTarget(targetFront1));
+
+ let targets = getToolboxTargets(store.getState());
+ expect(targets.length).toEqual(1);
+ expect(targets[0].actorID).toEqual("target/1");
+
+ const targetFront2 = {
+ actorID: "target/2",
+ };
+
+ store.dispatch(actions.registerTarget(targetFront2));
+
+ targets = getToolboxTargets(store.getState());
+ expect(targets.length).toEqual(2);
+ expect(targets[0].actorID).toEqual("target/1");
+ expect(targets[1].actorID).toEqual("target/2");
+ });
+ });
+
+ describe("selectTarget", () => {
+ it("updates the selected property when the target is known", () => {
+ const store = createStore(reducer);
+ const targetFront1 = {
+ actorID: "target/1",
+ };
+ store.dispatch(actions.registerTarget(targetFront1));
+ store.dispatch(actions.selectTarget("target/1"));
+ expect(getSelectedTarget(store.getState()).actorID).toBe("target/1");
+ });
+
+ it("does not update the selected property when the target is unknown", () => {
+ const store = createStore(reducer);
+ const targetFront1 = {
+ actorID: "target/1",
+ };
+ store.dispatch(actions.registerTarget(targetFront1));
+ store.dispatch(actions.selectTarget("target/1"));
+ expect(getSelectedTarget(store.getState()).actorID).toBe("target/1");
+
+ store.dispatch(actions.selectTarget("target/unknown"));
+ expect(getSelectedTarget(store.getState()).actorID).toBe("target/1");
+ });
+
+ it("does not update the state when the target is already selected", () => {
+ const store = createStore(reducer);
+ const targetFront1 = {
+ actorID: "target/1",
+ };
+ store.dispatch(actions.registerTarget(targetFront1));
+ store.dispatch(actions.selectTarget("target/1"));
+
+ const state = store.getState();
+ store.dispatch(actions.selectTarget("target/1"));
+ expect(store.getState()).toStrictEqual(state);
+ });
+ });
+
+ describe("unregisterTarget", () => {
+ it("removes the target from the list", () => {
+ const store = createStore(reducer);
+
+ const targetFront1 = {
+ actorID: "target/1",
+ };
+ const targetFront2 = {
+ actorID: "target/2",
+ };
+
+ store.dispatch(actions.registerTarget(targetFront1));
+ store.dispatch(actions.registerTarget(targetFront2));
+
+ let targets = getToolboxTargets(store.getState());
+ expect(targets.length).toEqual(2);
+
+ store.dispatch(actions.unregisterTarget(targetFront1));
+ targets = getToolboxTargets(store.getState());
+ expect(targets.length).toEqual(1);
+ expect(targets[0].actorID).toEqual("target/2");
+
+ store.dispatch(actions.unregisterTarget(targetFront2));
+ expect(getToolboxTargets(store.getState()).length).toEqual(0);
+ });
+
+ it("does not update the state when the target is unknown", () => {
+ const store = createStore(reducer);
+
+ const targetFront1 = {
+ actorID: "target/1",
+ };
+ const targetFront2 = {
+ actorID: "target/unknown",
+ };
+
+ store.dispatch(actions.registerTarget(targetFront1));
+
+ const state = store.getState();
+ store.dispatch(actions.unregisterTarget(targetFront2));
+ expect(store.getState()).toStrictEqual(state);
+ });
+
+ it("resets the selected property when it was the selected target", () => {
+ const store = createStore(reducer);
+
+ const targetFront1 = {
+ actorID: "target/1",
+ };
+
+ store.dispatch(actions.registerTarget(targetFront1));
+ store.dispatch(actions.selectTarget("target/1"));
+ expect(getSelectedTarget(store.getState()).actorID).toBe("target/1");
+
+ store.dispatch(actions.unregisterTarget(targetFront1));
+ expect(getSelectedTarget(store.getState())).toBe(null);
+ });
+ });
+});