Function.prototype.bind = Function.prototype.bind || require('function-bind');

var bespoke = require('bespoke');
var keys = require('bespoke-keys');
var forms = require('../../lib-instrumented/bespoke-forms.js');

require('simulant/simulant');

describe("bespoke-forms", function() {

  var

    parent, deck,

    createDeck = function(innerHTML) {
      return function() {
        parent = document.createElement('article');
        for (var i = 0; i < 2; i++) {
          parent.appendChild((function() {
            var el = document.createElement('section');
            el.innerHTML = innerHTML;
            return el;
          }()));
        }

        document.body.appendChild(parent);

        return (deck = bespoke.from(parent, [
          keys(),
          forms()
        ]));
      };
    },

    removeDeck = function() {
      document.body.removeChild(parent);
    },

    right = function(selector) {
      simulant.fire(deck.slides[0].querySelector(selector), 'keydown', {
        which: 39,
        bubbles: true
      });
    },

    isFirstSlideActive = function() {
      return deck.slides[0].classList.contains('bespoke-active');
    };

  describe("deck.slide", function() {

    describe("'input' element", function() {

      beforeEach(createDeck('<input type="text" />'));

      it("should not go to the next slide when pressing right arrow inside input", function() {
        right('input');
        expect(isFirstSlideActive()).toBe(true);
      });

    });

    describe("'select' element", function() {

      beforeEach(createDeck('<select><option>Hello World</option></select>'));

      it("should not go to the next slide when pressing right arrow inside select", function() {
        right('select');
        expect(isFirstSlideActive()).toBe(true);
      });

    });

    describe("'textarea' element", function() {

      beforeEach(createDeck('<textarea></textarea>'));

      it("should not go to the next slide when pressing right arrow inside textarea", function() {
        right('textarea');
        expect(isFirstSlideActive()).toBe(true);
      });

    });

    describe("'contenteditable' element", function() {

      beforeEach(createDeck('<div contenteditable="true"></div>'));

      it("should not go to the next slide when pressing right arrow inside an editable element", function() {
        right('[contenteditable]');
        expect(isFirstSlideActive()).toBe(true);
      });

    });

  });

});

@@ -1044,127 +1044,15 @@
 %7D);%0A
-    %7D,%0A%0A    isFirstSlideActive = function() %7B%0A      return deck.slides%5B0%5D.classList.contains('bespoke-active');%0A
     %7D;%0A
+
 %0A  d
@@ -1324,33 +1324,25 @@
  expect(
-isFirstSlideActiv
+deck.slid
 e()).toB
@@ -1335,36 +1335,33 @@
 k.slide()).toBe(
-true
+0
 );%0A      %7D);%0A%0A  
@@ -1631,33 +1631,25 @@
  expect(
-isFirstSlideActiv
+deck.slid
 e()).toB
@@ -1642,36 +1642,33 @@
 k.slide()).toBe(
-true
+0
 );%0A      %7D);%0A%0A  
@@ -1920,33 +1920,25 @@
  expect(
-isFirstSlideActiv
+deck.slid
 e()).toB
@@ -1931,36 +1931,33 @@
 k.slide()).toBe(
-true
+0
 );%0A      %7D);%0A%0A  
@@ -2253,25 +2253,17 @@
 ect(
-isFirstSlideActiv
+deck.slid
 e())
@@ -2268,20 +2268,17 @@
 )).toBe(
-true
+0
 );%0A     

Simplify tests