|
1 |
| -import { loadFixture, testVM } from '../../../tests/utils' |
| 1 | +import ButtonGroup from './button-group' |
| 2 | +import { mount } from '@vue/test-utils' |
2 | 3 |
|
3 | 4 | describe('button-group', () => {
|
4 |
| - beforeEach(loadFixture(__dirname, 'button-group')) |
5 |
| - testVM() |
6 |
| - |
7 |
| - it('basic should contain base class', async () => { |
8 |
| - const { |
9 |
| - app: { $refs } |
10 |
| - } = window |
| 5 | + it('has expected default structure', async () => { |
| 6 | + const wrapper = mount(ButtonGroup) |
| 7 | + expect(wrapper.is('div')).toBe(true) |
| 8 | + expect(wrapper.classes()).toContain('btn-group') |
| 9 | + expect(wrapper.classes().length).toBe(1) |
| 10 | + expect(wrapper.attributes('role')).toBeDefined() |
| 11 | + expect(wrapper.attributes('role')).toBe('group') |
| 12 | + expect(wrapper.text()).toBe('') |
| 13 | + }) |
11 | 14 |
|
12 |
| - expect($refs.basic).toHaveClass('btn-group') |
| 15 | + it('should render default slot', async () => { |
| 16 | + const wrapper = mount(ButtonGroup, { |
| 17 | + slots: { |
| 18 | + default: '<span>foobar</span>' |
| 19 | + } |
| 20 | + }) |
| 21 | + expect(wrapper.is('div')).toBe(true) |
| 22 | + expect(wrapper.classes()).toContain('btn-group') |
| 23 | + expect(wrapper.classes().length).toBe(1) |
| 24 | + expect(wrapper.attributes('role')).toBeDefined() |
| 25 | + expect(wrapper.attributes('role')).toBe('group') |
| 26 | + expect(wrapper.find('span').exists()).toBe(true) |
| 27 | + expect(wrapper.text()).toBe('foobar') |
13 | 28 | })
|
14 | 29 |
|
15 | 30 | it('should apply vertical class', async () => {
|
16 |
| - const { |
17 |
| - app: { $refs } |
18 |
| - } = window |
19 |
| - |
20 |
| - expect($refs.vertical).toHaveClass('btn-group-vertical') |
| 31 | + const wrapper = mount(ButtonGroup, { |
| 32 | + propsData: { |
| 33 | + vertical: true |
| 34 | + } |
| 35 | + }) |
| 36 | + expect(wrapper.is('div')).toBe(true) |
| 37 | + expect(wrapper.classes()).toContain('btn-group-vertical') |
| 38 | + expect(wrapper.classes()).not.toContain('btn-group') |
| 39 | + expect(wrapper.classes().length).toBe(1) |
21 | 40 | })
|
22 | 41 |
|
23 | 42 | it('should apply size class', async () => {
|
24 |
| - const { |
25 |
| - app: { $refs } |
26 |
| - } = window |
| 43 | + const wrapper = mount(ButtonGroup, { |
| 44 | + propsData: { |
| 45 | + size: 'sm' |
| 46 | + } |
| 47 | + }) |
| 48 | + expect(wrapper.is('div')).toBe(true) |
| 49 | + expect(wrapper.classes()).toContain('btn-group') |
| 50 | + expect(wrapper.classes()).toContain('btn-group-sm') |
| 51 | + expect(wrapper.classes().length).toBe(2) |
| 52 | + }) |
| 53 | + |
| 54 | + it('should apply size class when vertical', async () => { |
| 55 | + const wrapper = mount(ButtonGroup, { |
| 56 | + propsData: { |
| 57 | + size: 'sm', |
| 58 | + vertical: true |
| 59 | + } |
| 60 | + }) |
| 61 | + expect(wrapper.is('div')).toBe(true) |
| 62 | + expect(wrapper.classes()).toContain('btn-group-sm') |
| 63 | + expect(wrapper.classes()).toContain('btn-group-vertical') |
| 64 | + expect(wrapper.classes()).not.toContain('btn-group') |
| 65 | + expect(wrapper.classes().length).toBe(2) |
| 66 | + }) |
27 | 67 |
|
28 |
| - expect($refs.size).toHaveClass('btn-group-sm') |
| 68 | + it('has custom role when aria-role prop set', async () => { |
| 69 | + const wrapper = mount(ButtonGroup, { |
| 70 | + propsData: { |
| 71 | + ariaRole: 'foobar' |
| 72 | + } |
| 73 | + }) |
| 74 | + expect(wrapper.is('div')).toBe(true) |
| 75 | + expect(wrapper.classes()).toContain('btn-group') |
| 76 | + expect(wrapper.classes().length).toBe(1) |
| 77 | + expect(wrapper.attributes('role')).toBeDefined() |
| 78 | + expect(wrapper.attributes('role')).toBe('foobar') |
29 | 79 | })
|
30 | 80 | })
|
0 commit comments