Source code
Revision control
Copy as Markdown
Other Tools
import { GlobalOverrider } from "test/unit/utils";
import { TippyTopProvider } from "lib/TippyTopProvider.sys.mjs";
describe("TippyTopProvider", () => {
let instance;
let globals;
beforeEach(async () => {
globals = new GlobalOverrider();
let fetchStub = globals.sandbox.stub();
globals.set("fetch", fetchStub);
fetchStub.resolves({
ok: true,
status: 200,
json: () =>
Promise.resolve([
{
domains: ["facebook.com"],
image_url: "images/facebook-com.png",
favicon_url: "images/facebook-com.png",
background_color: "#3b5998",
},
{
domains: ["gmail.com", "mail.google.com"],
image_url: "images/gmail-com.png",
favicon_url: "images/gmail-com.png",
background_color: "#000000",
},
]),
});
instance = new TippyTopProvider();
await instance.init();
});
it("should provide an icon for facebook.com", () => {
assert.equal(
site.tippyTopIcon,
);
assert.equal(
site.smallFavicon,
);
assert.equal(site.backgroundColor, "#3b5998");
});
it("should provide an icon for www.facebook.com", () => {
assert.equal(
site.tippyTopIcon,
);
assert.equal(
site.smallFavicon,
);
assert.equal(site.backgroundColor, "#3b5998");
});
it("should not provide an icon for other.facebook.com", () => {
assert.isUndefined(site.tippyTopIcon);
});
it("should provide an icon for other.facebook.com with stripping", () => {
const site = instance.processSite(
"*"
);
assert.equal(
site.tippyTopIcon,
);
});
it("should provide an icon for facebook.com/foobar", () => {
assert.equal(
site.tippyTopIcon,
);
assert.equal(
site.smallFavicon,
);
assert.equal(site.backgroundColor, "#3b5998");
});
it("should provide an icon for gmail.com", () => {
assert.equal(
site.tippyTopIcon,
);
assert.equal(
site.smallFavicon,
);
assert.equal(site.backgroundColor, "#000000");
});
it("should provide an icon for mail.google.com", () => {
assert.equal(
site.tippyTopIcon,
);
assert.equal(
site.smallFavicon,
);
assert.equal(site.backgroundColor, "#000000");
});
it("should handle garbage URLs gracefully", () => {
const site = instance.processSite({ url: "garbagejlfkdsa" });
assert.isUndefined(site.tippyTopIcon);
assert.isUndefined(site.backgroundColor);
});
it("should handle error when fetching and parsing manifest", async () => {
globals = new GlobalOverrider();
let fetchStub = globals.sandbox.stub();
globals.set("fetch", fetchStub);
fetchStub.rejects("whaaaa");
instance = new TippyTopProvider();
await instance.init();
});
});