@@ -528,6 +528,155 @@ describe('form-tags', () => {
528
528
wrapper.destroy()
529
529
})
530
530
531
+
it('reset() method works', async () => {
532
+
const wrapper = mount(BFormTags, {
533
+
propsData: {
534
+
value: ['one', 'two'],
535
+
addOnChange: true,
536
+
tagValidator: tag => tag.length < 4
537
+
}
538
+
})
539
+
540
+
expect(wrapper.element.tagName).toBe('DIV')
541
+
expect(wrapper.vm.tags).toEqual(['one', 'two'])
542
+
expect(wrapper.vm.newTag).toEqual('')
543
+
544
+
const $input = wrapper.find('input')
545
+
expect($input.exists()).toBe(true)
546
+
expect($input.element.value).toBe('')
547
+
expect($input.element.type).toBe('text')
548
+
549
+
$input.element.value = 'three'
550
+
await $input.trigger('input')
551
+
await $input.trigger('change')
552
+
expect(wrapper.vm.newTag).toEqual('three')
553
+
expect(wrapper.vm.tags).toEqual(['one', 'two'])
554
+
expect(wrapper.vm.tagsState.invalid).toContain('three')
555
+
556
+
const $tags = wrapper.findAll('.badge')
557
+
expect($tags.length).toBe(2)
558
+
await $tags
559
+
.at(1)
560
+
.find('button')
561
+
.trigger('click')
562
+
expect(wrapper.vm.tags).toEqual(['one'])
563
+
expect(wrapper.vm.removedTags).toContain('two')
564
+
565
+
wrapper.vm.reset()
566
+
await waitNT(wrapper.vm)
567
+
568
+
expect(wrapper.vm.newTag).toEqual('')
569
+
expect(wrapper.vm.tags).toEqual([])
570
+
expect(wrapper.vm.removedTags).toEqual([])
571
+
expect(wrapper.vm.tagsState.invalid).toEqual([])
572
+
573
+
wrapper.destroy()
574
+
})
575
+
576
+
it('native reset event works', async () => {
577
+
const wrapper = mount(BFormTags, {
578
+
propsData: {
579
+
value: ['one', 'two'],
580
+
addOnChange: true,
581
+
tagValidator: tag => tag.length < 4
582
+
}
583
+
})
584
+
585
+
expect(wrapper.element.tagName).toBe('DIV')
586
+
expect(wrapper.vm.tags).toEqual(['one', 'two'])
587
+
expect(wrapper.vm.newTag).toEqual('')
588
+
589
+
const $input = wrapper.find('input')
590
+
expect($input.exists()).toBe(true)
591
+
expect($input.element.value).toBe('')
592
+
expect($input.element.type).toBe('text')
593
+
594
+
$input.element.value = 'three'
595
+
await $input.trigger('input')
596
+
await $input.trigger('change')
597
+
expect(wrapper.vm.newTag).toEqual('three')
598
+
expect(wrapper.vm.tags).toEqual(['one', 'two'])
599
+
expect(wrapper.vm.tagsState.invalid).toContain('three')
600
+
601
+
const $tags = wrapper.findAll('.badge')
602
+
expect($tags.length).toBe(2)
603
+
await $tags
604
+
.at(1)
605
+
.find('button')
606
+
.trigger('click')
607
+
expect(wrapper.vm.tags).toEqual(['one'])
608
+
expect(wrapper.vm.removedTags).toContain('two')
609
+
610
+
await $input.trigger('reset')
611
+
await waitNT(wrapper.vm)
612
+
613
+
expect(wrapper.vm.newTag).toEqual('')
614
+
expect(wrapper.vm.tags).toEqual([])
615
+
expect(wrapper.vm.removedTags).toEqual([])
616
+
expect(wrapper.vm.tagsState.invalid).toEqual([])
617
+
618
+
wrapper.destroy()
619
+
})
620
+
621
+
it('form native reset event triggers reset', async () => {
622
+
const App = {
623
+
render(h) {
624
+
return h('form', [
625
+
h(BFormTags, {
626
+
props: {
627
+
value: ['one', 'two'],
628
+
addOnChange: true,
629
+
tagValidator: tag => tag.length < 4
630
+
}
631
+
})
632
+
])
633
+
}
634
+
}
635
+
const wrapper = mount(App, {
636
+
attachTo: createContainer()
637
+
})
638
+
639
+
expect(wrapper.element.tagName).toBe('FORM')
640
+
641
+
const formTags = wrapper.findComponent(BFormTags)
642
+
expect(formTags.exists()).toBe(true)
643
+
expect(formTags.element.tagName).toBe('DIV')
644
+
expect(formTags.vm.tags).toEqual(['one', 'two'])
645
+
expect(formTags.vm.newTag).toEqual('')
646
+
647
+
const $input = formTags.find('input')
648
+
expect($input.exists()).toBe(true)
649
+
expect($input.element.value).toBe('')
650
+
expect($input.element.type).toBe('text')
651
+
652
+
$input.element.value = 'three'
653
+
await $input.trigger('input')
654
+
await $input.trigger('change')
655
+
expect(formTags.vm.newTag).toEqual('three')
656
+
expect(formTags.vm.tags).toEqual(['one', 'two'])
657
+
expect(formTags.vm.tagsState.invalid).toContain('three')
658
+
659
+
const $tags = formTags.findAll('.badge')
660
+
expect($tags.length).toBe(2)
661
+
await $tags
662
+
.at(1)
663
+
.find('button')
664
+
.trigger('click')
665
+
expect(formTags.vm.tags).toEqual(['one'])
666
+
expect(formTags.vm.removedTags).toContain('two')
667
+
668
+
// Trigger form's native reset event
669
+
wrapper.find('form').trigger('reset')
670
+
await waitNT(formTags.vm)
671
+
672
+
expect(formTags.vm.newTag).toEqual('')
673
+
expect(formTags.vm.tags).toEqual([])
674
+
expect(formTags.vm.removedTags).toEqual([])
675
+
expect(formTags.vm.tagsState.invalid).toEqual([])
676
+
677
+
wrapper.destroy()
678
+
})
679
+
531
680
it('focuses input when wrapper div clicked', async () => {
532
681
const wrapper = mount(BFormTags, {
533
682
attachTo: createContainer(),
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4