import test from "ava"

import beautifyHTML from "../../../_utils/beautify-html"

import collection from "./fixtures/collection.js"
import store from "./fixtures/store.js"

import toHTML, { writeAllHTMLFiles } from "../index"

const expectedHTML = {
  "destination/index.html":
    require("./results/destination/index.html").default,
  "destination/test-url/index.html":
    require("./results/destination/test-url/index.html").default,
  "destination/test/index.html":
    require("./results/destination/test/index.html").default,
}

test("don't break if there is nothing to transform", async (t) => {
  toHTML({
    routes: require("./fixtures/routes-splat.js").default,
    collection: [],
  })
  .then((files) => {
    t.is(files.length, 0)
  })
  .catch((error) => {
    t.fail(error)
  })
})

test("writeAllHTMLFiles", (t) => {
  t.plan(3)

  return writeAllHTMLFiles({
    routes: require("./fixtures/routes.js").default,
    collection,
    store,
    assetsFiles: {
      js: [ "test.js" ],
      css: [ "test.css" ],
    },
    destination: "destination",
    baseUrl: { pathname: "/" },
    ghPages: true,
    setPageData: () => {},
    writeHTMLFile: (filename, html) => {
      if (!expectedHTML[filename]) {
        throw new Error(filename + " is missing in expectedHTML results")
      }

      t.deepEqual(
        beautifyHTML(html),
        expectedHTML[filename](),
      )
    },
    forgetPageData: () => {},
  }, true)
  .catch((error) => {
    t.fail(error)
  })
})

@@ -15,16 +15,44 @@
 om %22ava%22
+%0Aimport %7B join %7D from %22path%22
 %0A%0Aimport
@@ -273,16 +273,22 @@
 L = %7B%0A  
+%5Bjoin(
 %22destina
@@ -283,33 +283,36 @@
 oin(%22destination
-/
+%22, %22
 index.html%22:%0A   
@@ -298,32 +298,34 @@
 n%22, %22index.html%22
+)%5D
 :%0A    require(%22.
@@ -361,32 +361,38 @@
 ml%22).default,%0A  
+%5Bjoin(
 %22destination/tes
@@ -383,33 +383,36 @@
 %22destination
-/
+%22, %22
 test-url
 /index.html%22
@@ -391,33 +391,36 @@
 tion%22, %22test-url
-/
+%22, %22
 index.html%22:%0A   
@@ -406,32 +406,34 @@
 l%22, %22index.html%22
+)%5D
 :%0A    require(%22.
@@ -486,16 +486,22 @@
 ault,%0A  
+%5Bjoin(
 %22destina
@@ -496,38 +496,44 @@
 oin(%22destination
-/test/
+%22, %22test%22, %22
 index.html%22:%0A   
@@ -527,16 +527,18 @@
 ex.html%22
+)%5D
 :%0A    re

Fix new tests for route-to-urls for Windows