summaryrefslogtreecommitdiffstats
path: root/browser/components/newtab/test/unit/asrouter/SnippetsTestMessageProvider.test.js
blob: fc8fbe15acbd5e38b7230f5f663de4b3e4005591 (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
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.sys.mjs";
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`
      );
    });
  });
});