CFRMessageProvider.test.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {CFRMessageProvider} from "lib/CFRMessageProvider.jsm";
  2. const messages = CFRMessageProvider.getMessages();
  3. const REGULAR_IDS = [
  4. "FACEBOOK_CONTAINER",
  5. "GOOGLE_TRANSLATE",
  6. "YOUTUBE_ENHANCE",
  7. // These are excluded for now.
  8. // "WIKIPEDIA_CONTEXT_MENU_SEARCH",
  9. // "REDDIT_ENHANCEMENT",
  10. ];
  11. describe("CFRMessageProvider", () => {
  12. it("should have a total of 4 messages", () => {
  13. assert.lengthOf(messages, 4);
  14. });
  15. it("should have one message each for the three regular addons", () => {
  16. for (const id of REGULAR_IDS) {
  17. const cohort3 = messages.find(msg => msg.id === `${id}_3`);
  18. assert.ok(cohort3, `contains three day cohort for ${id}`);
  19. assert.deepEqual(cohort3.frequency, {lifetime: 3}, "three day cohort has the right frequency cap");
  20. assert.notInclude(cohort3.targeting, `providerCohorts.cfr`);
  21. }
  22. });
  23. it("should always have xpinstallEnabled as targeting if it is an addon", () => {
  24. for (const message of messages) {
  25. // Ensure that the CFR messages that are recommending an addon have this targeting.
  26. // In the future when we can do targeting based on category, this test will change.
  27. // See bug 1494778 and 1497653
  28. if (message.id !== "PIN_TAB") {
  29. assert.include(message.targeting, `(xpinstallEnabled == true)`);
  30. }
  31. }
  32. });
  33. it("should restrict all messages to `en` locale for now (PIN TAB is handled separately)", () => {
  34. for (const message of messages.filter(m => m.id !== "PIN_TAB")) {
  35. assert.include(message.targeting, `localeLanguageCode == "en"`);
  36. }
  37. });
  38. it("should restrict locale for PIN_TAB message", () => {
  39. const pinTabMessage = messages.find(m => m.id === "PIN_TAB");
  40. // 6 en-* locales, fr and de
  41. assert.lengthOf(pinTabMessage.targeting.match(/en-|fr|de/g), 8);
  42. });
  43. it("should contain `www.` version of the hosts", () => {
  44. const pinTabMessage = messages.find(m => m.id === "PIN_TAB");
  45. assert.isTrue(pinTabMessage.trigger.params.filter(host => host.startsWith("www.")).length > 0);
  46. });
  47. });