gecko-dev/browser/components/newtab/test/unit/asrouter/SnippetsTestMessageProvider.test.js
Bernard Igiri 24f9294ade Bug 1614465 - Replacing ASRouter calls to MessageChannel with JSWindowActors to eliminate ASRouterFeed r=k88hudson
Patch by Bernard Igiri <bigiri@mozilla.com>

Replacing async events with async method calls that use JSWindowActors to communicate with the parent process.
This will simplify these calls, bring the relevant code into local scope, and eliminate the need for MessageChannel.
Eliminating the MessageChannel dependency allows us to move the ASRouter initialization out of ASRouterFeed and into
JSWindowActors.

Differential Revision: https://phabricator.services.mozilla.com/D71796
2020-10-21 20:04:13 +00:00

43 lines
1.8 KiB
JavaScript

import EOYSnippetSchema from "../../../content-src/asrouter/templates/EOYSnippet/EOYSnippet.schema.json";
import SimpleBelowSearchSnippetSchema from "../../../content-src/asrouter/templates/SimpleBelowSearchSnippet/SimpleBelowSearchSnippet.schema.json";
import SimpleSnippetSchema from "../../../content-src/asrouter/templates/SimpleSnippet/SimpleSnippet.schema.json";
import { SnippetsTestMessageProvider } from "../../../lib/SnippetsTestMessageProvider.jsm";
import SubmitFormSnippetSchema from "../../../content-src/asrouter/templates/SubmitFormSnippet/SubmitFormSnippet.schema.json";
import SubmitFormScene2SnippetSchema from "../../../content-src/asrouter/templates/SubmitFormSnippet/SubmitFormScene2Snippet.schema.json";
const schemas = {
simple_snippet: SimpleSnippetSchema,
newsletter_snippet: SubmitFormSnippetSchema,
fxa_signup_snippet: SubmitFormSnippetSchema,
send_to_device_snippet: SubmitFormSnippetSchema,
send_to_device_scene2_snippet: SubmitFormScene2SnippetSchema,
eoy_snippet: EOYSnippetSchema,
simple_below_search_snippet: SimpleBelowSearchSnippetSchema,
};
describe("SnippetsTestMessageProvider", async () => {
let messages = await SnippetsTestMessageProvider.getMessages();
it("should return an array of messages", () => {
assert.isArray(messages);
});
it("should have a valid example of each schema", () => {
Object.keys(schemas).forEach(templateName => {
const example = messages.find(
message => message.template === templateName
);
assert.ok(example, `has a ${templateName} example`);
});
});
it("should have examples that are valid", () => {
messages.forEach(example => {
assert.jsonSchema(
example.content,
schemas[example.template],
`${example.id} should be valid`
);
});
});
});