summaryrefslogtreecommitdiffstats
path: root/browser/components/asrouter/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/asrouter/tests/unit')
-rw-r--r--browser/components/asrouter/tests/unit/ASRouterChild.test.js11
-rw-r--r--browser/components/asrouter/tests/unit/ASRouterTargeting.test.js4
-rw-r--r--browser/components/asrouter/tests/unit/CFRPageActions.test.js6
-rw-r--r--browser/components/asrouter/tests/unit/ModalOverlay.test.jsx69
-rw-r--r--browser/components/asrouter/tests/unit/TargetingDocs.test.js2
-rw-r--r--browser/components/asrouter/tests/unit/ToolbarPanelHub.test.js18
-rw-r--r--browser/components/asrouter/tests/unit/asrouter-utils.test.js36
-rw-r--r--browser/components/asrouter/tests/unit/unit-entry.js14
8 files changed, 35 insertions, 125 deletions
diff --git a/browser/components/asrouter/tests/unit/ASRouterChild.test.js b/browser/components/asrouter/tests/unit/ASRouterChild.test.js
index 41fdd79ea2..b73e56d510 100644
--- a/browser/components/asrouter/tests/unit/ASRouterChild.test.js
+++ b/browser/components/asrouter/tests/unit/ASRouterChild.test.js
@@ -1,22 +1,12 @@
/*eslint max-nested-callbacks: ["error", 10]*/
import { ASRouterChild } from "actors/ASRouterChild.sys.mjs";
import { MESSAGE_TYPE_HASH as msg } from "modules/ActorConstants.sys.mjs";
-import { GlobalOverrider } from "test/unit/utils";
describe("ASRouterChild", () => {
let asRouterChild = null;
- let globals = null;
- let overrider = null;
let sandbox = null;
beforeEach(() => {
sandbox = sinon.createSandbox();
- globals = {
- Cu: {
- cloneInto: sandbox.stub().returns(Promise.resolve()),
- },
- };
- overrider = new GlobalOverrider();
- overrider.set(globals);
asRouterChild = new ASRouterChild();
asRouterChild.telemetry = {
sendTelemetry: sandbox.stub(),
@@ -26,7 +16,6 @@ describe("ASRouterChild", () => {
});
afterEach(() => {
sandbox.restore();
- overrider.restore();
asRouterChild = null;
});
describe("asRouterMessage", () => {
diff --git a/browser/components/asrouter/tests/unit/ASRouterTargeting.test.js b/browser/components/asrouter/tests/unit/ASRouterTargeting.test.js
index 610b488b47..392fa59aed 100644
--- a/browser/components/asrouter/tests/unit/ASRouterTargeting.test.js
+++ b/browser/components/asrouter/tests/unit/ASRouterTargeting.test.js
@@ -32,11 +32,11 @@ describe("#CachedTargetingGetter", () => {
globals.set(
"TargetingContext",
class {
- static combineContexts(...args) {
+ static combineContexts() {
return sinon.stub();
}
- evalWithDefault(expr) {
+ evalWithDefault() {
return sinon.stub();
}
}
diff --git a/browser/components/asrouter/tests/unit/CFRPageActions.test.js b/browser/components/asrouter/tests/unit/CFRPageActions.test.js
index 31970eb43a..92dfa43d92 100644
--- a/browser/components/asrouter/tests/unit/CFRPageActions.test.js
+++ b/browser/components/asrouter/tests/unit/CFRPageActions.test.js
@@ -554,7 +554,7 @@ describe("CFRPageActions", () => {
);
const htmlFooterEl = fakeRemoteL10n.createElement.args.find(
/* eslint-disable-next-line max-nested-callbacks */
- ([doc, el, args]) =>
+ ([, , args]) =>
args && args.content === fakeRecommendation.content.text
);
assert.ok(htmlFooterEl);
@@ -849,7 +849,7 @@ describe("CFRPageActions", () => {
);
const [, , headerElementArgs] = fakeRemoteL10n.createElement.args.find(
/* eslint-disable-next-line max-nested-callbacks */
- ([doc, el, args]) => args && args.content && args.attributes
+ ([, , args]) => args && args.content && args.attributes
);
assert.equal(
headerElementArgs.content.string_id,
@@ -872,7 +872,7 @@ describe("CFRPageActions", () => {
);
const [, , headerElementArgs] = fakeRemoteL10n.createElement.args.find(
/* eslint-disable-next-line max-nested-callbacks */
- ([doc, el, args]) => args && args.content && args.attributes
+ ([, , args]) => args && args.content && args.attributes
);
assert.equal(
headerElementArgs.content.string_id,
diff --git a/browser/components/asrouter/tests/unit/ModalOverlay.test.jsx b/browser/components/asrouter/tests/unit/ModalOverlay.test.jsx
deleted file mode 100644
index 2320e16fc3..0000000000
--- a/browser/components/asrouter/tests/unit/ModalOverlay.test.jsx
+++ /dev/null
@@ -1,69 +0,0 @@
-import { ModalOverlayWrapper } from "content-src/components/ModalOverlay/ModalOverlay";
-import { mount } from "enzyme";
-import React from "react";
-
-describe("ModalOverlayWrapper", () => {
- let fakeDoc;
- let sandbox;
- let header;
- beforeEach(() => {
- sandbox = sinon.createSandbox();
- header = document.createElement("div");
-
- fakeDoc = {
- addEventListener: sandbox.stub(),
- removeEventListener: sandbox.stub(),
- body: { classList: { add: sandbox.stub(), remove: sandbox.stub() } },
- getElementById() {
- return header;
- },
- };
- });
- afterEach(() => {
- sandbox.restore();
- });
- it("should add eventListener and a class on mount", async () => {
- mount(<ModalOverlayWrapper document={fakeDoc} />);
- assert.calledOnce(fakeDoc.addEventListener);
- assert.calledWith(fakeDoc.body.classList.add, "modal-open");
- });
-
- it("should remove eventListener on unmount", async () => {
- const wrapper = mount(<ModalOverlayWrapper document={fakeDoc} />);
- wrapper.unmount();
- assert.calledOnce(fakeDoc.addEventListener);
- assert.calledOnce(fakeDoc.removeEventListener);
- assert.calledWith(fakeDoc.body.classList.remove, "modal-open");
- });
-
- it("should call props.onClose on an Escape key", async () => {
- const onClose = sandbox.stub();
- mount(<ModalOverlayWrapper document={fakeDoc} onClose={onClose} />);
-
- // Simulate onkeydown being called
- const [, callback] = fakeDoc.addEventListener.firstCall.args;
- callback({ key: "Escape" });
-
- assert.calledOnce(onClose);
- });
-
- it("should not call props.onClose on other keys than Escape", async () => {
- const onClose = sandbox.stub();
- mount(<ModalOverlayWrapper document={fakeDoc} onClose={onClose} />);
-
- // Simulate onkeydown being called
- const [, callback] = fakeDoc.addEventListener.firstCall.args;
- callback({ key: "Ctrl" });
-
- assert.notCalled(onClose);
- });
-
- it("should not call props.onClose when clicked outside dialog", async () => {
- const onClose = sandbox.stub();
- const wrapper = mount(
- <ModalOverlayWrapper document={fakeDoc} onClose={onClose} />
- );
- wrapper.find("div.modalOverlayOuter.active").simulate("click");
- assert.notCalled(onClose);
- });
-});
diff --git a/browser/components/asrouter/tests/unit/TargetingDocs.test.js b/browser/components/asrouter/tests/unit/TargetingDocs.test.js
index d00f971453..536049e64b 100644
--- a/browser/components/asrouter/tests/unit/TargetingDocs.test.js
+++ b/browser/components/asrouter/tests/unit/TargetingDocs.test.js
@@ -50,7 +50,7 @@ describe("ASRTargeting docs", () => {
describe("All targeting params documented in targeting-attributes.md", () => {
for (const targetingParam of ASRTargetingAttributes) {
- // If this test is failing, you probably forgot to add docs to content-src/asrouter/targeting-attributes.md
+ // If this test is failing, you probably forgot to add docs to asrouter/docs/targeting-attributes.md
// for a new targeting attribute, or you forgot to put it in the table of contents up top.
it(`should have docs and table of contents entry for ${targetingParam}`, () => {
assert.include(
diff --git a/browser/components/asrouter/tests/unit/ToolbarPanelHub.test.js b/browser/components/asrouter/tests/unit/ToolbarPanelHub.test.js
index 64cb8243b7..1755f62308 100644
--- a/browser/components/asrouter/tests/unit/ToolbarPanelHub.test.js
+++ b/browser/components/asrouter/tests/unit/ToolbarPanelHub.test.js
@@ -392,14 +392,13 @@ describe("ToolbarPanelHub", () => {
for (let message of messages) {
assert.ok(
fakeRemoteL10n.createElement.args.find(
- ([doc, el, args]) =>
- args && args.classList === "whatsNew-message-title"
+ ([, , args]) => args && args.classList === "whatsNew-message-title"
)
);
if (message.content.layout === "tracking-protections") {
assert.ok(
fakeRemoteL10n.createElement.args.find(
- ([doc, el, args]) =>
+ ([, , args]) =>
args && args.classList === "whatsNew-message-subtitle"
)
);
@@ -407,13 +406,13 @@ describe("ToolbarPanelHub", () => {
if (message.id === "WHATS_NEW_FINGERPRINTER_COUNTER_72") {
assert.ok(
fakeRemoteL10n.createElement.args.find(
- ([doc, el, args]) => el === "h2" && args.content === 3
+ ([, el, args]) => el === "h2" && args.content === 3
)
);
}
assert.ok(
fakeRemoteL10n.createElement.args.find(
- ([doc, el, args]) =>
+ ([, , args]) =>
args && args.classList === "whatsNew-message-content"
)
);
@@ -456,10 +455,9 @@ describe("ToolbarPanelHub", () => {
// value as the `order` field of the message
const titleEls = fakeRemoteL10n.createElement.args
.filter(
- ([doc, el, args]) =>
- args && args.classList === "whatsNew-message-title"
+ ([, , args]) => args && args.classList === "whatsNew-message-title"
)
- .map(([doc, el, args]) => args.content);
+ .map(([, , args]) => args.content);
assert.deepEqual(titleEls, [1, 2, 3]);
});
it("should accept string for image attributes", async () => {
@@ -488,7 +486,7 @@ describe("ToolbarPanelHub", () => {
await instance.renderMessages(fakeWindow, fakeDocument, "container-id");
const [, , args] = fakeRemoteL10n.createElement.args.find(
- ([doc, el, elArgs]) => elArgs && elArgs.attributes
+ ([, , elArgs]) => elArgs && elArgs.attributes
);
assert.ok(args);
// Currently this.state.contentArguments has 8 different entries
@@ -510,7 +508,7 @@ describe("ToolbarPanelHub", () => {
await instance.renderMessages(fakeWindow, fakeDocument, "container-id");
const dateElements = fakeRemoteL10n.createElement.args.filter(
- ([doc, el, args]) =>
+ ([, el, args]) =>
el === "p" && args.classList === "whatsNew-message-date"
);
assert.lengthOf(dateElements, uniqueDates.length);
diff --git a/browser/components/asrouter/tests/unit/asrouter-utils.test.js b/browser/components/asrouter/tests/unit/asrouter-utils.test.js
index 553c9608ed..81252b4d50 100644
--- a/browser/components/asrouter/tests/unit/asrouter-utils.test.js
+++ b/browser/components/asrouter/tests/unit/asrouter-utils.test.js
@@ -1,30 +1,22 @@
-import { ASRouterUtils } from "content-src/asrouter-utils";
-import { GlobalOverrider } from "test/unit/utils";
+import { ASRouterUtils } from "../../content-src/asrouter-utils.mjs";
describe("ASRouterUtils", () => {
- let globals = null;
- let overrider = null;
let sandbox = null;
beforeEach(() => {
sandbox = sinon.createSandbox();
- globals = {
- ASRouterMessage: sandbox.stub().resolves({}),
- };
- overrider = new GlobalOverrider();
- overrider.set(globals);
+ globalThis.ASRouterMessage = sandbox.stub().resolves({});
});
afterEach(() => {
sandbox.restore();
- overrider.restore();
});
describe("sendMessage", () => {
it("default", () => {
ASRouterUtils.sendMessage({ foo: "bar" });
- assert.calledOnce(globals.ASRouterMessage);
- assert.calledWith(globals.ASRouterMessage, { foo: "bar" });
+ assert.calledOnce(globalThis.ASRouterMessage);
+ assert.calledWith(globalThis.ASRouterMessage, { foo: "bar" });
});
it("throws if ASRouterMessage is not defined", () => {
- overrider.set("ASRouterMessage", undefined);
+ globalThis.ASRouterMessage = null;
assert.throws(() => ASRouterUtils.sendMessage({ foo: "bar" }));
});
it("can accept the legacy NEWTAB_MESSAGE_REQUEST message without throwing", async () => {
@@ -41,7 +33,7 @@ describe("ASRouterUtils", () => {
it("default", () => {
ASRouterUtils.blockById(1, { foo: "bar" });
assert.calledWith(
- globals.ASRouterMessage,
+ globalThis.ASRouterMessage,
sinon.match({ data: { foo: "bar", id: 1 } })
);
});
@@ -50,7 +42,7 @@ describe("ASRouterUtils", () => {
it("default", () => {
ASRouterUtils.modifyMessageJson({ foo: "bar" });
assert.calledWith(
- globals.ASRouterMessage,
+ globalThis.ASRouterMessage,
sinon.match({ data: { content: { foo: "bar" } } })
);
});
@@ -59,7 +51,7 @@ describe("ASRouterUtils", () => {
it("default", () => {
ASRouterUtils.executeAction({ foo: "bar" });
assert.calledWith(
- globals.ASRouterMessage,
+ globalThis.ASRouterMessage,
sinon.match({ data: { foo: "bar" } })
);
});
@@ -68,7 +60,7 @@ describe("ASRouterUtils", () => {
it("default", () => {
ASRouterUtils.unblockById(2);
assert.calledWith(
- globals.ASRouterMessage,
+ globalThis.ASRouterMessage,
sinon.match({ data: { id: 2 } })
);
});
@@ -77,7 +69,7 @@ describe("ASRouterUtils", () => {
it("default", () => {
ASRouterUtils.blockBundle(2);
assert.calledWith(
- globals.ASRouterMessage,
+ globalThis.ASRouterMessage,
sinon.match({ data: { bundle: 2 } })
);
});
@@ -86,7 +78,7 @@ describe("ASRouterUtils", () => {
it("default", () => {
ASRouterUtils.unblockBundle(2);
assert.calledWith(
- globals.ASRouterMessage,
+ globalThis.ASRouterMessage,
sinon.match({ data: { bundle: 2 } })
);
});
@@ -95,7 +87,7 @@ describe("ASRouterUtils", () => {
it("default", () => {
ASRouterUtils.overrideMessage(12);
assert.calledWith(
- globals.ASRouterMessage,
+ globalThis.ASRouterMessage,
sinon.match({ data: { id: 12 } })
);
});
@@ -104,7 +96,7 @@ describe("ASRouterUtils", () => {
it("default", () => {
ASRouterUtils.editState("foo", "bar");
assert.calledWith(
- globals.ASRouterMessage,
+ globalThis.ASRouterMessage,
sinon.match({ data: { foo: "bar" } })
);
});
@@ -112,7 +104,7 @@ describe("ASRouterUtils", () => {
describe("sendTelemetry", () => {
it("default", () => {
ASRouterUtils.sendTelemetry({ foo: "bar" });
- assert.calledOnce(globals.ASRouterMessage);
+ assert.calledOnce(globalThis.ASRouterMessage);
});
});
});
diff --git a/browser/components/asrouter/tests/unit/unit-entry.js b/browser/components/asrouter/tests/unit/unit-entry.js
index b8b799e051..f2046a81cb 100644
--- a/browser/components/asrouter/tests/unit/unit-entry.js
+++ b/browser/components/asrouter/tests/unit/unit-entry.js
@@ -105,8 +105,8 @@ const TEST_GLOBAL = {
JSWindowActorParent,
JSWindowActorChild,
AboutReaderParent: {
- addMessageListener: (messageName, listener) => {},
- removeMessageListener: (messageName, listener) => {},
+ addMessageListener: (_messageName, _listener) => {},
+ removeMessageListener: (_messageName, _listener) => {},
},
AboutWelcomeTelemetry: class {
submitGleanPingForPing() {}
@@ -289,8 +289,8 @@ const TEST_GLOBAL = {
},
dump() {},
EveryWindow: {
- registerCallback: (id, init, uninit) => {},
- unregisterCallback: id => {},
+ registerCallback: (_id, _init, _uninit) => {},
+ unregisterCallback: _id => {},
},
setTimeout: window.setTimeout.bind(window),
clearTimeout: window.clearTimeout.bind(window),
@@ -410,7 +410,7 @@ const TEST_GLOBAL = {
},
urlFormatter: { formatURL: str => str, formatURLPref: str => str },
mm: {
- addMessageListener: (msg, cb) => this.receiveMessage(),
+ addMessageListener: (_msg, _cb) => this.receiveMessage(),
removeMessageListener() {},
},
obs: {
@@ -420,7 +420,7 @@ const TEST_GLOBAL = {
},
telemetry: {
setEventRecordingEnabled: () => {},
- recordEvent: eventDetails => {},
+ recordEvent: _eventDetails => {},
scalarSet: () => {},
keyedScalarAdd: () => {},
},
@@ -578,7 +578,7 @@ const TEST_GLOBAL = {
finish: () => {},
},
Sampling: {
- ratioSample(seed, ratios) {
+ ratioSample(_seed, _ratios) {
return Promise.resolve(0);
},
},