import {test} from "tape";
import {default as nightmare} from "nightmare";

const url = "http://localhost:4000/test/browser/box.html";

test("automatically added <svg> element to page", (assert) => {
  const page = nightmare();
  page.goto(url).wait(500)
    .evaluate(() => document.getElementsByTagName("svg").length)
    .then((result) => {
      assert.equal(1, result);
      page.end(() => {
        assert.end();
      });
    });
});

test("created <text> container element", (assert) => {
  const page = nightmare();
  page.goto(url).wait(500)
    .evaluate(() => document.getElementsByTagName("text").length)
    .then((result) => {
      assert.equal(1, result);
      page.end(() => {
        assert.end();
      });
    });
});

test("created 2 <tspan> elements", (assert) => {
  const page = nightmare();
  page.goto(url).wait(500)
    .evaluate(() => document.getElementsByTagName("tspan").length)
    .then((result) => {
      assert.equal(2, result);
      page.end(() => {
        assert.end();
      });
    });
});

test("wrapped text correctly", (assert) => {
  const page = nightmare();
  page.goto(url).wait(500)
    .evaluate(() => {

      const tspans = document.getElementsByTagName("tspan");

      return tspans[0].textContent === "Hello D3plus, please wrap" &&
             tspans[1].textContent === "this sentence for me.";

    })
    .then((result) => {
      assert.equal(true, result);
      page.end(() => {
        assert.end();
      });
    });
});

@@ -233,35 +233,25 @@
 ge.goto(url)
-.wait(500)
 %0A
+
     .evaluat
@@ -521,34 +521,24 @@
 ge.goto(url)
-.wait(500)
 %0A    .evalua
@@ -804,34 +804,24 @@
 ge.goto(url)
-.wait(500)
 %0A    .evalua
@@ -1092,18 +1092,8 @@
 url)
-.wait(500)
 %0A   
@@ -1179,16 +1179,157 @@
 ;%0A%0A     
+ let ret = %22%22;%0A      tspans.forEach((line) =%3E %7B%0A        ret += line.textContent;%0A        ret += %22 - %22;%0A      %7D);%0A%0A      return ret;%0A%0A      //
  return 
@@ -1386,24 +1386,27 @@
 ap%22 &&%0A     
+ //
         tspa

test for test