2022-02-23 10:47:25 +08:00
|
|
|
import { nextTick } from 'vue'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
2021-08-24 13:36:48 +08:00
|
|
|
import ElCheckbox from '@element-plus/components/checkbox'
|
2022-04-19 12:46:57 +08:00
|
|
|
import triggerEvent from '@element-plus/test-utils/trigger-event'
|
2022-02-06 00:37:20 +08:00
|
|
|
import { rAF } from '@element-plus/test-utils/tick'
|
2021-09-17 15:27:31 +08:00
|
|
|
import ElTable from '../src/table.vue'
|
2022-03-08 14:03:32 +08:00
|
|
|
import ElTableColumn from '../src/table-column'
|
2022-03-25 15:35:56 +08:00
|
|
|
import { doubleWait, getTestData, mount } from './table-test-common'
|
2021-09-17 15:27:31 +08:00
|
|
|
import type { VueWrapper } from '@vue/test-utils'
|
|
|
|
import type { ComponentPublicInstance } from 'vue'
|
2020-10-20 10:31:47 +08:00
|
|
|
|
2021-08-24 13:36:48 +08:00
|
|
|
const { CheckboxGroup: ElCheckboxGroup } = ElCheckbox
|
2020-10-20 10:31:47 +08:00
|
|
|
|
2022-04-19 12:46:57 +08:00
|
|
|
vi.mock('lodash-unified', async () => {
|
2022-02-10 16:35:44 +08:00
|
|
|
return {
|
2022-04-19 12:46:57 +08:00
|
|
|
...((await vi.importActual('lodash-unified')) as Record<string, any>),
|
|
|
|
debounce: vi.fn((fn) => {
|
|
|
|
fn.cancel = vi.fn()
|
|
|
|
fn.flush = vi.fn()
|
2022-02-10 16:35:44 +08:00
|
|
|
return fn
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-10-20 10:31:47 +08:00
|
|
|
describe('Table.vue', () => {
|
|
|
|
describe('rendering data is correct', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData">
|
|
|
|
<el-table-column prop="id" />
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
created() {
|
|
|
|
this.testData = getTestData()
|
|
|
|
},
|
|
|
|
})
|
2021-06-12 19:38:39 +08:00
|
|
|
it('head', async () => {
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-06-12 19:38:39 +08:00
|
|
|
const ths = wrapper.findAll('thead th')
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(ths.map((node) => node.text()).filter((o) => o)).toEqual([
|
|
|
|
'片名',
|
|
|
|
'发行日期',
|
|
|
|
'导演',
|
|
|
|
'时长(分)',
|
|
|
|
])
|
2020-10-20 10:31:47 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
it('row length', () => {
|
|
|
|
expect(
|
2021-09-04 19:29:28 +08:00
|
|
|
wrapper.findAll('.el-table__body-wrapper tbody tr').length
|
2020-10-20 10:31:47 +08:00
|
|
|
).toEqual(getTestData().length)
|
|
|
|
})
|
|
|
|
it('row data', () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const cells = wrapper.findAll('td .cell').map((node) => node.text())
|
|
|
|
const testDataArr = getTestData().flatMap((cur) => {
|
2021-06-12 19:38:39 +08:00
|
|
|
return Object.values(cur).map(String)
|
|
|
|
})
|
|
|
|
expect(cells).toEqual(testDataArr)
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
})
|
2021-02-26 20:18:37 +08:00
|
|
|
|
|
|
|
it('custom template', async () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
ElCheckboxGroup,
|
|
|
|
ElCheckbox,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="tableData">
|
|
|
|
<el-table-column label="someLabel">
|
|
|
|
<template #default="{ row }">
|
|
|
|
<el-checkbox-group v-model="row.checkList">
|
|
|
|
<el-checkbox label="复选框 A"></el-checkbox>
|
|
|
|
<el-checkbox label="复选框 B"></el-checkbox>
|
|
|
|
</el-checkbox-group>
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
tableData: [
|
|
|
|
{
|
|
|
|
checkList: [],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
checkList: ['复选框 A'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
checkList: ['复选框 A', '复选框 B'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
const vm = wrapper.vm
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-02-26 20:18:37 +08:00
|
|
|
const checkGroup = vm.$el.querySelectorAll(
|
2021-09-04 19:29:28 +08:00
|
|
|
'.el-table__body-wrapper .el-checkbox-group'
|
2021-02-26 20:18:37 +08:00
|
|
|
)
|
|
|
|
expect(checkGroup.length).toBe(3)
|
|
|
|
const checkbox = vm.$el.querySelectorAll(
|
2021-09-04 19:29:28 +08:00
|
|
|
'.el-table__body-wrapper .el-checkbox'
|
2021-02-26 20:18:37 +08:00
|
|
|
)
|
|
|
|
expect(checkbox.length).toBe(6)
|
|
|
|
const checkSelect = vm.$el.querySelectorAll(
|
2021-09-04 19:29:28 +08:00
|
|
|
'.el-table__body-wrapper label.is-checked'
|
2021-02-26 20:18:37 +08:00
|
|
|
)
|
|
|
|
expect(checkSelect.length).toBe(3)
|
|
|
|
})
|
2020-10-20 10:31:47 +08:00
|
|
|
describe('attributes', () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const createTable = function (props, opts?) {
|
2020-10-20 10:31:47 +08:00
|
|
|
return mount(
|
|
|
|
Object.assign(
|
|
|
|
{
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" ${props}>
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
created() {
|
|
|
|
this.testData = getTestData()
|
|
|
|
},
|
|
|
|
},
|
2021-09-04 19:29:28 +08:00
|
|
|
opts
|
|
|
|
)
|
2020-10-20 10:31:47 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('height', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('height="134"')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(wrapper.attributes('style')).toContain('height: 134px')
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('height as string', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('height="100px"')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(wrapper.attributes('style')).toContain('height: 100px')
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('maxHeight', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('max-height="134"')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(wrapper.attributes('style')).toContain('max-height: 134px')
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2022-02-11 15:00:33 +08:00
|
|
|
it('maxHeight uses special units', async () => {
|
|
|
|
const wrapper = createTable('max-height="60vh"')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2022-02-11 15:00:33 +08:00
|
|
|
expect(
|
|
|
|
wrapper.find('.el-table__body-wrapper').attributes('style')
|
2022-02-21 14:20:44 +08:00
|
|
|
).toContain('max-height: calc(60vh - 0px - 0px);')
|
2022-02-11 15:00:33 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('stripe', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('stripe')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(wrapper.classes()).toContain('el-table--striped')
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('border', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('border')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(wrapper.classes()).toContain('el-table--border')
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('fit', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable(':fit="false"')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(wrapper.classes()).not.toContain('el-table--fit')
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('show-header', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable(':show-header="false"')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(wrapper.findAll('.el-table__header-wrapper').length).toEqual(0)
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('tableRowClassName', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable(':row-class-name="tableRowClassName"', {
|
|
|
|
methods: {
|
|
|
|
tableRowClassName({ rowIndex }) {
|
|
|
|
if (rowIndex === 1) {
|
|
|
|
return 'info-row'
|
|
|
|
} else if (rowIndex === 3) {
|
|
|
|
return 'positive-row'
|
|
|
|
}
|
|
|
|
|
|
|
|
return ''
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(wrapper.findAll('.info-row').length).toEqual(1)
|
|
|
|
expect(wrapper.findAll('.positive-row').length).toEqual(1)
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('tableRowStyle[Object]', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable(':row-style="{ height: \'60px\' }"', {})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(wrapper.find('.el-table__body tr').attributes('style')).toContain(
|
2021-09-04 19:29:28 +08:00
|
|
|
'height: 60px'
|
2020-10-20 10:31:47 +08:00
|
|
|
)
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('tableRowStyle[Function]', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable(':row-style="tableRowStyle"', {
|
|
|
|
methods: {
|
|
|
|
tableRowStyle({ rowIndex }) {
|
|
|
|
if (rowIndex === 1) {
|
|
|
|
return { height: '60px', display: 'none' }
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const child1 = wrapper.find('.el-table__body tr:nth-child(1)')
|
|
|
|
const child2 = wrapper.find('.el-table__body tr:nth-child(2)')
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(child1.attributes('style')).toBeUndefined()
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(child2.attributes('style')).toContain('height: 60px')
|
|
|
|
expect(child2.attributes('style')).toContain('display: none')
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('current-row-key', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" row-key="id" highlight-current-row :current-row-key="currentRowKey">
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
created() {
|
|
|
|
this.testData = getTestData()
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return { currentRowKey: null }
|
|
|
|
},
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.vm.currentRowKey = 1
|
|
|
|
const tr = wrapper.find('.el-table__body-wrapper tbody tr')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(tr.classes()).toContain('current-row')
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.vm.currentRowKey = 2
|
|
|
|
|
|
|
|
const rows = wrapper.findAll('.el-table__body-wrapper tbody tr')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(tr.classes()).not.toContain('current-row')
|
|
|
|
expect(rows[1].classes()).toContain('current-row')
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
describe('filter', () => {
|
|
|
|
let wrapper: VueWrapper<ComponentPublicInstance>
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
beforeEach(async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table ref="table" :data="testData" @filter-change="handleFilterChange">
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column
|
|
|
|
prop="director"
|
|
|
|
column-key="director"
|
|
|
|
:filters="[
|
|
|
|
{ text: 'John Lasseter', value: 'John Lasseter' },
|
|
|
|
{ text: 'Peter Docter', value: 'Peter Docter' },
|
|
|
|
{ text: 'Andrew Stanton', value: 'Andrew Stanton' }
|
|
|
|
]"
|
|
|
|
:filter-method="filterMethod"
|
|
|
|
label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.testData = getTestData()
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
filterMethod(value, row) {
|
|
|
|
return value === row.director
|
|
|
|
},
|
|
|
|
handleFilterChange(filters) {
|
|
|
|
this.filters = filters
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => wrapper.unmount())
|
|
|
|
|
|
|
|
it('render', () => {
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(
|
2021-09-04 19:29:28 +08:00
|
|
|
wrapper.find('.el-table__column-filter-trigger')
|
2021-05-13 17:55:04 +08:00
|
|
|
).not.toBeUndefined()
|
2020-10-20 10:31:47 +08:00
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('click dropdown', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const btn = wrapper.find('.el-table__column-filter-trigger')
|
|
|
|
btn.trigger('click')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const filter = document.body.querySelector('.el-table-filter')
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(filter).not.toBeUndefined()
|
2020-10-20 10:31:47 +08:00
|
|
|
filter.parentNode.removeChild(filter)
|
|
|
|
})
|
|
|
|
|
2022-02-06 00:37:20 +08:00
|
|
|
it('click filter', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const btn = wrapper.find('.el-table__column-filter-trigger')
|
|
|
|
|
|
|
|
btn.trigger('click')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const filter = document.body.querySelector('.el-table-filter')
|
|
|
|
|
|
|
|
triggerEvent(filter.querySelector('.el-checkbox'), 'click', true, false)
|
|
|
|
// confrim button
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
triggerEvent(
|
|
|
|
filter.querySelector('.el-table-filter__bottom button'),
|
|
|
|
'click',
|
|
|
|
true,
|
2021-09-04 19:29:28 +08:00
|
|
|
false
|
2020-10-20 10:31:47 +08:00
|
|
|
)
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(
|
2021-09-04 19:29:28 +08:00
|
|
|
(wrapper.vm as ComponentPublicInstance & { filters: any }).filters[
|
2020-10-20 10:31:47 +08:00
|
|
|
'director'
|
2021-09-04 19:29:28 +08:00
|
|
|
]
|
2020-10-20 10:31:47 +08:00
|
|
|
).toEqual(['John Lasseter'])
|
|
|
|
expect(
|
2021-09-04 19:29:28 +08:00
|
|
|
wrapper.findAll('.el-table__body-wrapper tbody tr').length
|
2020-10-20 10:31:47 +08:00
|
|
|
).toEqual(3)
|
|
|
|
filter.parentNode.removeChild(filter)
|
|
|
|
})
|
|
|
|
|
2022-02-23 10:47:25 +08:00
|
|
|
it('clear filter', async () => {
|
|
|
|
const btn = wrapper.find('.el-table__column-filter-trigger')
|
|
|
|
|
|
|
|
btn.trigger('click')
|
|
|
|
await doubleWait()
|
|
|
|
const filter = document.body.querySelector('.el-table-filter')
|
|
|
|
|
|
|
|
triggerEvent(filter.querySelector('.el-checkbox'), 'click', true, false)
|
|
|
|
// confrim button
|
|
|
|
await doubleWait()
|
|
|
|
triggerEvent(
|
|
|
|
filter.querySelector('.el-table-filter__bottom button'),
|
|
|
|
'click',
|
|
|
|
true,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
await nextTick()
|
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-table__body-wrapper tbody tr').length
|
|
|
|
).toEqual(3)
|
|
|
|
wrapper.vm.$refs.table.clearFilter()
|
|
|
|
await nextTick()
|
|
|
|
expect(
|
|
|
|
wrapper.findAll('.el-table__body-wrapper tbody tr').length
|
|
|
|
).toEqual(5)
|
|
|
|
filter.parentNode.removeChild(filter)
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('click reset', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const btn = wrapper.find('.el-table__column-filter-trigger')
|
|
|
|
btn.trigger('click')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const filter = document.body.querySelector('.el-table-filter')
|
|
|
|
|
|
|
|
triggerEvent(filter.querySelector('.el-checkbox'), 'click', true, false)
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
triggerEvent(
|
|
|
|
filter.querySelectorAll('.el-table-filter__bottom button')[1],
|
|
|
|
'click',
|
|
|
|
true,
|
2021-09-04 19:29:28 +08:00
|
|
|
false
|
2020-10-20 10:31:47 +08:00
|
|
|
)
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(
|
2021-09-04 19:29:28 +08:00
|
|
|
(wrapper.vm as ComponentPublicInstance & { filters: any }).filters[
|
2020-10-20 10:31:47 +08:00
|
|
|
'director'
|
2021-09-04 19:29:28 +08:00
|
|
|
]
|
2020-10-20 10:31:47 +08:00
|
|
|
).toEqual([])
|
2022-04-19 12:46:57 +08:00
|
|
|
expect([
|
|
|
|
...filter.querySelector('.el-table-filter__bottom button').classList,
|
|
|
|
]).toContain('is-disabled')
|
2020-10-20 10:31:47 +08:00
|
|
|
filter.parentNode.removeChild(filter)
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('events', () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const createTable = function (prop = '') {
|
2020-10-20 10:31:47 +08:00
|
|
|
return mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" @${prop}="handleEvent">
|
|
|
|
<el-table-column type="selection" />
|
|
|
|
<el-table-column prop="name" />
|
|
|
|
<el-table-column prop="release" />
|
|
|
|
<el-table-column prop="director" />
|
|
|
|
<el-table-column prop="runtime"/>
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
handleEvent(...args) {
|
|
|
|
this.result = args
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return { result: '', testData: getTestData() }
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('select', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('select')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.findAll('.el-checkbox')[1].trigger('click')
|
|
|
|
expect(wrapper.vm.result.length).toEqual(2)
|
|
|
|
expect(wrapper.vm.result[1]).toHaveProperty('name')
|
|
|
|
expect(wrapper.vm.result[1]['name']).toEqual(getTestData()[0].name)
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('selection-change', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('selection-change')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.findAll('.el-checkbox')[1].trigger('click')
|
|
|
|
expect(wrapper.vm.result.length).toEqual(1)
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('cell-mouse-enter', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('cell-mouse-enter')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const cell = wrapper.findAll('.el-table__body .cell')[2] // first row
|
2021-06-12 19:38:39 +08:00
|
|
|
triggerEvent(cell.element.parentElement, 'mouseenter')
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(wrapper.vm.result.length).toEqual(4) // row, column, cell, event
|
|
|
|
expect(wrapper.vm.result[0]).toHaveProperty('name')
|
|
|
|
expect(wrapper.vm.result[0]['name']).toEqual(getTestData()[0].name)
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('cell-mouse-leave', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('cell-mouse-leave')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const cell = wrapper.findAll('.el-table__body .cell')[7] // second row
|
|
|
|
const cell2 = wrapper.findAll('.el-table__body .cell')[2] // first row
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
triggerEvent(cell2.element.parentElement, 'mouseenter')
|
|
|
|
triggerEvent(cell.element.parentElement, 'mouseleave')
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(wrapper.vm.result.length).toEqual(4) // row, column, cell, event
|
|
|
|
expect(wrapper.vm.result[0]).toHaveProperty('name')
|
|
|
|
expect(wrapper.vm.result[0]['name']).toEqual(getTestData()[0].name)
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('row-click', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('row-click')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const cell = wrapper.findAll('.el-table__body .cell')[2] // first row
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
triggerEvent(cell.element.parentElement.parentElement, 'click')
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(wrapper.vm.result.length).toEqual(3) // row, event, column
|
|
|
|
expect(wrapper.vm.result[0]).toHaveProperty('name')
|
|
|
|
expect(wrapper.vm.result[0]['name']).toEqual(getTestData()[0].name)
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('row-dblclick', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('row-dblclick')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const cell = wrapper.findAll('.el-table__body .cell')[2] // first row
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
triggerEvent(cell.element.parentElement.parentElement, 'dblclick')
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(wrapper.vm.result.length).toEqual(3) // row, event, column
|
|
|
|
expect(wrapper.vm.result[0]).toHaveProperty('name')
|
|
|
|
expect(wrapper.vm.result[0]['name']).toEqual(getTestData()[0].name)
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('header-click', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('header-click')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const cell = wrapper.findAll('.el-table__header th')[1] // header[prop='name']
|
|
|
|
cell.trigger('click')
|
|
|
|
expect(wrapper.vm.result.length).toEqual(2) // column, event
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(wrapper.vm.result[0]['name']).toBeUndefined()
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.unmount()
|
2020-12-23 16:59:31 +08:00
|
|
|
})
|
2020-10-20 10:31:47 +08:00
|
|
|
})
|
|
|
|
describe('summary row', () => {
|
2021-06-12 19:38:39 +08:00
|
|
|
it('should render', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" show-summary>
|
|
|
|
<el-table-column prop="name" />
|
|
|
|
<el-table-column prop="release"/>
|
|
|
|
<el-table-column prop="director"/>
|
|
|
|
<el-table-column prop="runtime"/>
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.testData = getTestData()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const footer = wrapper.find('.el-table__footer')
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(footer).not.toBeUndefined()
|
2021-06-12 19:38:39 +08:00
|
|
|
const cells = footer.findAll('.cell')
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(cells[cells.length - 1].text()).toEqual('459')
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('custom sum text', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" show-summary sum-text="Time">
|
|
|
|
<el-table-column prop="name" />
|
|
|
|
<el-table-column prop="release"/>
|
|
|
|
<el-table-column prop="director"/>
|
|
|
|
<el-table-column prop="runtime"/>
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.testData = getTestData()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-06-12 19:38:39 +08:00
|
|
|
const cells = wrapper.findAll('.el-table__footer .cell')
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(cells[0].text()).toEqual('Time')
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('custom summary method', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" show-summary :summary-method="getSummary">
|
|
|
|
<el-table-column prop="name" />
|
|
|
|
<el-table-column prop="release"/>
|
|
|
|
<el-table-column prop="director"/>
|
|
|
|
<el-table-column prop="runtime"/>
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.testData = getTestData()
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
getSummary(param) {
|
|
|
|
const { columns, data } = param
|
|
|
|
const result = []
|
2021-09-04 19:29:28 +08:00
|
|
|
columns.forEach((column) => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const prop = column.property
|
|
|
|
if (prop === 'release') {
|
2021-09-04 19:29:28 +08:00
|
|
|
const dates = data.map((item) => item[prop])
|
|
|
|
const releaseYears = dates.map((date) =>
|
|
|
|
Number(date.slice(0, 4))
|
|
|
|
)
|
2020-10-20 10:31:47 +08:00
|
|
|
result.push(
|
|
|
|
releaseYears.reduce((prev, curr) => {
|
|
|
|
return prev + curr
|
2021-09-04 19:29:28 +08:00
|
|
|
})
|
2020-10-20 10:31:47 +08:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
result.push('')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return result
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-06-12 19:38:39 +08:00
|
|
|
const cells = wrapper.findAll('.el-table__footer .cell')
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(cells[1].text()).toEqual('9996')
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
describe('methods', () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const createTable = function (prop = '') {
|
2020-10-20 10:31:47 +08:00
|
|
|
return mount({
|
|
|
|
components: {
|
|
|
|
ElTableColumn,
|
|
|
|
ElTable,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table ref="table" :data="testData" @${prop}="handleEvent">
|
|
|
|
<el-table-column type="selection" />
|
|
|
|
<el-table-column prop="name" />
|
|
|
|
<el-table-column prop="release" />
|
|
|
|
<el-table-column prop="director" />
|
|
|
|
<el-table-column prop="runtime"/>
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
handleEvent(selection) {
|
|
|
|
this.fireCount++
|
|
|
|
this.selection = selection
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return { selection: null, testData: getTestData(), fireCount: 0 }
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
it('toggleRowSelection', () => {
|
|
|
|
const wrapper = createTable('selection-change')
|
|
|
|
const vm = wrapper.vm
|
|
|
|
vm.$refs.table.toggleRowSelection(vm.testData[0])
|
|
|
|
expect(vm.selection.length).toEqual(1)
|
|
|
|
expect(vm.fireCount).toEqual(1)
|
|
|
|
|
|
|
|
// test use second parameter
|
|
|
|
vm.$refs.table.toggleRowSelection(vm.testData[0])
|
|
|
|
expect(vm.fireCount).toEqual(2)
|
|
|
|
|
|
|
|
vm.$refs.table.toggleRowSelection(vm.testData[0], false)
|
|
|
|
expect(vm.fireCount).toEqual(2)
|
|
|
|
expect(vm.selection.length).toEqual(0)
|
|
|
|
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('toggleAllSelection', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = createTable('selection-change')
|
|
|
|
const vm = wrapper.vm
|
|
|
|
vm.$refs.table.toggleAllSelection()
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(vm.selection.length).toEqual(5)
|
|
|
|
|
|
|
|
vm.$refs.table.toggleAllSelection()
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(vm.selection.length).toEqual(0)
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('clearSelection', () => {
|
|
|
|
const wrapper = createTable('selection-change')
|
|
|
|
const vm = wrapper.vm
|
|
|
|
vm.$refs.table.toggleRowSelection(vm.testData[0])
|
|
|
|
expect(vm.selection.length).toEqual(1)
|
|
|
|
expect(vm.fireCount).toEqual(1)
|
|
|
|
|
|
|
|
// clear selection
|
|
|
|
vm.$refs.table.clearSelection()
|
|
|
|
expect(vm.fireCount).toEqual(2)
|
|
|
|
expect(vm.selection.length).toEqual(0)
|
|
|
|
|
|
|
|
vm.$refs.table.clearSelection()
|
|
|
|
expect(vm.fireCount).toEqual(2)
|
|
|
|
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
2021-06-12 19:38:39 +08:00
|
|
|
it('sort', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTableColumn,
|
|
|
|
ElTable,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table ref="table" :data="testData" :default-sort = "{prop: 'runtime', order: 'ascending'}">
|
|
|
|
<el-table-column prop="name" />
|
|
|
|
<el-table-column prop="release" />
|
|
|
|
<el-table-column prop="director" />
|
|
|
|
<el-table-column prop="runtime"/>
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
return { testData: getTestData() }
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
const vm = wrapper.vm
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const lastCells = wrapper.findAll(
|
2021-09-04 19:29:28 +08:00
|
|
|
'.el-table__body-wrapper tbody tr td:last-child'
|
2020-10-20 10:31:47 +08:00
|
|
|
)
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(lastCells.map((node) => node.text())).toEqual([
|
|
|
|
'80',
|
|
|
|
'92',
|
|
|
|
'92',
|
2022-03-07 16:15:54 +08:00
|
|
|
'95',
|
2021-09-04 19:29:28 +08:00
|
|
|
'100',
|
|
|
|
])
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-09-04 19:29:28 +08:00
|
|
|
vm.testData = vm.testData.map((data) =>
|
|
|
|
Object.assign(data, { runtime: -data.runtime })
|
2020-10-20 10:31:47 +08:00
|
|
|
)
|
|
|
|
vm.$refs.table.sort('runtime', 'ascending')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(lastCells.map((node) => node.text())).toEqual([
|
|
|
|
'-100',
|
|
|
|
'-95',
|
|
|
|
'-92',
|
|
|
|
'-92',
|
|
|
|
'-80',
|
|
|
|
])
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('sort correct change icon', async () => {
|
|
|
|
function assertSortIconCount($el, msg, count = 1) {
|
|
|
|
const sortIconCount = $el.querySelectorAll(
|
2021-09-04 19:29:28 +08:00
|
|
|
'th.ascending, th.descending'
|
2020-10-20 10:31:47 +08:00
|
|
|
).length
|
|
|
|
expect(sortIconCount).toEqual(count)
|
|
|
|
}
|
|
|
|
|
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table ref="table" :data="testData" >
|
|
|
|
<el-table-column prop="name" sortable />
|
|
|
|
<el-table-column prop="release" sortable />
|
|
|
|
<el-table-column prop="director" sortable />
|
|
|
|
<el-table-column prop="runtime" sortable />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
return { testData: getTestData() }
|
|
|
|
},
|
|
|
|
})
|
|
|
|
const vm = wrapper.vm
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
assertSortIconCount(
|
|
|
|
wrapper.element,
|
|
|
|
'sorting icon is not empty after mount',
|
2021-09-04 19:29:28 +08:00
|
|
|
0
|
2020-10-20 10:31:47 +08:00
|
|
|
)
|
|
|
|
// manual click first column header
|
|
|
|
const elm = wrapper.find('.caret-wrapper')
|
|
|
|
elm.trigger('click')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
assertSortIconCount(
|
|
|
|
wrapper.element,
|
2021-09-04 19:29:28 +08:00
|
|
|
'sorting icon is not one after click header'
|
2020-10-20 10:31:47 +08:00
|
|
|
)
|
|
|
|
vm.$refs.table.sort('director', 'descending')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
assertSortIconCount(
|
|
|
|
wrapper.element,
|
2021-09-04 19:29:28 +08:00
|
|
|
'sorting icon is not one after call sort'
|
2020-10-20 10:31:47 +08:00
|
|
|
)
|
|
|
|
vm.$refs.table.sort('director', 'ascending')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
assertSortIconCount(
|
|
|
|
wrapper.element,
|
2021-09-04 19:29:28 +08:00
|
|
|
'sorting icon is not one after sort same column'
|
2020-10-20 10:31:47 +08:00
|
|
|
)
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('setCurrentRow', async () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<div>
|
|
|
|
<el-table ref="table" :data="testData" highlight-current-row>
|
|
|
|
<el-table-column prop="name" sortable />
|
|
|
|
<el-table-column prop="release" sortable />
|
|
|
|
<el-table-column prop="director" sortable />
|
|
|
|
<el-table-column prop="runtime" sortable />
|
|
|
|
</el-table>
|
|
|
|
<button class="clear" @click="clear">clear</button>
|
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
return { testData: getTestData() }
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
clear() {
|
|
|
|
this.$refs.table.setCurrentRow()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
const vm = wrapper.vm
|
|
|
|
|
|
|
|
vm.$refs.table.setCurrentRow(vm.testData[1])
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const secondRow = vm.$el.querySelectorAll('.el-table__row')[1]
|
2022-04-19 12:46:57 +08:00
|
|
|
expect([...secondRow.classList]).toContain('current-row')
|
2020-10-20 10:31:47 +08:00
|
|
|
|
|
|
|
vm.$el.querySelector('.clear').click()
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2022-04-19 12:46:57 +08:00
|
|
|
expect([...secondRow.classList]).not.toContain('current-row')
|
2020-10-20 10:31:47 +08:00
|
|
|
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('hover', async () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData">
|
|
|
|
<el-table-column prop="name" label="片名" fixed />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
testData: getTestData(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
const tr = wrapper.find('.el-table__body-wrapper tbody tr')
|
2022-02-06 00:37:20 +08:00
|
|
|
await tr.trigger('mouseenter')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2022-02-06 00:37:20 +08:00
|
|
|
await rAF()
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(tr.classes()).toContain('hover-row')
|
2022-02-06 00:37:20 +08:00
|
|
|
await tr.trigger('mouseleave')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
|
2022-02-06 00:37:20 +08:00
|
|
|
await rAF()
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(tr.classes()).not.toContain('hover-row')
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('highlight-current-row', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" highlight-current-row>
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" sortable />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.testData = getTestData()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
const vm = wrapper.vm
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const tr = vm.$el.querySelector('.el-table__body-wrapper tbody tr')
|
|
|
|
triggerEvent(tr, 'click', true, false)
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2022-04-19 12:46:57 +08:00
|
|
|
expect([...tr.classList]).toContain('current-row')
|
2020-10-20 10:31:47 +08:00
|
|
|
let rows = vm.$el.querySelectorAll('.el-table__body-wrapper tbody tr')
|
|
|
|
|
|
|
|
triggerEvent(rows[1], 'click', true, false)
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2022-04-19 12:46:57 +08:00
|
|
|
expect([...tr.classList]).not.toContain('current-row')
|
|
|
|
expect([...rows[1].classList]).toContain('current-row')
|
2020-10-20 10:31:47 +08:00
|
|
|
|
|
|
|
const ths = vm.$el.querySelectorAll('.el-table__header-wrapper thead th')
|
|
|
|
triggerEvent(ths[3], 'click', true, false)
|
|
|
|
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
rows = vm.$el.querySelectorAll('.el-table__body-wrapper tbody tr')
|
|
|
|
|
2022-04-19 12:46:57 +08:00
|
|
|
expect([...rows[1].classList]).not.toContain('current-row')
|
|
|
|
expect([...rows[3].classList]).toContain('current-row')
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('keep highlight row when data change', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" highlight-current-row row-key="release">
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" sortable />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
testData: getTestData(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
const vm = wrapper.vm
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
let rows = vm.$el.querySelectorAll('.el-table__body-wrapper tbody tr')
|
|
|
|
triggerEvent(rows[2], 'click', true, false)
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2022-04-19 12:46:57 +08:00
|
|
|
expect([...rows[2].classList]).toContain('current-row')
|
2020-10-20 10:31:47 +08:00
|
|
|
const data = getTestData()
|
|
|
|
data.splice(0, 0, {
|
|
|
|
id: 8,
|
|
|
|
name: 'Monsters, Inc.',
|
|
|
|
release: '2018-02-01',
|
|
|
|
director: 'Peter Docter',
|
|
|
|
runtime: 92,
|
|
|
|
})
|
|
|
|
data[2].name = 'Modified Name'
|
|
|
|
vm.testData = data
|
|
|
|
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
rows = vm.$el.querySelectorAll('.el-table__body-wrapper tbody tr')
|
2022-04-19 12:46:57 +08:00
|
|
|
expect([...rows[3].classList]).toContain('current-row')
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('keep highlight row after sort', async () => {
|
2020-10-20 10:31:47 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" row-key="release" highlight-current-row >
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" sortable />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
testData: getTestData(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
const vm = wrapper.vm
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
const rows = vm.$el.querySelectorAll('.el-table__body-wrapper tbody tr')
|
2020-10-20 10:31:47 +08:00
|
|
|
triggerEvent(rows[1], 'click', true, false)
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2022-04-19 12:46:57 +08:00
|
|
|
expect([...rows[1].classList]).toContain('current-row')
|
2021-05-13 17:55:04 +08:00
|
|
|
triggerEvent(rows[3], 'click', true, false)
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2022-04-19 12:46:57 +08:00
|
|
|
expect([...rows[3].classList]).toContain('current-row')
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('table append is visible in viewport if height is 100%', async () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="[]" height="100%">
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" />
|
|
|
|
<template #append>
|
|
|
|
<div class="append-content" style="height: 48px;">
|
|
|
|
append 区域始终出现在视图内
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const emptyBlockEl = wrapper.find('.el-table__empty-block')
|
|
|
|
expect(emptyBlockEl.attributes('style')).toContain('height: 100%')
|
|
|
|
wrapper.unmount()
|
|
|
|
})
|
|
|
|
|
2021-06-12 21:21:43 +08:00
|
|
|
describe('rowKey & index', () => {
|
|
|
|
it('key type is string', async () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" row-key="release" highlight-current-row >
|
|
|
|
<el-table-column type="index" />
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" sortable />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
testData: getTestData(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-06-12 21:21:43 +08:00
|
|
|
const rows = wrapper.findAll('.el-table__row')
|
|
|
|
rows.forEach((row, index) => {
|
|
|
|
const cell = row.find('td')
|
|
|
|
expect(cell.text()).toMatch(`${index + 1}`)
|
|
|
|
})
|
2021-06-10 13:33:07 +08:00
|
|
|
})
|
2021-06-12 21:21:43 +08:00
|
|
|
it('with expand row', async () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" row-key="release" highlight-current-row >
|
|
|
|
<el-table-column type="index" />
|
|
|
|
<el-table-column type="expand">
|
|
|
|
<template #default="props">
|
|
|
|
<span class="index">{{ props.$index }}</span>
|
|
|
|
<span class="director">{{ props.row.director }}</span>
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" sortable />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
testData: getTestData(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-06-12 21:21:43 +08:00
|
|
|
const rows = wrapper.findAll('.el-table__row')
|
|
|
|
rows.forEach((row, index) => {
|
|
|
|
const cell = row.find('td')
|
|
|
|
expect(cell.text()).toMatch(`${index + 1}`)
|
|
|
|
})
|
|
|
|
let index = 0
|
|
|
|
for (const row of rows) {
|
|
|
|
const expandCell = row.findAll('td')[1]
|
|
|
|
const triggerIcon = expandCell.find('.el-table__expand-icon')
|
|
|
|
triggerIcon.trigger('click')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-06-12 21:21:43 +08:00
|
|
|
const cell = row.find('td')
|
|
|
|
expect(cell.text()).toMatch(`${++index}`)
|
|
|
|
triggerIcon.trigger('click')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-06-12 21:21:43 +08:00
|
|
|
}
|
2021-06-10 13:33:07 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-10-20 10:31:47 +08:00
|
|
|
describe('tree', () => {
|
|
|
|
let wrapper: VueWrapper<ComponentPublicInstance>
|
|
|
|
afterEach(() => wrapper?.unmount())
|
|
|
|
it('render tree structual data', async () => {
|
|
|
|
wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTableColumn,
|
|
|
|
ElTable,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" row-key="release">
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
const testData = getTestData() as any
|
|
|
|
testData[1].children = [
|
|
|
|
{
|
|
|
|
name: "A Bug's Life copy 1",
|
|
|
|
release: '1998-11-25-1',
|
|
|
|
director: 'John Lasseter',
|
|
|
|
runtime: 95,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "A Bug's Life copy 2",
|
|
|
|
release: '1998-11-25-2',
|
|
|
|
director: 'John Lasseter',
|
|
|
|
runtime: 95,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
return {
|
2021-09-04 19:29:28 +08:00
|
|
|
testData,
|
2020-10-20 10:31:47 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const rows = wrapper.findAll('.el-table__row')
|
|
|
|
expect(rows.length).toEqual(7)
|
2022-03-31 10:27:21 +08:00
|
|
|
// validate placeholder
|
|
|
|
expect(wrapper.findAll('.el-table__placeholder').length).toBe(6)
|
2020-10-20 10:31:47 +08:00
|
|
|
const childRows = wrapper.findAll('.el-table__row--level-1')
|
|
|
|
expect(childRows.length).toEqual(2)
|
2021-09-04 19:29:28 +08:00
|
|
|
childRows.forEach((item) => {
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(item.attributes('style')).toContain('display: none')
|
|
|
|
})
|
|
|
|
wrapper.find('.el-table__expand-icon').trigger('click')
|
|
|
|
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-09-04 19:29:28 +08:00
|
|
|
childRows.forEach((item) => {
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(item.attributes('style')).toEqual('')
|
2020-10-20 10:31:47 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('load substree row data', async () => {
|
|
|
|
wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" row-key="release" lazy :load="load">
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
const testData = getTestData() as any
|
|
|
|
testData[testData.length - 1].children = [
|
|
|
|
{
|
|
|
|
name: "A Bug's Life copy 1",
|
|
|
|
release: '2008-1-25-1',
|
|
|
|
director: 'John Lasseter',
|
|
|
|
runtime: 95,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
testData[1].hasChildren = true
|
|
|
|
return {
|
2021-09-04 19:29:28 +08:00
|
|
|
testData,
|
2020-10-20 10:31:47 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
load(row, treeNode, resolve) {
|
|
|
|
resolve([
|
|
|
|
{
|
|
|
|
name: "A Bug's Life copy 1",
|
|
|
|
release: '1998-11-25-1',
|
|
|
|
director: 'John Lasseter',
|
|
|
|
runtime: 95,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "A Bug's Life copy 2",
|
|
|
|
release: '1998-11-25-2',
|
|
|
|
director: 'John Lasseter',
|
|
|
|
runtime: 95,
|
|
|
|
},
|
|
|
|
])
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const expandIcon = wrapper.find('.el-table__expand-icon')
|
|
|
|
expandIcon.trigger('click')
|
|
|
|
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(expandIcon.classes()).toContain('el-table__expand-icon--expanded')
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(wrapper.findAll('.el-table__row').length).toEqual(8)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('tree-props & default-expand-all & expand-change', async () => {
|
2022-04-19 12:46:57 +08:00
|
|
|
const spy = vi.fn()
|
2020-10-20 10:31:47 +08:00
|
|
|
wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table
|
|
|
|
:data="testData" lazy default-expand-all row-key="release" :tree-props="{children: 'childrenTest', hasChildren: 'hasChildrenTest'}"
|
|
|
|
:load="load" @expand-change="change">
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
const testData = getTestData() as any
|
|
|
|
testData[testData.length - 1].childrenTest = [
|
|
|
|
{
|
|
|
|
name: "A Bug's Life copy 1",
|
|
|
|
release: '2008-1-25-1',
|
|
|
|
director: 'John Lasseter',
|
|
|
|
runtime: 95,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
testData[1].hasChildrenTest = true
|
|
|
|
return {
|
2021-09-04 19:29:28 +08:00
|
|
|
testData,
|
2020-10-20 10:31:47 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
load(row, treeNode, resolve) {
|
|
|
|
resolve([
|
|
|
|
{
|
|
|
|
name: "A Bug's Life copy 1",
|
|
|
|
release: '1998-11-25-1',
|
|
|
|
director: 'John Lasseter',
|
|
|
|
runtime: 95,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "A Bug's Life copy 2",
|
|
|
|
release: '1998-11-25-2',
|
|
|
|
director: 'John Lasseter',
|
|
|
|
runtime: 95,
|
|
|
|
},
|
|
|
|
])
|
|
|
|
},
|
|
|
|
change: spy,
|
|
|
|
},
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const childRows = wrapper.findAll('.el-table__row--level-1')
|
2021-09-04 19:29:28 +08:00
|
|
|
childRows.forEach((item) => {
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(item.attributes('style')).toBeUndefined()
|
2020-10-20 10:31:47 +08:00
|
|
|
})
|
|
|
|
const expandIcon = wrapper.find('.el-table__expand-icon')
|
|
|
|
expandIcon.trigger('click')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(
|
2021-09-04 19:29:28 +08:00
|
|
|
expandIcon.classes().includes('el-table__expand-icon--expanded')
|
2021-05-13 17:55:04 +08:00
|
|
|
).toBeTruthy()
|
2020-10-20 10:31:47 +08:00
|
|
|
expect(wrapper.findAll('.el-table__row').length).toEqual(8)
|
2021-06-12 17:10:24 +08:00
|
|
|
expect(spy.mock.calls[0][0]).toBeInstanceOf(Object)
|
|
|
|
expect(spy.mock.calls[0][1]).toBeTruthy()
|
2020-10-20 10:31:47 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
it('expand-row-keys & toggleRowExpansion', async () => {
|
|
|
|
wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" row-key="release" lazy :load="load" :expand-row-keys="['2003-5-30']" ref="table">
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
const testData = getTestData() as any
|
|
|
|
testData[testData.length - 1].children = [
|
|
|
|
{
|
|
|
|
name: "A Bug's Life copy 1",
|
|
|
|
release: '2003-5-30-1',
|
|
|
|
director: 'John Lasseter',
|
|
|
|
runtime: 95,
|
|
|
|
hasChildren: true,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
return {
|
2021-09-04 19:29:28 +08:00
|
|
|
testData,
|
2020-10-20 10:31:47 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
load(row, treeNode, resolve) {
|
|
|
|
resolve([
|
|
|
|
{
|
|
|
|
name: "A Bug's Life copy 1",
|
|
|
|
release: '2003-5-30-2',
|
|
|
|
director: 'John Lasseter',
|
|
|
|
runtime: 95,
|
|
|
|
},
|
|
|
|
])
|
|
|
|
},
|
|
|
|
closeExpandRow() {
|
|
|
|
const testData = this.testData
|
|
|
|
const row = testData[testData.length - 1].children[0]
|
|
|
|
this.$refs.table.toggleRowExpansion(row)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2020-10-20 10:31:47 +08:00
|
|
|
const childRows = wrapper.findAll('.el-table__row--level-1')
|
2021-09-04 19:29:28 +08:00
|
|
|
childRows.forEach((item) => {
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(item.attributes('style')).toBeUndefined()
|
2020-10-20 10:31:47 +08:00
|
|
|
})
|
|
|
|
const expandIcon = childRows[0].find('.el-table__expand-icon')
|
|
|
|
expandIcon.trigger('click')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(expandIcon.classes()).toContain('el-table__expand-icon--expanded')
|
|
|
|
;(wrapper.vm as any).closeExpandRow()
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-13 17:55:04 +08:00
|
|
|
expect(expandIcon.classes()).not.toContain(
|
2021-09-04 19:29:28 +08:00
|
|
|
'el-table__expand-icon--expanded'
|
2021-05-13 17:55:04 +08:00
|
|
|
)
|
2020-10-20 10:31:47 +08:00
|
|
|
})
|
2021-05-21 15:54:39 +08:00
|
|
|
|
2021-06-12 19:38:39 +08:00
|
|
|
it('v-if on el-table-column should patch correctly', async () => {
|
2021-05-21 15:54:39 +08:00
|
|
|
wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<div>
|
|
|
|
<button @click="hideName">hide name column</button>
|
|
|
|
<el-table :data="testData">
|
|
|
|
<el-table-column key="name" label="片名" v-if="showName">
|
|
|
|
<template #default="{ row }"><span class="name">{{ row.name }}</span></template>
|
|
|
|
</el-table-column>
|
|
|
|
<el-table-column key="release" label="发行日期" >
|
|
|
|
<template #default="{ row }"><span class="release">{{ row.release }}</span></template>
|
|
|
|
</el-table-column>
|
|
|
|
</el-table>
|
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
testData: getTestData() as any,
|
|
|
|
showName: true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
hideName() {
|
|
|
|
this.showName = false
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-21 15:54:39 +08:00
|
|
|
const firstCellSpanBeforeHide = wrapper.find('.el-table__body tr td span')
|
|
|
|
expect(firstCellSpanBeforeHide.classes().includes('name')).toBeTruthy()
|
|
|
|
wrapper.find('button').trigger('click')
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2021-05-21 15:54:39 +08:00
|
|
|
const firstCellSpanAfterHide = wrapper.find('.el-table__body tr td span')
|
|
|
|
expect(firstCellSpanAfterHide.classes().includes('release')).toBeTruthy()
|
|
|
|
})
|
2020-10-20 10:31:47 +08:00
|
|
|
})
|
2022-02-10 09:35:29 +08:00
|
|
|
|
|
|
|
it('when tableLayout is auto', async () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
components: {
|
|
|
|
ElTable,
|
|
|
|
ElTableColumn,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<el-table :data="testData" table-layout="auto">
|
|
|
|
<el-table-column prop="id" />
|
|
|
|
<el-table-column prop="name" label="片名" />
|
|
|
|
<el-table-column prop="release" label="发行日期" />
|
|
|
|
<el-table-column prop="director" label="导演" />
|
|
|
|
<el-table-column prop="runtime" label="时长(分)" />
|
|
|
|
</el-table>
|
|
|
|
`,
|
|
|
|
created() {
|
|
|
|
this.testData = getTestData()
|
|
|
|
},
|
|
|
|
})
|
2022-02-21 14:20:44 +08:00
|
|
|
await doubleWait()
|
2022-02-10 09:35:29 +08:00
|
|
|
expect(wrapper.find('.el-table__body thead').exists()).toBeTruthy()
|
|
|
|
expect(wrapper.find('.el-table__body colgroup col').exists()).toBeFalsy()
|
|
|
|
expect(wrapper.find('.el-table__body tbody').exists()).toBeTruthy()
|
|
|
|
})
|
2020-10-20 10:31:47 +08:00
|
|
|
})
|