var x = require('element')
  , test = require('prova')

  , placeholder = require('./placeholder')

test('empty element, focus & blur', function (t) {
  var empty = x('<p contenteditable data-placeholder="beep"></p>')
  document.body.appendChild(empty)

  placeholder(empty)

  t.ok(empty.classList.contains('placeholder'))

  empty.focus()

  t.notOk(empty.classList.contains('placeholder'))

  empty.blur()

  t.ok(empty.classList.contains('placeholder'))

  t.end()
})

test('element with text', function (t) {
  var text = x('<p contenteditable data-placeholder="boop">foo</p>')
  document.body.appendChild(text)

  placeholder(text)

  t.notOk(text.classList.contains('placeholder'))

  t.end()
})

test('element with child', function (t) {
  var withChild = x('<p contenteditable data-placeholder="bong"></p>')
  withChild.appendChild(x('<img src="http://placekitten.com/g/90/90"/>'))
  document.body.appendChild(withChild)

  placeholder(withChild)

  t.notOk(withChild.classList.contains('placeholder'))

  t.end()
})

test('element appending child', function (t) {
  var element = x('<p contenteditable data-placeholder="blip"></p>')
    , child = x('<img src="http://placekitten/g/90/90"/>')

  document.body.appendChild(element)

  placeholder(element)

  element.appendChild(child)

  // run in next tick so that the observer can run
  process.nextTick(function () {
    t.notOk(element.classList.contains('placeholder'))
    t.end()
  })
})

test('element setting innerHTML', function (t) {
  var element = x('<p contenteditable data-placeholder="blip"></p>')

  document.body.appendChild(element)

  placeholder(element)

  element.innerHTML = 'oh yeah'

  // run in next tick so that the observer can run
  process.nextTick(function () {
    t.notOk(element.classList.contains('placeholder'))
    t.end()
  })
})

test('element changing in focus', function (t) {
  var element = x('<p contenteditable data-placeholder="foo">content</p>')

  document.body.appendChild(element)

  placeholder(element)

  element.focus()

  element.innerHTML = ''

  process.nextTick(function () {
    t.notOk(element.classList.contains('placeholder'))
    t.end()
  })
})

@@ -151,20 +151,22 @@
 %0A  var e
-mpty
+lement
  = x('%3Cp
@@ -242,20 +242,22 @@
 dChild(e
-mpty
+lement
 )%0A%0A  pla
@@ -266,20 +266,22 @@
 holder(e
-mpty
+lement
 )%0A%0A  t.o
@@ -275,36 +275,38 @@
 ement)%0A%0A  t.ok(e
-mpty
+lement
 .classList.conta
@@ -329,20 +329,22 @@
 '))%0A%0A  e
-mpty
+lement
 .focus()
@@ -356,20 +356,22 @@
 .notOk(e
-mpty
+lement
 .classLi
@@ -402,20 +402,22 @@
 '))%0A%0A  e
-mpty
+lement
 .blur()%0A
@@ -425,20 +425,22 @@
   t.ok(e
-mpty
+lement
 .classLi
@@ -529,19 +529,22 @@
 %7B%0A  var 
-tex
+elemen
 t = x('%3C
@@ -623,19 +623,22 @@
 ndChild(
-tex
+elemen
 t)%0A%0A  pl
@@ -647,19 +647,22 @@
 eholder(
-tex
+elemen
 t)%0A%0A  t.
@@ -667,19 +667,22 @@
 t.notOk(
-tex
+elemen
 t.classL
@@ -773,25 +773,23 @@
 %7B%0A  var 
-withChild
+element
  = x('%3Cp
@@ -838,25 +838,23 @@
 /p%3E')%0A  
-withChild
+element
 .appendC
@@ -936,25 +936,23 @@
 ndChild(
-withChild
+element
 )%0A%0A  pla
@@ -960,25 +960,23 @@
 eholder(
-withChild
+element
 )%0A%0A  t.n
@@ -984,17 +984,15 @@
 tOk(
-withChild
+element
 .cla

test cleanup