diff --git a/src/App.vue b/src/App.vue index a0d7a19..46362c7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,4 +2,4 @@ Vue-Tailwind - + \ No newline at end of file diff --git a/src/components/DxhTabs.vue b/src/components/DxhTabs.vue new file mode 100644 index 0000000..766a526 --- /dev/null +++ b/src/components/DxhTabs.vue @@ -0,0 +1,56 @@ + + + + + {{ item.label }} + + + {{ findActiveTabContent().content }} + + + + diff --git a/src/components/__tests__/DxhTab.spec.ts b/src/components/__tests__/DxhTab.spec.ts new file mode 100644 index 0000000..421faa9 --- /dev/null +++ b/src/components/__tests__/DxhTab.spec.ts @@ -0,0 +1,46 @@ +import { describe, it, expect, beforeEach, afterEach } from 'vitest' +import { mount } from '@vue/test-utils' +import DxhTabs from '@/components/DxhTabs.vue' + +describe('DxhTabs.vue', () => { + let wrapper: any + + beforeEach(() => { + wrapper = mount(DxhTabs, { + props: { + direction: 'horizontal', + items: [ + { id: 1, label: 'Tab 1', content: 'Content 1' }, + { id: 2, label: 'Tab 2', content: 'Content 2' } + ], + defaultActive: 1 + } + }) + }) + + afterEach(() => { + wrapper.unmount() + }) + + it('renders with correct initial state', () => { + const tab1 = wrapper.find('[data-test="tab-1"]') + const tab2 = wrapper.find('[data-test="tab-2"]') + const content = wrapper.find('[data-test="tab-content"]') + + expect(tab1.classes()).toContain('border-black') + expect(tab2.classes()).not.toContain('border-black') + expect(content.text()).toBe('Content 1') + }) + + it('changes active tab on click', async () => { + const tab1 = wrapper.find('[data-test="tab-1"]') + const tab2 = wrapper.find('[data-test="tab-2"]') + const content = wrapper.find('[data-test="tab-content"]') + + await tab2.trigger('click') + + expect(tab1.classes()).not.toContain('border-black') + expect(tab2.classes()).toContain('border-black') + expect(content.text()).toBe('Content 2') + }) +}) diff --git a/src/index.ts b/src/index.ts index ee2ff8d..887aa11 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ -import DButton from "./components/DButton.vue" -import DInput from "./components/DInput.vue" +import DButton from './components/DButton.vue' +import DInput from './components/DInput.vue' +import DxhTabs from './components/DxhTabs.vue' -export default {DButton, DInput} \ No newline at end of file +export default { DButton, DInput, DxhTabs }