Skip to content

Commit

Permalink
fix(b-form-tags): unit test (#5586)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobmllr95 authored Jul 16, 2020
1 parent feca961 commit f4d509a
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions src/components/form-tags/form-tags.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { createContainer, waitNT, waitRAF } from '../../../tests/utils'
import { BFormTags } from './form-tags'

describe('form-tags', () => {
it('has div as root element', async () => {
it('has expected default structure', async () => {
const wrapper = mount(BFormTags)
expect(wrapper.element.tagName).toBe('DIV')

expect(wrapper.element.tagName).toBe('DIV')
expect(wrapper.classes()).toContain('b-form-tags')
expect(wrapper.classes()).toContain('form-control')
expect(wrapper.attributes('role')).toBe('group')
Expand All @@ -21,6 +21,7 @@ describe('form-tags', () => {
value: ['apple', 'orange']
}
})

expect(wrapper.element.tagName).toBe('DIV')

const $tags = wrapper.findAll('.b-form-tag')
Expand Down Expand Up @@ -49,12 +50,10 @@ describe('form-tags', () => {
value: ['apple', 'orange']
}
})
expect(wrapper.element.tagName).toBe('DIV')

await wrapper.setProps({
value: ['pear']
})
expect(wrapper.element.tagName).toBe('DIV')

await wrapper.setProps({ value: ['pear'] })
expect(wrapper.vm.tags).toEqual(['pear'])

wrapper.destroy()
Expand All @@ -72,13 +71,14 @@ describe('form-tags', () => {
}
}
})
expect(wrapper.element.tagName).toBe('DIV')

await waitNT(wrapper.vm)
await waitRAF()

expect(wrapper.element.tagName).toBe('DIV')

expect(scope).toBeDefined()
expect(typeof scope).toBe('object')

expect(Array.isArray(scope.tags)).toBe(true)
expect(scope.tags).toEqual(['apple', 'orange'])
expect(typeof scope.addTag).toBe('function')
Expand All @@ -104,11 +104,11 @@ describe('form-tags', () => {
name: 'foo'
}
})

expect(wrapper.element.tagName).toBe('DIV')

const $hidden = wrapper.findAll('input[type=hidden]')
expect($hidden.length).toBe(2)

expect($hidden.at(0).attributes('value')).toEqual('apple')
expect($hidden.at(0).attributes('name')).toEqual('foo')
expect($hidden.at(1).attributes('value')).toEqual('orange')
Expand All @@ -123,13 +123,12 @@ describe('form-tags', () => {
value: ['apple', 'orange']
}
})
expect(wrapper.element.tagName).toBe('DIV')

expect(wrapper.element.tagName).toBe('DIV')
expect(wrapper.vm.tags).toEqual(['apple', 'orange'])
expect(wrapper.vm.newTag).toEqual('')

const $input = wrapper.find('input')

expect($input.exists()).toBe(true)
expect($input.element.value).toBe('')
expect($input.element.type).toBe('text')
Expand Down Expand Up @@ -164,14 +163,13 @@ describe('form-tags', () => {
value: ['apple', 'orange', 'pear', 'peach']
}
})
expect(wrapper.element.tagName).toBe('DIV')

expect(wrapper.element.tagName).toBe('DIV')
expect(wrapper.vm.tags).toEqual(['apple', 'orange', 'pear', 'peach'])
expect(wrapper.vm.newTag).toEqual('')

let $tags = wrapper.findAll('.badge')
expect($tags.length).toBe(4)

expect($tags.at(1).attributes('title')).toEqual('orange')

const $btn = $tags.at(1).find('button')
Expand All @@ -194,13 +192,12 @@ describe('form-tags', () => {
value: ['apple', 'orange']
}
})
expect(wrapper.element.tagName).toBe('DIV')

expect(wrapper.element.tagName).toBe('DIV')
expect(wrapper.vm.tags).toEqual(['apple', 'orange'])
expect(wrapper.vm.newTag).toEqual('')

const $input = wrapper.find('input')

expect($input.exists()).toBe(true)
expect($input.element.value).toBe('')

Expand Down Expand Up @@ -234,13 +231,12 @@ describe('form-tags', () => {
value: ['one', 'two']
}
})
expect(wrapper.element.tagName).toBe('DIV')

expect(wrapper.element.tagName).toBe('DIV')
expect(wrapper.vm.tags).toEqual(['one', 'two'])
expect(wrapper.vm.newTag).toEqual('')

const $input = wrapper.find('input')

expect($input.exists()).toBe(true)
expect($input.element.value).toBe('')

Expand Down Expand Up @@ -295,8 +291,8 @@ describe('form-tags', () => {
value: ['one', 'two']
}
})
expect(wrapper.element.tagName).toBe('DIV')

expect(wrapper.element.tagName).toBe('DIV')
expect(wrapper.vm.tags).toEqual(['one', 'two'])
expect(wrapper.vm.newTag).toEqual('')
expect(wrapper.vm.duplicateTags).toEqual([])
Expand All @@ -306,7 +302,6 @@ describe('form-tags', () => {
expect(wrapper.find('.form-text').exists()).toBe(false)

const $input = wrapper.find('input')

expect($input.exists()).toBe(true)
expect($input.element.value).toBe('')

Expand Down Expand Up @@ -465,16 +460,16 @@ describe('form-tags', () => {
value: ['apple', 'orange']
}
})
expect(wrapper.element.tagName).toBe('DIV')

expect(wrapper.element.tagName).toBe('DIV')
expect(wrapper.vm.tags).toEqual(['apple', 'orange'])
expect(wrapper.vm.newTag).toEqual('')

const $input = wrapper.find('input')
const $button = wrapper.find('button.b-form-tags-button')

expect($input.exists()).toBe(true)
expect($input.element.value).toBe('')

const $button = wrapper.find('button.b-form-tags-button')
expect($button.exists()).toBe(true)
expect($button.classes()).toContain('invisible')

Expand All @@ -499,20 +494,18 @@ describe('form-tags', () => {
value: ['apple', 'orange']
}
})
expect(wrapper.element.tagName).toBe('DIV')

await waitNT(wrapper.vm)
await waitRAF()

expect(wrapper.element.tagName).toBe('DIV')
expect(wrapper.vm.tags).toEqual(['apple', 'orange'])
expect(wrapper.vm.newTag).toEqual('')

expect(wrapper.classes()).not.toContain('focus')

const $input = wrapper.find('input')

expect($input.exists()).toBe(true)
expect($input.element.value).toBe('')

expect(document.activeElement).not.toBe($input.element)

await wrapper.trigger('click')
Expand Down Expand Up @@ -552,22 +545,26 @@ describe('form-tags', () => {
value: ['apple', 'orange']
}
})
expect(wrapper.element.tagName).toBe('DIV')

await waitNT(wrapper.vm)
await waitRAF()

expect(wrapper.element.tagName).toBe('DIV')
expect(wrapper.vm.tags).toEqual(['apple', 'orange'])
expect(wrapper.vm.newTag).toEqual('')

expect(wrapper.classes()).not.toContain('focus')
expect(wrapper.classes()).toContain('focus')

const $input = wrapper.find('input')

expect($input.exists()).toBe(true)
expect($input.element.value).toBe('')

expect(document.activeElement).toBe($input.element)

wrapper.vm.blur()
await waitNT(wrapper.vm)
await waitRAF()
expect(wrapper.classes()).not.toContain('focus')
expect(document.activeElement).not.toBe($input.element)

wrapper.destroy()
})
})

1 comment on commit f4d509a

@vercel
Copy link

@vercel vercel bot commented on f4d509a Jul 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.