Skip to content

Commit

Permalink
test: table
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed Jun 14, 2024
1 parent 1a53143 commit 35b491a
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 51 deletions.
48 changes: 0 additions & 48 deletions src/packages/base-field/__tests__/__snapshots__/index.test.js.snap

This file was deleted.

7 changes: 4 additions & 3 deletions src/packages/descriptions/__tests__/Descriptions.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ describe('Descriptions', () => {
},
onLoad: (value) => {
console.log(value)
},
onRequestError: (error) => {
console.log(error)
}
},
slots: {
Expand All @@ -40,6 +37,10 @@ describe('Descriptions', () => {
}
})
expect(wrapper.exists()).toBeTruthy()
// onReload
wrapper.vm.reload && wrapper.vm.reload()
// tryOnScopeDispose
wrapper.unmount()
})

it('props columns', async () => {
Expand Down
18 changes: 18 additions & 0 deletions src/packages/form/__tests__/Form.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import { Form, Text } from '../index'

describe('Form', () => {
it('render', async () => {
const wrapper = mount(Form, {
slots: {
default: () => {
return [
<Text name={'text'}/>
]
}
}
})
expect(wrapper.exists()).toBeTruthy()
})
})
33 changes: 33 additions & 0 deletions src/packages/locale-provider/__tests__/LocaleProvider.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import LocaleProvider, { useLocaleReceiver } from '../index'
import enUS from '../lang/en-US'

describe('LocaleProvider', () => {
it('render', async () => {
const wrapper = mount(LocaleProvider, {
slots: {
default: () => {
const { t } = useLocaleReceiver()
return (<div>{t('open')}</div>)
}
}
})
expect(wrapper.exists()).toBeTruthy()
// 切换语言
await wrapper.setProps({ locale: enUS })
expect(wrapper.exists()).toBeTruthy()
})

it('translate path', () => {
const wrapper = mount(LocaleProvider, {
slots: {
default: () => {
const { t } = useLocaleReceiver('Table')
return (<div>{t(['toolbar', 'reload'])}</div>)
}
}
})
expect(wrapper.exists()).toBeTruthy()
})
})
18 changes: 18 additions & 0 deletions src/packages/resize-observer/__tests__/ResizeObserver.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import ResizeObserver from '../index'

describe('ResizeObserver', () => {
it('render', async () => {
const wrapper = mount(ResizeObserver, {
slots: {
default: () => {
return (
<div style={{ height: '200px' }}/>
)
}
}
})
expect(wrapper.exists()).toBeTruthy()
})
})
68 changes: 68 additions & 0 deletions src/packages/table/__tests__/Table.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import { Table } from '../index'
import ColumnSetting from '../components/column-setting'
import { Tooltip } from 'ant-design-vue'

describe('Table', () => {
it('render', async () => {
const wrapper = mount(Table, {
props: {
columns: [
{
title: 'test1',
dataIndex: 'test1'
},
{
title: 'test2',
dataIndex: 'test2'
}
],
dataSource: [
{
test1: 'test1',
test2: 'test2'
}
]
}
})
expect(wrapper.exists()).toBeTruthy()
// column-setting
const columnSetting = wrapper.findComponent(ColumnSetting)
const button = columnSetting.get('button')
button.trigger('click')
})

it('render slots', async () => {
const wrapper = mount(Table, {
props: {
columns: [
{
title: 'test1',
dataIndex: 'test1'
},
{
title: 'test2',
dataIndex: 'test2'
}
],
request: () => {
return Promise.resolve({
data: [
{
test1: 'test1',
test2: 'test2'
}
]
})
}
},
slots: {
extra: () => {
return (<Tooltip>Extra</Tooltip>)
}
}
})
expect(wrapper.exists()).toBeTruthy()
})
})
7 changes: 7 additions & 0 deletions tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ global.window.matchMedia = (query) => {
removeListener: () => {}
}
}

const originGetComputedStyle = window.getComputedStyle
window.getComputedStyle = ele => {
const style = originGetComputedStyle(ele)
style.lineHeight = '16px';
return style;
}

0 comments on commit 35b491a

Please sign in to comment.