text: const assert = require('assert');
  const { exec } = require('../../../setup');
  const { easeInOut, testAnimation, testNoAnimation, waitFor } = require('../../../helpers');
  
  describe('#after', function() {
  
      beforeEach(async function() {
          await exec(_ => {
              document.body.innerHTML =
                  '<div id="parent1">' +
                  '<span></span>' +
                  '<a href="#" class="test1">Test</a>' +
                  '<a href="#" class="test2">Test</a>' +
                  '</div>' +
                  '<div id="parent2">' +
                  '<span></span>' +
                  '<a href="#" class="test3">Test</a>' +
                  '<a href="#" class="test4">Test</a>' +
                  '</div>';
          });
      });
  
      it('inserts each other node after each node', async function() {
          assert.strictEqual(
              await exec(_ => {
                  dom.after('div', 'a');
                  return document.body.innerHTML;
              }),
              '<div id="parent1">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>' +
              '<div id="parent2">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>'
          );
      });
  
      it('preserves events for other nodes', async function() {
          assert.strictEqual(
              await exec(_ => {
                  let result = 0;
                  dom.addEvent('a', 'click', _ => {
                      result++;
                  });
                  dom.after('div', 'a');
                  dom.triggerEvent('a', 'click');
                  return result;
              }),
              8
          );
      });
  
      it('preserves data for other nodes', async function() {
          assert.deepStrictEqual(
              await exec(_ => {
                  dom.setData('a', 'test', 'Test');
                  dom.after('div', 'a');
                  return [...document.querySelectorAll('a')]
                      .map(node =>
                          dom.getData(node, 'test')
                      );
              }),
              [
                  'Test',
                  'Test',
                  'Test',
                  'Test',
                  'Test',
                  'Test',
                  'Test',
                  'Test'
              ]
          );
      });
  
      it('preserves animations for other nodes', async function() {
          await exec(_ => {
              dom.animate(
                  'a',
                  _ => { },
                  {
                      duration: 100,
                      debug: true
                  }
              );
              dom.after('div', 'a');
          }).then(waitFor(50)).then(async _ => {
              await testAnimation('body > a:nth-of-type(1)', easeInOut, 100);
              await testAnimation('body > a:nth-of-type(2)', easeInOut, 100);
              await testAnimation('body > a:nth-of-type(3)', easeInOut, 100);
              await testAnimation('body > a:nth-of-type(4)', easeInOut, 100);
              await testAnimation('body > a:nth-of-type(5)', easeInOut, 100);
              await testAnimation('body > a:nth-of-type(6)', easeInOut, 100);
              await testAnimation('body > a:nth-of-type(7)', easeInOut, 100);
              await testAnimation('body > a:nth-of-type(8)', easeInOut, 100);
          }).then(waitFor(100)).then(async _ => {
              await testNoAnimation('body > a:nth-of-type(1)');
              await testNoAnimation('body > a:nth-of-type(2)');
              await testNoAnimation('body > a:nth-of-type(3)');
              await testNoAnimation('body > a:nth-of-type(4)');
              await testNoAnimation('body > a:nth-of-type(5)');
              await testNoAnimation('body > a:nth-of-type(6)');
              await testNoAnimation('body > a:nth-of-type(7)');
              await testNoAnimation('body > a:nth-of-type(8)');
          });
      });
  
      it('does not clone for the last other nodes', async function() {
          assert.strictEqual(
              await exec(_ => {
                  const nodes = [...document.querySelectorAll('a')];
                  dom.after('div', 'a');
                  const newNodes = [...document.querySelectorAll('a')].slice(4);
                  return nodes.every((node, i) => node.isSameNode(newNodes[i]));
              }),
              true
          );
      });
  
      it('works with HTMLElement nodes', async function() {
          assert.strictEqual(
              await exec(_ => {
                  dom.after(
                      document.getElementById('parent1'),
                      'a'
                  );
                  return document.body.innerHTML;
              }),
              '<div id="parent1">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>' +
              '<div id="parent2">' +
              '<span></span>' +
              '</div>'
          );
      });
  
      it('works with NodeList nodes', async function() {
          assert.strictEqual(
              await exec(_ => {
                  dom.after(
                      document.querySelectorAll('div'),
                      'a'
                  );
                  return document.body.innerHTML;
              }),
              '<div id="parent1">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>' +
              '<div id="parent2">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>'
          );
      });
  
      it('works with HTMLCollection nodes', async function() {
          assert.strictEqual(
              await exec(_ => {
                  dom.after(
                      document.body.children,
                      'a'
                  );
                  return document.body.innerHTML;
              }),
              '<div id="parent1">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>' +
              '<div id="parent2">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>'
          );
      });
  
      it('works with array nodes', async function() {
          assert.strictEqual(
              await exec(_ => {
                  dom.after([
                      document.getElementById('parent1'),
                      document.getElementById('parent2')
                  ], 'a');
                  return document.body.innerHTML;
              }),
              '<div id="parent1">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>' +
              '<div id="parent2">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>'
          );
      });
  
      it('works with HTMLElement other nodes', async function() {
          assert.strictEqual(
              await exec(_ => {
                  dom.after(
                      'div',
                      document.querySelector('.test1')
                  );
                  return document.body.innerHTML;
              }),
              '<div id="parent1">' +
              '<span></span>' +
              '<a href="#" class="test2">Test</a>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<div id="parent2">' +
              '<span></span>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>'
          );
      });
  
      it('works with NodeList other nodes', async function() {
          assert.strictEqual(
              await exec(_ => {
                  dom.after(
                      'div',
                      document.querySelectorAll('a')
                  );
                  return document.body.innerHTML;
              }),
              '<div id="parent1">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>' +
              '<div id="parent2">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>'
          );
      });
  
      it('works with HTMLCollection other nodes', async function() {
          assert.strictEqual(
              await exec(_ => {
                  dom.after(
                      'div',
                      document.getElementById('parent1').children
                  );
                  return document.body.innerHTML;
              }),
              '<div id="parent1">' +
              '</div>' +
              '<span></span>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<div id="parent2">' +
              '<span></span>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>' +
              '</div>' +
              '<span></span>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>'
          );
      });
  
      it('works with DocumentFragment other nodes', async function() {
          assert.strictEqual(
              await exec(_ => {
                  const range = document.createRange();
                  const fragment = range.createContextualFragment(
                      '<div><span></span></div>'
                  );
                  dom.after('div', fragment);
                  return document.body.innerHTML;
              }),
              '<div id="parent1">' +
              '<span></span>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '</div>' +
              '<div><span></span></div>' +
              '<div id="parent2">' +
              '<span></span>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>' +
              '</div>' +
              '<div><span></span></div>'
          );
      });
  
      it('works with array other nodes', async function() {
          assert.strictEqual(
              await exec(_ => {
                  dom.after('div', [
                      document.querySelector('.test1'),
                      document.querySelector('.test2'),
                      document.querySelector('.test3'),
                      document.querySelector('.test4')
                  ]);
                  return document.body.innerHTML;
              }),
              '<div id="parent1">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>' +
              '<div id="parent2">' +
              '<span></span>' +
              '</div>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>'
          );
      });
  
      it('works with HTML other nodes', async function() {
          assert.strictEqual(
              await exec(_ => {
                  dom.after('div', '<div><span></span></div>');
                  return document.body.innerHTML;
              }),
              '<div id="parent1">' +
              '<span></span>' +
              '<a href="#" class="test1">Test</a>' +
              '<a href="#" class="test2">Test</a>' +
              '</div>' +
              '<div><span></span></div>' +
              '<div id="parent2">' +
              '<span></span>' +
              '<a href="#" class="test3">Test</a>' +
              '<a href="#" class="test4">Test</a>' +
              '</div>' +
              '<div><span></span></div>'
          );
      });
  
  });