Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(separator): add test #102

Merged
merged 11 commits into from
May 12, 2023
46 changes: 46 additions & 0 deletions packages/components/separator/src/separator.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { describe, expect, it } from 'vitest'
import { mount, shallowMount } from '@vue/test-utils'
import { OkuSeparator } from './separator'

describe('OkuSeparator', () => {
const wrapper = mount(OkuSeparator)

it('renders correctly', async () => {
expect(wrapper.html()).toBe(`<div role="separator" data-orientation="horizontal">
<!---->
</div>`)
})

it('renders ref correctly', async () => {
// TODO: outerHTML is not available on VueWrapper
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
expect(wrapper.vm.innerRef.outerHTML).toBe('<div role="separator" data-orientation="horizontal"><!----></div>')
})

it('sets role as separator without decorative', async () => {
expect(wrapper.attributes('role')).toBe('separator')
})

it('sets default orientation horizontal', async () => {
expect(wrapper.attributes('data-orientation')).toBe('horizontal')
})

it('sets role as none on adding decorative', async () => {
const wrapper = shallowMount(OkuSeparator, {
propsData: {
decorative: true,
},
})
expect(wrapper.attributes('role')).toBe('none')
})

it('sets orientation vertical', async () => {
const wrapper = shallowMount(OkuSeparator, {
propsData: {
orientation: 'vertical',
},
})
expect(wrapper.attributes('data-orientation')).toBe('vertical')
})
})
7 changes: 5 additions & 2 deletions packages/components/separator/src/separator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const Separator = defineComponent({
// `aria-orientation` defaults to `horizontal` so we only need it if `orientation` is vertical
const ariaOrientation = orientation === 'vertical' ? orientation : undefined
const semanticProps = props.decorative ? { role: 'none' } : { 'aria-orientation': ariaOrientation, 'role': 'separator' }
const dataOrientation = { 'data-orientation': orientation }

const innerRef = ref<ComponentPublicInstance>()

Expand All @@ -62,13 +63,15 @@ const Separator = defineComponent({
...attrs,
ref: innerRef,
...semanticProps,
dataOrientation: orientation,
...dataOrientation,
style: {
...domProps,
border: 'none',
},
},
slots.default?.(),
{
default: () => slots.default?.(),
},
)

return originalReturn as unknown as {
Expand Down