import htmlpage from "../htmlpage";
import { IllegalArgumentException } from "../../exceptions";

describe("htmlpage", () => {
  it("throws on missing context path", () => {
    expect(() => {
      htmlpage();
    }).toThrow(IllegalArgumentException);
  });

  it("throws on missing application", () => {
    expect(() => {
      htmlpage({ contextPath: "" });
    }).toThrow(IllegalArgumentException);
  });

  it("create an empty server htmlpage", () => {
    const page = htmlpage({ contextPath: "", html: "" });

    expect(page).toBe(`<!doctype html>
  <html >
    <head>
      <meta charset="utf-8" />
      
      {CSSASSETS:<link rel="stylesheet" type="text/css" href="/{FILE}" />:CSSASSETS}
    </head>
    <body class="nojs">
      <div id="application"></div>
      <div id="portal"></div>
      <script
        type="application/json"
        data-app-state="app-json"
        data-app-contextpath=""
        data-app-filepath="{FILEPATH}"
        data-app-nonce=""></script>
      {JSASSETS:<script src="/{FILE}"></script>:JSASSETS}
    </body>
  </html>`);
  });

  it("create a server htmlpage", () => {
    const page = htmlpage({
      contextPath: "/contextPath",
      html: "<div>app</div>",
      head: {
        htmlAttributes: 'lang="en"',
        description: [
          '<meta name="description" content="Test description" data-react-helmet="true">',
        ],
      },
      state: "{state: []}",
      UUID: "1234-5678-90",
    });

    expect(page).toBe(`<!doctype html>
  <html lang="en">
    <head>
      <meta charset="utf-8" />
      <meta name="description" content="Test description" data-react-helmet="true">
      {CSSASSETS:<link rel="stylesheet" type="text/css" href="/contextPath/{FILE}" />:CSSASSETS}
    </head>
    <body class="nojs">
      <div id="application"><div>app</div></div>
      <div id="portal"></div>
      <script
        type="application/json"
        data-app-state="app-json"
        data-app-contextpath="/contextPath"
        data-app-filepath="{FILEPATH}"
        data-app-nonce="1234-5678-90">{state: []}</script>
      {JSASSETS:<script src="/contextPath/{FILE}"></script>:JSASSETS}
    </body>
  </html>`);
  });
});
