TippyTopProvider.test.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {GlobalOverrider} from "test/unit/utils";
  2. import {TippyTopProvider} from "lib/TippyTopProvider.jsm";
  3. describe("TippyTopProvider", () => {
  4. let instance;
  5. let globals;
  6. beforeEach(async () => {
  7. globals = new GlobalOverrider();
  8. let fetchStub = globals.sandbox.stub();
  9. globals.set("fetch", fetchStub);
  10. fetchStub.resolves({
  11. ok: true,
  12. status: 200,
  13. json: () => Promise.resolve([{
  14. "title": "facebook",
  15. "url": "https://www.facebook.com/",
  16. "image_url": "facebook-com.png",
  17. "background_color": "#3b5998",
  18. "domain": "facebook.com",
  19. }, {
  20. "title": "gmail",
  21. "urls": ["https://www.gmail.com/", "https://mail.google.com"],
  22. "image_url": "gmail-com.png",
  23. "background_color": "#000000",
  24. "domain": "gmail.com",
  25. }]),
  26. });
  27. instance = new TippyTopProvider();
  28. await instance.init();
  29. });
  30. it("should provide an icon for facebook.com", () => {
  31. const site = instance.processSite({url: "https://facebook.com"});
  32. assert.equal(site.tippyTopIcon, "resource://activity-stream/data/content/tippytop/images/facebook-com.png");
  33. assert.equal(site.backgroundColor, "#3b5998");
  34. });
  35. it("should provide an icon for www.facebook.com", () => {
  36. const site = instance.processSite({url: "https://www.facebook.com"});
  37. assert.equal(site.tippyTopIcon, "resource://activity-stream/data/content/tippytop/images/facebook-com.png");
  38. assert.equal(site.backgroundColor, "#3b5998");
  39. });
  40. it("should provide an icon for facebook.com/foobar", () => {
  41. const site = instance.processSite({url: "https://facebook.com/foobar"});
  42. assert.equal(site.tippyTopIcon, "resource://activity-stream/data/content/tippytop/images/facebook-com.png");
  43. assert.equal(site.backgroundColor, "#3b5998");
  44. });
  45. it("should provide an icon for gmail.com", () => {
  46. const site = instance.processSite({url: "https://gmail.com"});
  47. assert.equal(site.tippyTopIcon, "resource://activity-stream/data/content/tippytop/images/gmail-com.png");
  48. assert.equal(site.backgroundColor, "#000000");
  49. });
  50. it("should provide an icon for mail.google.com", () => {
  51. const site = instance.processSite({url: "https://mail.google.com"});
  52. assert.equal(site.tippyTopIcon, "resource://activity-stream/data/content/tippytop/images/gmail-com.png");
  53. assert.equal(site.backgroundColor, "#000000");
  54. });
  55. it("should handle garbage URLs gracefully", () => {
  56. const site = instance.processSite({url: "garbagejlfkdsa"});
  57. assert.isUndefined(site.tippyTopIcon);
  58. assert.isUndefined(site.backgroundColor);
  59. });
  60. it("should handle error when fetching and parsing manifest", async () => {
  61. globals = new GlobalOverrider();
  62. let fetchStub = globals.sandbox.stub();
  63. globals.set("fetch", fetchStub);
  64. fetchStub.rejects("whaaaa");
  65. instance = new TippyTopProvider();
  66. await instance.init();
  67. instance.processSite({url: "https://facebook.com"});
  68. });
  69. });