|
1 |
| -import { loadFixture, testVM } from '../../../tests/utils' |
2 |
| - |
3 |
| -const variantList = [ |
4 |
| - 'secondary', |
5 |
| - 'primary', |
6 |
| - 'success', |
7 |
| - 'info', |
8 |
| - 'warning', |
9 |
| - 'danger', |
10 |
| - 'dark', |
11 |
| - 'light' |
12 |
| -].map(variant => { |
13 |
| - return { ref: `badge_${variant}`, variant } |
14 |
| -}) |
| 1 | +import Badge from './badge' |
| 2 | +import { mount } from '@vue/test-utils' |
15 | 3 |
|
16 | 4 | describe('badge', () => {
|
17 |
| - beforeEach(loadFixture(__dirname, 'badge')) |
18 |
| - testVM() |
| 5 | + it('should have base classes', async () => { |
| 6 | + const wrapper = mount(Badge) |
| 7 | + expect(wrapper.is('span')).toBe(true) |
| 8 | + expect(wrapper.classes()).toContain('badge') |
| 9 | + expect(wrapper.classes()).toContain('badge-secondary') |
| 10 | + expect(wrapper.classes()).not.toContain('badge-pill') |
| 11 | + expect(wrapper.classes()).not.toContain('active') |
| 12 | + expect(wrapper.classes()).not.toContain('disabled') |
| 13 | + expect(wrapper.attributes('href')).not.toBeDefined() |
| 14 | + }) |
19 | 15 |
|
20 |
| - it('should apply variant classes', async () => { |
21 |
| - const { |
22 |
| - app: { $refs } |
23 |
| - } = window |
| 16 | + it('should have default slot content', async () => { |
| 17 | + const wrapper = mount(Badge, { |
| 18 | + slots: { |
| 19 | + default: 'foobar' |
| 20 | + } |
| 21 | + }) |
| 22 | + expect(wrapper.is('span')).toBe(true) |
| 23 | + expect(wrapper.text()).toBe('foobar') |
| 24 | + expect(wrapper.classes()).toContain('badge') |
| 25 | + expect(wrapper.classes()).toContain('badge-secondary') |
| 26 | + expect(wrapper.classes()).not.toContain('badge-pill') |
| 27 | + expect(wrapper.classes()).not.toContain('active') |
| 28 | + expect(wrapper.classes()).not.toContain('disabled') |
| 29 | + expect(wrapper.attributes('href')).not.toBeDefined() |
| 30 | + }) |
24 | 31 |
|
25 |
| - expect($refs.badge_pill).toHaveAllClasses(['badge', 'badge-pill']) |
| 32 | + it('should apply variant class', async () => { |
| 33 | + const wrapper = mount(Badge, { |
| 34 | + propsData: { |
| 35 | + variant: 'danger' |
| 36 | + } |
| 37 | + }) |
| 38 | + expect(wrapper.is('span')).toBe(true) |
| 39 | + expect(wrapper.classes()).toContain('badge-danger') |
| 40 | + expect(wrapper.classes()).toContain('badge') |
| 41 | + expect(wrapper.classes()).not.toContain('badge-pill') |
| 42 | + expect(wrapper.classes()).not.toContain('active') |
| 43 | + expect(wrapper.classes()).not.toContain('disabled') |
| 44 | + }) |
26 | 45 |
|
27 |
| - variantList.forEach(({ ref, variant }) => { |
28 |
| - const vm = $refs[ref][0] |
29 |
| - expect(vm).toHaveAllClasses(['badge', `badge-${variant}`]) |
| 46 | + it('should apply pill class', async () => { |
| 47 | + const wrapper = mount(Badge, { |
| 48 | + propsData: { |
| 49 | + pill: true |
| 50 | + } |
30 | 51 | })
|
| 52 | + expect(wrapper.is('span')).toBe(true) |
| 53 | + expect(wrapper.classes()).toContain('badge-pill') |
| 54 | + expect(wrapper.classes()).toContain('badge') |
| 55 | + expect(wrapper.classes()).toContain('badge-secondary') |
| 56 | + expect(wrapper.classes()).not.toContain('active') |
| 57 | + expect(wrapper.classes()).not.toContain('disabled') |
31 | 58 | })
|
32 | 59 |
|
33 |
| - it('should apply secondary class when not passed variant', async () => { |
34 |
| - const { |
35 |
| - app: { $refs } |
36 |
| - } = window |
| 60 | + it('should have active class when prop active set', async () => { |
| 61 | + const wrapper = mount(Badge, { |
| 62 | + propsData: { |
| 63 | + active: true |
| 64 | + } |
| 65 | + }) |
| 66 | + expect(wrapper.is('span')).toBe(true) |
| 67 | + expect(wrapper.classes()).toContain('active') |
| 68 | + expect(wrapper.classes()).toContain('badge-secondary') |
| 69 | + expect(wrapper.classes()).toContain('badge') |
| 70 | + expect(wrapper.classes()).not.toContain('badge-pill') |
| 71 | + expect(wrapper.classes()).not.toContain('disabled') |
| 72 | + }) |
37 | 73 |
|
38 |
| - const vm = $refs.no_props |
39 |
| - expect(vm).toHaveClass('badge-secondary') |
| 74 | + it('should have disabled class when prop disabled set', async () => { |
| 75 | + const wrapper = mount(Badge, { |
| 76 | + propsData: { |
| 77 | + disabled: true |
| 78 | + } |
| 79 | + }) |
| 80 | + expect(wrapper.is('span')).toBe(true) |
| 81 | + expect(wrapper.classes()).toContain('disabled') |
| 82 | + expect(wrapper.classes()).toContain('badge-secondary') |
| 83 | + expect(wrapper.classes()).toContain('badge') |
| 84 | + expect(wrapper.classes()).not.toContain('badge-pill') |
| 85 | + expect(wrapper.classes()).not.toContain('active') |
40 | 86 | })
|
41 | 87 |
|
42 |
| - it('should not apply pill class when not passed pill boolean prop', async () => { |
43 |
| - const { |
44 |
| - app: { $refs } |
45 |
| - } = window |
| 88 | + it('renders custom root element', async () => { |
| 89 | + const wrapper = mount(Badge, { |
| 90 | + propsData: { |
| 91 | + tag: 'small' |
| 92 | + } |
| 93 | + }) |
| 94 | + expect(wrapper.is('small')).toBe(true) |
| 95 | + expect(wrapper.classes()).toContain('badge') |
| 96 | + expect(wrapper.classes()).toContain('badge-secondary') |
| 97 | + expect(wrapper.classes()).not.toContain('badge-pill') |
| 98 | + expect(wrapper.classes()).not.toContain('active') |
| 99 | + expect(wrapper.classes()).not.toContain('disabled') |
| 100 | + }) |
46 | 101 |
|
47 |
| - const vm = $refs.no_props |
48 |
| - expect(vm).not.toHaveClass('badge-pill') |
| 102 | + it('renders link when href provided', async () => { |
| 103 | + const wrapper = mount(Badge, { |
| 104 | + propsData: { |
| 105 | + href: '/foo/bar' |
| 106 | + } |
| 107 | + }) |
| 108 | + expect(wrapper.is('a')).toBe(true) |
| 109 | + expect(wrapper.attributes('href')).toBeDefined() |
| 110 | + expect(wrapper.attributes('href')).toBe('/foo/bar') |
| 111 | + expect(wrapper.classes()).toContain('badge') |
| 112 | + expect(wrapper.classes()).toContain('badge-secondary') |
| 113 | + expect(wrapper.classes()).not.toContain('badge-pill') |
| 114 | + expect(wrapper.classes()).not.toContain('active') |
| 115 | + expect(wrapper.classes()).not.toContain('disabled') |
49 | 116 | })
|
50 | 117 | })
|
0 commit comments