Bug 1503288 - Use 'args' in button_action params to fix busted simplified onboarding actions. r=k88hudson, a=RyanVM
authorUrsula Sarracini <ursulasarracini@gmail.com>
Tue, 30 Oct 2018 19:36:22 +0000
changeset 500957 6432de180d3c57360d0e9ddb9f8414dbaeb26745
parent 500956 cb358118e54de761923e4b29bee9d34c1560b98a
child 500958 6e4f5a616fe2a24e282ce7f23327d3f9ae17437d
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersk88hudson, RyanVM
bugs1503288
milestone64.0
Bug 1503288 - Use 'args' in button_action params to fix busted simplified onboarding actions. r=k88hudson, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D10232
browser/components/newtab/content-src/asrouter/templates/OnboardingMessage/OnboardingMessage.schema.json
browser/components/newtab/lib/OnboardingMessageProvider.jsm
browser/components/newtab/test/unit/asrouter/templates/OnboardingMessage.test.jsx
new file mode 100644
--- /dev/null
+++ b/browser/components/newtab/content-src/asrouter/templates/OnboardingMessage/OnboardingMessage.schema.json
@@ -0,0 +1,93 @@
+{
+  "title": "OnboardingMessage",
+  "description": "A template with a title, icon, button and description. No markup allowed.",
+  "version": "1.0.0",
+  "type": "object",
+  "properties": {
+    "title": {
+      "oneOf": [
+        {
+          "type": "string",
+          "description": "The message displayed in the title of the onboarding card"
+        },
+        {
+          "type": "object",
+          "properties": {
+            "string_id": {
+              "type": "string"
+            }
+          },
+          "required": ["string_id"],
+          "description": "Id of localized string for onboarding card title"
+        }
+      ],
+      "description": "Id of localized string or message override."
+    },
+    "text": {
+      "oneOf": [
+        {
+          "type": "string",
+          "description": "The message displayed in the description of the onboarding card"
+        },
+        {
+          "type": "object",
+          "properties": {
+            "string_id": {
+              "type": "string"
+            }
+          },
+          "required": ["string_id"],
+          "description": "Id of localized string for onboarding card description"
+        }
+      ],
+      "description": "Id of localized string or message override."
+    },
+    "icon": {
+      "allOf": [
+        {
+          "type": "string",
+          "description": "Image associated with the onboarding card"
+        }
+      ]
+    },
+    "button_label": {
+      "oneOf": [
+        {
+          "type": "string",
+          "description": "The label of the onboarding card's action button"
+        },
+        {
+          "type": "object",
+          "properties": {
+            "string_id": {
+              "type": "string"
+            }
+          },
+          "required": ["string_id"],
+          "description": "Id of localized string for onboarding card button"
+        }
+      ],
+      "description": "Id of localized string or message override."
+    },
+    "button_action": {
+      "type": "object",
+      "properties": {
+        "type": {
+          "type": "string",
+          "description": "Action dispatched by the button."
+        },
+        "data": {
+          "properties": {
+            "args": {
+              "type": "string",
+              "description": "Additional parameters for button action, for example which link the button should open."
+            }
+          }
+        }
+      }
+    }
+  },
+  "additionalProperties": false,
+  "required": ["title", "text", "icon", "button_label", "button_action"]
+}
+
--- a/browser/components/newtab/lib/OnboardingMessageProvider.jsm
+++ b/browser/components/newtab/lib/OnboardingMessageProvider.jsm
@@ -30,51 +30,51 @@ const ONBOARDING_MESSAGES = () => ([
     order: 3,
     content: {
       title: {string_id: "onboarding-screenshots-title"},
       text: {string_id: "onboarding-screenshots-text"},
       icon: "screenshots",
       button_label: {string_id: "onboarding-button-label-try-now"},
       button_action: {
         type: "OPEN_URL",
-        data: {url: "https://screenshots.firefox.com/#tour"},
+        data: {args: "https://screenshots.firefox.com/#tour"},
       },
     },
     trigger: {id: "firstRun"},
   },
   {
     id: "ONBOARDING_3",
     template: "onboarding",
     bundled: 3,
     order: 1,
     content: {
       title: {string_id: "onboarding-addons-title"},
       text: {string_id: "onboarding-addons-text"},
       icon: "addons",
       button_label: {string_id: "onboarding-button-label-try-now"},
       button_action: {
         type: "OPEN_ABOUT_PAGE",
-        data: {page: "addons"},
+        data: {args: "addons"},
       },
     },
     trigger: {id: "firstRun"},
   },
   {
     id: "ONBOARDING_4",
     template: "onboarding",
     bundled: 3,
     order: 1,
     content: {
       title: {string_id: "onboarding-ghostery-title"},
       text: {string_id: "onboarding-ghostery-text"},
       icon: "gift",
       button_label: {string_id: "onboarding-button-label-try-now"},
       button_action: {
         type: "OPEN_URL",
-        data: {url: "https://addons.mozilla.org/en-US/firefox/addon/ghostery/"},
+        data: {args: "https://addons.mozilla.org/en-US/firefox/addon/ghostery/"},
       },
     },
     targeting: "providerCohorts.onboarding == 'ghostery'",
     trigger: {id: "firstRun"},
   },
 ]);
 
 const OnboardingMessageProvider = {
@@ -84,16 +84,20 @@ const OnboardingMessageProvider = {
       {id: "onboarding-start-browsing-button-label"},
     ]);
     return {header: header.value, button_label: button_label.value};
   },
   async getMessages() {
     const messages = await this.translateMessages(ONBOARDING_MESSAGES());
     return messages;
   },
+  getUntranslatedMessages() {
+    // This is helpful for jsonSchema testing - since we are localizing in the provider
+    return ONBOARDING_MESSAGES();
+  },
   async translateMessages(messages) {
     let translatedMessages = [];
     for (const msg of messages) {
       let translatedMessage = msg;
       const [button_string, title_string, text_string] = await L10N.formatMessages([
         {id: msg.content.button_label.string_id},
         {id: msg.content.title.string_id},
         {id: msg.content.text.string_id},
new file mode 100644
--- /dev/null
+++ b/browser/components/newtab/test/unit/asrouter/templates/OnboardingMessage.test.jsx
@@ -0,0 +1,35 @@
+import {OnboardingMessageProvider} from "lib/OnboardingMessageProvider.jsm";
+import schema from "content-src/asrouter/templates/OnboardingMessage/OnboardingMessage.schema.json";
+
+const DEFAULT_CONTENT = {
+  "title": "A title",
+  "text": "A description",
+  "icon": "icon",
+  "button_label": "some_button_label",
+  "button_action": {
+    "type": "SOME_TYPE",
+    "data": {"args": "example.com"},
+  },
+};
+
+const L10N_CONTENT = {
+  "title": {string_id: "onboarding-private-browsing-title"},
+  "text": {string_id: "onboarding-private-browsing-text"},
+  "icon": "icon",
+  "button_label": {string_id: "onboarding-button-label-try-now"},
+  "button_action": {type: "SOME_TYPE"},
+};
+
+describe("OnboardingMessage", () => {
+  it("should validate DEFAULT_CONTENT", () => {
+    assert.jsonSchema(DEFAULT_CONTENT, schema);
+  });
+  it("should validate L10N_CONTENT", () => {
+    assert.jsonSchema(L10N_CONTENT, schema);
+  });
+  it("should validate all messages from OnboardingMessageProvider", () => {
+    const messages = OnboardingMessageProvider.getUntranslatedMessages();
+    messages.forEach(msg => assert.jsonSchema(msg.content, schema));
+  });
+});
+