import assert from 'power-assert'
import Vue from 'vue'


describe('validator element directive', () => {
  let vm, el

  beforeEach(() => {
    el = document.createElement('div')
  })


  describe('normal', () => {
    beforeEach(() => {
      vm = new Vue({
        el: el,
        template: '<validator name="validator1"></validator>'
      })
    })

    it('validator scope should be assigned', () => {
      assert(vm.$validator1 !== undefined)
      assert(vm.$validator1.valid !== undefined)
      assert(vm.$validator1.invalid !== undefined)
      assert(vm.$validator1.touched !== undefined)
      assert(vm.$validator1.untouched !== undefined)
      assert(vm.$validator1.modified !== undefined)
      assert(vm.$validator1.dirty !== undefined)
      assert(vm.$validator1.pristine !== undefined)
    })
  })


  describe('invalid warn', () => {
    context.skip('not specify name attribute', () => {
      // TODO:
    })
    context.skip('not exist validator map object in vm instance', () => {
      // TODO:
    })
  })


  describe('groups attribute', () => {
    context('plain string', () => {
      beforeEach(() => {
        vm = new Vue({
          el: el,
          template: '<validator name="validator1" :groups="\'group1\'"></validator>'
        })
      })

      it('validator group scope should be assigned', () => {
        assert(vm.$validator1.group1 !== undefined)
        assert(vm.$validator1.group1.valid !== undefined)
        assert(vm.$validator1.group1.invalid !== undefined)
        assert(vm.$validator1.group1.touched !== undefined)
        assert(vm.$validator1.group1.untouched !== undefined)
        assert(vm.$validator1.group1.modified !== undefined)
        assert(vm.$validator1.group1.dirty !== undefined)
        assert(vm.$validator1.group1.pristine !== undefined)
      })
    })

    context('array', () => {
      beforeEach(() => {
        vm = new Vue({
          el: el,
          data: { group: 'group2' },
          template: '<validator name="validator1" :groups="[\'group1\', group]"></validator>'
        })
      })

      it('validator group scope should be assigned', () => {
        assert(vm.$validator1.group1 !== undefined)
        assert(vm.$validator1.group1.valid !== undefined)
        assert(vm.$validator1.group1.invalid !== undefined)
        assert(vm.$validator1.group1.touched !== undefined)
        assert(vm.$validator1.group1.untouched !== undefined)
        assert(vm.$validator1.group1.modified !== undefined)
        assert(vm.$validator1.group1.dirty !== undefined)
        assert(vm.$validator1.group1.pristine !== undefined)
        assert(vm.$validator1.group2 !== undefined)
        assert(vm.$validator1.group2.valid !== undefined)
        assert(vm.$validator1.group2.invalid !== undefined)
        assert(vm.$validator1.group2.touched !== undefined)
        assert(vm.$validator1.group2.untouched !== undefined)
        assert(vm.$validator1.group2.modified !== undefined)
        assert(vm.$validator1.group2.dirty !== undefined)
        assert(vm.$validator1.group2.pristine !== undefined)
      })
    })
  })


  describe('v-show', () => {
    beforeEach(() => {
      vm = new Vue({
        el: el,
        data: {
          hidden: false
        },
        template: '<validator v-show="hidden" name="validator1"></validator>'
      })
    })

    describe('set true', () => {
      beforeEach((done) => {
        vm.hidden = true
        vm.$nextTick(done)
      })

      it('validator scope should be assigned', () => {
        assert(vm.$validator1 !== undefined)
        assert(vm.$validator1.valid !== undefined)
        assert(vm.$validator1.invalid !== undefined)
        assert(vm.$validator1.touched !== undefined)
        assert(vm.$validator1.untouched !== undefined)
        assert(vm.$validator1.modified !== undefined)
        assert(vm.$validator1.dirty !== undefined)
        assert(vm.$validator1.pristine !== undefined)
      })

      context('set false', () => {
        beforeEach((done) => {
          vm.hidden = false
          vm.$nextTick(done)
        })

        it('validator scope should be assigned', () => {
          assert(vm.$validator1 !== undefined)
          assert(vm.$validator1.valid !== undefined)
          assert(vm.$validator1.invalid !== undefined)
          assert(vm.$validator1.touched !== undefined)
          assert(vm.$validator1.untouched !== undefined)
          assert(vm.$validator1.modified !== undefined)
          assert(vm.$validator1.dirty !== undefined)
          assert(vm.$validator1.pristine !== undefined)
        })

        describe('set true', () => {
          beforeEach((done) => {
            vm.hidden = true
            vm.$nextTick(done)
          })

          it('validator scope should be assigned', () => {
            assert(vm.$validator1 !== undefined)
            assert(vm.$validator1.valid !== undefined)
            assert(vm.$validator1.invalid !== undefined)
            assert(vm.$validator1.touched !== undefined)
            assert(vm.$validator1.untouched !== undefined)
            assert(vm.$validator1.modified !== undefined)
            assert(vm.$validator1.dirty !== undefined)
            assert(vm.$validator1.pristine !== undefined)
          })
        })
      })
    })
  })


  describe('v-if', () => {
    beforeEach(() => {
      vm = new Vue({
        el: el,
        data: {
          hidden: false
        },
        template: '<validator v-if="hidden" name="validator1"></validator>'
      })
    })

    describe('set true', () => {
      beforeEach((done) => {
        vm.hidden = true
        vm.$nextTick(done)
      })

      it('validator scope should be assigned', () => {
        assert(vm.$validator1 !== undefined)
        assert(vm.$validator1.valid !== undefined)
        assert(vm.$validator1.invalid !== undefined)
        assert(vm.$validator1.touched !== undefined)
        assert(vm.$validator1.untouched !== undefined)
        assert(vm.$validator1.modified !== undefined)
        assert(vm.$validator1.dirty !== undefined)
        assert(vm.$validator1.pristine !== undefined)
      })

      describe('set false', () => {
        beforeEach((done) => {
          vm.hidden = false
          vm.$nextTick(done)
        })

        it('validator scope should not be assigned', () => {
          assert(vm.$validator1 === null)
        })

        describe('set true', () => {
          beforeEach((done) => {
            vm.hidden = true
            vm.$nextTick(done)
          })

          it('validator scope should be assigned', () => {
            assert(vm.$validator1 !== undefined)
            assert(vm.$validator1.valid !== undefined)
            assert(vm.$validator1.invalid !== undefined)
            assert(vm.$validator1.touched !== undefined)
            assert(vm.$validator1.untouched !== undefined)
            assert(vm.$validator1.modified !== undefined)
            assert(vm.$validator1.dirty !== undefined)
            assert(vm.$validator1.pristine !== undefined)
          })
        })
      })
    })
  })
})

@@ -857,29 +857,24 @@
 %0A    context
-.skip
 ('not specif
@@ -902,32 +902,90 @@
  =%3E %7B%0A      
-// TODO:
+it.skip('should be called warn', () =%3E %7B%0A        // TODO:%0A      %7D)
 %0A    %7D)%0A    
@@ -1050,24 +1050,73 @@
 e', () =%3E %7B%0A
+      it.skip('should be called warn', () =%3E %7B%0A  
       // TOD
@@ -1114,24 +1114,33 @@
    // TODO:%0A
+      %7D)%0A
     %7D)%0A  %7D)%0A

Refactor skipped tests