summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/reducers/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /devtools/client/debugger/src/reducers/tests
parentInitial commit. (diff)
downloadfirefox-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 'devtools/client/debugger/src/reducers/tests')
-rw-r--r--devtools/client/debugger/src/reducers/tests/breakpoints.spec.js73
-rw-r--r--devtools/client/debugger/src/reducers/tests/quick-open.spec.js59
-rw-r--r--devtools/client/debugger/src/reducers/tests/ui.spec.js30
3 files changed, 162 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/reducers/tests/breakpoints.spec.js b/devtools/client/debugger/src/reducers/tests/breakpoints.spec.js
new file mode 100644
index 0000000000..043c59dc5f
--- /dev/null
+++ b/devtools/client/debugger/src/reducers/tests/breakpoints.spec.js
@@ -0,0 +1,73 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
+
+import { initialBreakpointsState } from "../breakpoints";
+import { getBreakpointsForSource } from "../../selectors/breakpoints";
+
+import { makeMockBreakpoint, makeMockSource } from "../../utils/test-mockup";
+
+function initializeStateWith(data) {
+ const state = initialBreakpointsState();
+ state.breakpoints = data;
+ return state;
+}
+
+describe("Breakpoints Selectors", () => {
+ it("gets a breakpoint for an original source", () => {
+ const sourceId = "server1.conn1.child1/source1/originalSource";
+ const source = makeMockSource(undefined, sourceId);
+ const matchingBreakpoints = {
+ id1: makeMockBreakpoint(source, 1),
+ };
+
+ const otherBreakpoints = {
+ id2: makeMockBreakpoint(makeMockSource(undefined, "not-this-source"), 1),
+ };
+
+ const data = {
+ ...matchingBreakpoints,
+ ...otherBreakpoints,
+ };
+
+ const breakpoints = initializeStateWith(data);
+ const allBreakpoints = Object.values(matchingBreakpoints);
+ const sourceBreakpoints = getBreakpointsForSource({ breakpoints }, source);
+
+ expect(sourceBreakpoints).toEqual(allBreakpoints);
+ expect(sourceBreakpoints[0] === allBreakpoints[0]).toBe(true);
+ });
+
+ it("gets a breakpoint for a generated source", () => {
+ const generatedSourceId = "random-source";
+ const generatedSource = makeMockSource(undefined, generatedSourceId);
+ const matchingBreakpoints = {
+ id1: {
+ ...makeMockBreakpoint(generatedSource, 1),
+ location: { line: 1, source: { id: "original-source-id-1" } },
+ },
+ };
+
+ const otherBreakpoints = {
+ id2: {
+ ...makeMockBreakpoint(makeMockSource(undefined, "not-this-source"), 1),
+ location: { line: 1, source: { id: "original-source-id-2" } },
+ },
+ };
+
+ const data = {
+ ...matchingBreakpoints,
+ ...otherBreakpoints,
+ };
+
+ const breakpoints = initializeStateWith(data);
+
+ const allBreakpoints = Object.values(matchingBreakpoints);
+ const sourceBreakpoints = getBreakpointsForSource(
+ { breakpoints },
+ generatedSource
+ );
+
+ expect(sourceBreakpoints).toEqual(allBreakpoints);
+ });
+});
diff --git a/devtools/client/debugger/src/reducers/tests/quick-open.spec.js b/devtools/client/debugger/src/reducers/tests/quick-open.spec.js
new file mode 100644
index 0000000000..cd91b040be
--- /dev/null
+++ b/devtools/client/debugger/src/reducers/tests/quick-open.spec.js
@@ -0,0 +1,59 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
+
+import update, { initialQuickOpenState } from "../quick-open";
+import {
+ getQuickOpenEnabled,
+ getQuickOpenQuery,
+ getQuickOpenType,
+} from "../../selectors/quick-open";
+import {
+ setQuickOpenQuery,
+ openQuickOpen,
+ closeQuickOpen,
+} from "../../actions/quick-open";
+
+describe("quickOpen reducer", () => {
+ test("initial state", () => {
+ const state = update(undefined, { type: "FAKE" });
+ expect(getQuickOpenQuery({ quickOpen: state })).toEqual("");
+ expect(getQuickOpenType({ quickOpen: state })).toEqual("sources");
+ });
+
+ test("opens the quickOpen modal", () => {
+ const state = update(initialQuickOpenState(), openQuickOpen());
+ expect(getQuickOpenEnabled({ quickOpen: state })).toEqual(true);
+ });
+
+ test("closes the quickOpen modal", () => {
+ let state = update(initialQuickOpenState(), openQuickOpen());
+ expect(getQuickOpenEnabled({ quickOpen: state })).toEqual(true);
+ state = update(initialQuickOpenState(), closeQuickOpen());
+ expect(getQuickOpenEnabled({ quickOpen: state })).toEqual(false);
+ });
+
+ test("leaves query alone on open if not provided", () => {
+ const state = update(initialQuickOpenState(), openQuickOpen());
+ expect(getQuickOpenQuery({ quickOpen: state })).toEqual("");
+ expect(getQuickOpenType({ quickOpen: state })).toEqual("sources");
+ });
+
+ test("set query on open if provided", () => {
+ const state = update(initialQuickOpenState(), openQuickOpen("@"));
+ expect(getQuickOpenQuery({ quickOpen: state })).toEqual("@");
+ expect(getQuickOpenType({ quickOpen: state })).toEqual("functions");
+ });
+
+ test("clear query on close", () => {
+ const state = update(initialQuickOpenState(), closeQuickOpen());
+ expect(getQuickOpenQuery({ quickOpen: state })).toEqual("");
+ expect(getQuickOpenType({ quickOpen: state })).toEqual("sources");
+ });
+
+ test("sets the query to the provided string", () => {
+ const state = update(initialQuickOpenState(), setQuickOpenQuery("test"));
+ expect(getQuickOpenQuery({ quickOpen: state })).toEqual("test");
+ expect(getQuickOpenType({ quickOpen: state })).toEqual("sources");
+ });
+});
diff --git a/devtools/client/debugger/src/reducers/tests/ui.spec.js b/devtools/client/debugger/src/reducers/tests/ui.spec.js
new file mode 100644
index 0000000000..0be451429f
--- /dev/null
+++ b/devtools/client/debugger/src/reducers/tests/ui.spec.js
@@ -0,0 +1,30 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
+
+import { prefs } from "../../utils/prefs";
+import update, { initialUIState } from "../ui";
+
+describe("ui reducer", () => {
+ it("toggle framework grouping to false", () => {
+ const state = initialUIState();
+ const value = false;
+ const updatedState = update(state, {
+ type: "TOGGLE_FRAMEWORK_GROUPING",
+ value,
+ });
+ expect(updatedState.frameworkGroupingOn).toBe(value);
+ expect(prefs.frameworkGroupingOn).toBe(value);
+ });
+
+ it("toggle framework grouping to true", () => {
+ const state = initialUIState();
+ const value = true;
+ const updatedState = update(state, {
+ type: "TOGGLE_FRAMEWORK_GROUPING",
+ value,
+ });
+ expect(updatedState.frameworkGroupingOn).toBe(value);
+ expect(prefs.frameworkGroupingOn).toBe(value);
+ });
+});