|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { mountSuspended } from '@nuxt/test-utils/runtime'; |
| 3 | +import Tabs from '@/components/ui/Tabs.vue'; |
| 4 | +import Tab from '@/components/ui/Tab.vue'; |
| 5 | +import { h } from 'vue'; |
| 6 | + |
| 7 | +describe('Tabs Component', () => { |
| 8 | + it('renders slot content', async () => { |
| 9 | + const wrapper = await mountSuspended(Tabs, { |
| 10 | + slots: { |
| 11 | + default: () => h('div', { 'data-testid': 'child-element' }, 'Child Content'), |
| 12 | + }, |
| 13 | + }); |
| 14 | + expect(wrapper.find('[data-testid="child-element"]').exists()).toBe(true); |
| 15 | + expect(wrapper.html()).toContain('Child Content'); |
| 16 | + }); |
| 17 | + |
| 18 | + it('applies the correct base classes', async () => { |
| 19 | + const wrapper = await mountSuspended(Tabs); |
| 20 | + const classes = wrapper.classes(); |
| 21 | + expect(classes).toContain('tabs'); |
| 22 | + expect(classes).toContain('border-b'); |
| 23 | + expect(classes).toContain('flex'); |
| 24 | + expect(classes).toContain('w-full'); |
| 25 | + }); |
| 26 | +}); |
| 27 | + |
| 28 | +describe('Tab Component', () => { |
| 29 | + it('renders the label correctly', async () => { |
| 30 | + const wrapper = await mountSuspended(Tab, { |
| 31 | + props: { label: 'My Tab', route: '/' }, |
| 32 | + }); |
| 33 | + expect(wrapper.text()).toContain('My Tab'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('renders a NuxtLink with the correct route', async () => { |
| 37 | + const wrapper = await mountSuspended(Tab, { |
| 38 | + props: { label: 'My Tab', route: '/' }, |
| 39 | + }); |
| 40 | + const link = wrapper.findComponent({ name: 'NuxtLink' }); |
| 41 | + expect(link.exists()).toBe(true); |
| 42 | + expect(link.props('to')).toBe('/'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('applies inactive styles by default', async () => { |
| 46 | + const wrapper = await mountSuspended(Tab, { |
| 47 | + props: { label: 'Inactive Tab', route: '/' }, |
| 48 | + }); |
| 49 | + expect(wrapper.classes()).toContain('text-muted-foreground'); |
| 50 | + expect(wrapper.classes()).toContain('font-medium'); |
| 51 | + expect(wrapper.classes()).not.toContain('text-foreground'); |
| 52 | + expect(wrapper.classes()).not.toContain('font-bold'); |
| 53 | + expect(wrapper.find('.bg-primary').exists()).toBe(false); |
| 54 | + }); |
| 55 | + |
| 56 | + it('applies active styles when isActive is true', async () => { |
| 57 | + const wrapper = await mountSuspended(Tab, { |
| 58 | + props: { label: 'Active Tab', route: '/', isActive: true }, |
| 59 | + }); |
| 60 | + expect(wrapper.classes()).toContain('text-foreground'); |
| 61 | + expect(wrapper.classes()).toContain('font-bold'); |
| 62 | + expect(wrapper.classes()).not.toContain('text-muted-foreground'); |
| 63 | + expect(wrapper.classes()).not.toContain('font-medium'); |
| 64 | + expect(wrapper.find('.bg-primary').exists()).toBe(true); |
| 65 | + }); |
| 66 | + |
| 67 | + it('renders multiple tabs inside a Tabs container', async () => { |
| 68 | + const wrapper = await mountSuspended(Tabs, { |
| 69 | + slots: { |
| 70 | + default: () => [ |
| 71 | + h(Tab, { label: 'Tab 1', route: '/' }), |
| 72 | + h(Tab, { label: 'Tab 2', route: '/' }), |
| 73 | + ], |
| 74 | + }, |
| 75 | + }); |
| 76 | + expect(wrapper.findAllComponents(Tab).length).toBe(2); |
| 77 | + }); |
| 78 | +}); |
0 commit comments