2022-02-21 14:28:22 +08:00
|
|
|
import { defineComponent, nextTick } from 'vue'
|
|
|
|
import { mount } from '@vue/test-utils'
|
2022-03-25 15:35:56 +08:00
|
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
|
|
import { provideGlobalConfig, useNamespace } from '..'
|
2022-02-21 14:28:22 +08:00
|
|
|
import type { VueWrapper } from '@vue/test-utils'
|
|
|
|
|
|
|
|
const TestComp = defineComponent({
|
|
|
|
setup() {
|
|
|
|
const ns = useNamespace('table')
|
2022-07-28 22:01:22 +08:00
|
|
|
const cssVar = ns.cssVar({
|
|
|
|
'border-style': 'solid',
|
|
|
|
'border-width': '',
|
|
|
|
})
|
|
|
|
const cssVarBlock = ns.cssVarBlock({
|
|
|
|
'text-color': '#409eff',
|
|
|
|
'active-color': '',
|
|
|
|
})
|
2022-02-21 14:28:22 +08:00
|
|
|
return () => (
|
|
|
|
<div
|
|
|
|
id="testId"
|
|
|
|
class={[
|
|
|
|
ns.b(), // return ns + block
|
|
|
|
ns.b('body'),
|
|
|
|
ns.e('content'),
|
|
|
|
ns.m('active'),
|
|
|
|
ns.be('content', 'active'),
|
|
|
|
ns.em('content', 'active'),
|
|
|
|
ns.bem('body', 'content', 'active'),
|
|
|
|
ns.is('focus'),
|
|
|
|
ns.e(), // return empty string
|
|
|
|
ns.m(), // return empty string
|
|
|
|
ns.be(), // return empty string
|
|
|
|
ns.em(), // return empty string
|
|
|
|
ns.bem(), // return empty string
|
|
|
|
ns.is('hover', undefined), // return empty string
|
|
|
|
ns.is('clicked', false), // return empty string
|
|
|
|
]}
|
2022-07-28 22:01:22 +08:00
|
|
|
style={{ ...cssVar, ...cssVarBlock }}
|
2022-02-21 14:28:22 +08:00
|
|
|
>
|
|
|
|
text
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('use-locale', () => {
|
|
|
|
const Comp = defineComponent({
|
|
|
|
setup(_props, { slots }) {
|
|
|
|
provideGlobalConfig({ namespace: 'ep' })
|
|
|
|
return () => slots.default?.()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
let wrapper: VueWrapper<InstanceType<typeof Comp>>
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = mount(Comp, {
|
|
|
|
slots: { default: () => <TestComp /> },
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should provide bem correctly', async () => {
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('#testId').classes()).toEqual([
|
|
|
|
'ep-table', // b()
|
|
|
|
'ep-table-body', // b('body')
|
|
|
|
'ep-table__content', // e('content')
|
|
|
|
'ep-table--active', // m('active')
|
|
|
|
'ep-table-content__active', // be('content', 'active')
|
|
|
|
'ep-table__content--active', // em('content', 'active')
|
|
|
|
'ep-table-body__content--active', // bem('body', 'content', 'active')
|
|
|
|
'is-focus', // is('focus')
|
|
|
|
])
|
2022-07-28 22:01:22 +08:00
|
|
|
|
|
|
|
const style = wrapper.find('#testId').attributes('style')
|
|
|
|
expect(style).toMatch('--ep-border-style: solid;')
|
|
|
|
expect(style).not.toMatch('--ep-border-width:')
|
|
|
|
expect(style).toMatch('--ep-table-text-color: #409eff;')
|
|
|
|
expect(style).not.toMatch('--ep-table-active-color:')
|
2022-02-21 14:28:22 +08:00
|
|
|
})
|
|
|
|
})
|