summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/unit/asrouter/templates/ExtensionDoorhanger.test.jsx
blob: bef14c6982993abde5f585dd97a75b61a3a9d0c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { CFRMessageProvider } from "lib/CFRMessageProvider.sys.mjs";
import CFRDoorhangerSchema from "content-src/asrouter/templates/CFR/templates/ExtensionDoorhanger.schema.json";
import CFRChicletSchema from "content-src/asrouter/templates/CFR/templates/CFRUrlbarChiclet.schema.json";
import InfoBarSchema from "content-src/asrouter/templates/CFR/templates/InfoBar.schema.json";

const SCHEMAS = {
  cfr_urlbar_chiclet: CFRChicletSchema,
  cfr_doorhanger: CFRDoorhangerSchema,
  milestone_message: CFRDoorhangerSchema,
  infobar: InfoBarSchema,
};

const DEFAULT_CONTENT = {
  layout: "addon_recommendation",
  category: "dummyCategory",
  bucket_id: "some_bucket_id",
  notification_text: "Recommendation",
  heading_text: "Recommended Extension",
  info_icon: {
    label: { attributes: { tooltiptext: "Why am I seeing this" } },
    sumo_path: "extensionrecommendations",
  },
  addon: {
    id: "1234",
    title: "Addon name",
    icon: "https://mozilla.org/icon",
    author: "Author name",
    amo_url: "https://example.com",
  },
  text: "Description of addon",
  buttons: {
    primary: {
      label: {
        value: "Add Now",
        attributes: { accesskey: "A" },
      },
      action: {
        type: "INSTALL_ADDON_FROM_URL",
        data: { url: "https://example.com" },
      },
    },
    secondary: [
      {
        label: {
          value: "Not Now",
          attributes: { accesskey: "N" },
        },
        action: { type: "CANCEL" },
      },
    ],
  },
};

const L10N_CONTENT = {
  layout: "addon_recommendation",
  category: "dummyL10NCategory",
  bucket_id: "some_bucket_id",
  notification_text: { string_id: "notification_text_id" },
  heading_text: { string_id: "heading_text_id" },
  info_icon: {
    label: { string_id: "why_seeing_this" },
    sumo_path: "extensionrecommendations",
  },
  addon: {
    id: "1234",
    title: "Addon name",
    icon: "https://mozilla.org/icon",
    author: "Author name",
    amo_url: "https://example.com",
  },
  text: { string_id: "text_id" },
  buttons: {
    primary: {
      label: { string_id: "btn_ok_id" },
      action: {
        type: "INSTALL_ADDON_FROM_URL",
        data: { url: "https://example.com" },
      },
    },
    secondary: [
      {
        label: { string_id: "btn_cancel_id" },
        action: { type: "CANCEL" },
      },
    ],
  },
};

describe("ExtensionDoorhanger", () => {
  it("should validate DEFAULT_CONTENT", async () => {
    const messages = await CFRMessageProvider.getMessages();
    let doorhangerMessage = messages.find(m => m.id === "FACEBOOK_CONTAINER_3");
    assert.ok(doorhangerMessage, "Message found");
    assert.jsonSchema(
      { ...doorhangerMessage, content: DEFAULT_CONTENT },
      CFRDoorhangerSchema
    );
  });
  it("should validate L10N_CONTENT", async () => {
    const messages = await CFRMessageProvider.getMessages();
    let doorhangerMessage = messages.find(m => m.id === "FACEBOOK_CONTAINER_3");
    assert.ok(doorhangerMessage, "Message found");
    assert.jsonSchema(
      { ...doorhangerMessage, content: L10N_CONTENT },
      CFRDoorhangerSchema
    );
  });
  it("should validate all messages from CFRMessageProvider", async () => {
    const messages = await CFRMessageProvider.getMessages();
    messages.forEach(msg => assert.jsonSchema(msg, SCHEMAS[msg.template]));
  });
});