|
| 1 | +import NavItem from './nav-item' |
| 2 | +import Link from '../link/link' |
| 3 | +import { mount } from '@vue/test-utils' |
| 4 | + |
| 5 | +describe('nav-item', async () => { |
| 6 | + it('has expected default structure', async () => { |
| 7 | + const wrapper = mount(NavItem) |
| 8 | + expect(wrapper.is('li')).toBe(true) |
| 9 | + expect(wrapper.classes()).toContain('nav-item') |
| 10 | + expect(wrapper.classes().length).toBe(1) |
| 11 | + |
| 12 | + const link = wrapper.find('a') |
| 13 | + expect(link).toBeDefined() |
| 14 | + expect(link.is('a')).toBe(true) |
| 15 | + expect(link.is(Link)).toBe(true) |
| 16 | + expect(link.classes()).toContain('nav-link') |
| 17 | + expect(link.classes().length).toBe(1) |
| 18 | + expect(link.attributes('href')).toBeDefined() |
| 19 | + expect(link.attributes('href')).toBe('#') |
| 20 | + expect(link.attributes('role')).not.toBeDefined() |
| 21 | + }) |
| 22 | + |
| 23 | + it('has attrs on link when link-attrs set', async () => { |
| 24 | + const wrapper = mount(NavItem, { |
| 25 | + context: { |
| 26 | + props: { |
| 27 | + linkAttrs: { role: 'tab' } |
| 28 | + } |
| 29 | + } |
| 30 | + }) |
| 31 | + expect(wrapper.attributes('role')).not.toBeDefined() |
| 32 | + const link = wrapper.find(Link) |
| 33 | + expect(link).toBeDefined() |
| 34 | + expect(link.attributes('role')).toBeDefined() |
| 35 | + expect(link.attributes('role')).toBe('tab') |
| 36 | + }) |
| 37 | + |
| 38 | + it('has custom classes on link when link-classes set', async () => { |
| 39 | + const wrapper = mount(NavItem, { |
| 40 | + context: { |
| 41 | + props: { |
| 42 | + linkClasses: ['foo', { bar: true }] |
| 43 | + } |
| 44 | + } |
| 45 | + }) |
| 46 | + const link = wrapper.find(Link) |
| 47 | + expect(link).toBeDefined() |
| 48 | + expect(link.classes()).toContain('foo') |
| 49 | + expect(link.classes()).toContain('bar') |
| 50 | + expect(link.classes()).toContain('nav-link') |
| 51 | + }) |
| 52 | + |
| 53 | + it('has class "disabled" on link when disabled set', async () => { |
| 54 | + const wrapper = mount(NavItem, { |
| 55 | + context: { |
| 56 | + props: { disabled: true } |
| 57 | + } |
| 58 | + }) |
| 59 | + const link = wrapper.find(Link) |
| 60 | + expect(link).toBeDefined() |
| 61 | + expect(link.classes()).toContain('disabled') |
| 62 | + }) |
| 63 | + |
| 64 | + it('emits click event when clicked', async () => { |
| 65 | + const spy = jest.fn() |
| 66 | + const wrapper = mount(NavItem, { |
| 67 | + context: { |
| 68 | + on: { click: spy } |
| 69 | + } |
| 70 | + }) |
| 71 | + expect(spy).not.toHaveBeenCalled() |
| 72 | + wrapper.trigger('click') |
| 73 | + expect(spy).not.toHaveBeenCalled() |
| 74 | + |
| 75 | + const link = wrapper.find(Link) |
| 76 | + expect(link).toBeDefined() |
| 77 | + link.trigger('click') |
| 78 | + expect(spy).toHaveBeenCalled() |
| 79 | + }) |
| 80 | + |
| 81 | + it('does not emit a click event when clicked and disabled', async () => { |
| 82 | + const spy = jest.fn() |
| 83 | + const wrapper = mount(NavItem, { |
| 84 | + context: { |
| 85 | + props: { disabled: true }, |
| 86 | + on: { click: spy } |
| 87 | + } |
| 88 | + }) |
| 89 | + expect(spy).not.toHaveBeenCalled() |
| 90 | + wrapper.trigger('click') |
| 91 | + expect(spy).not.toHaveBeenCalled() |
| 92 | + |
| 93 | + const link = wrapper.find(Link) |
| 94 | + expect(link).toBeDefined() |
| 95 | + link.trigger('click') |
| 96 | + expect(spy).not.toHaveBeenCalled() |
| 97 | + }) |
| 98 | +}) |
0 commit comments