afterEach(() => wrapper?.unmount())
it('render tree structual data', async () => {
wrapper = mount({
components: {
ElTableColumn,
ElTable,
},
template: `
`,
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 {
testData,
}
},
})
await nextTick()
const rows = wrapper.findAll('.el-table__row')
expect(rows.length).toEqual(7)
const childRows = wrapper.findAll('.el-table__row--level-1')
expect(childRows.length).toEqual(2)
childRows.forEach((item) => {
expect(item.attributes('style')).toContain('display: none')
})
wrapper.find('.el-table__expand-icon').trigger('click')
await nextTick()
childRows.forEach((item) => {
expect(item.attributes('style')).toEqual('')
})
})
it('load substree row data', async () => {
wrapper = mount({
components: {
ElTable,
ElTableColumn,
},
template: `
`,
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 {
testData,
}
},
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,
},
])
},
},
})
await nextTick()
const expandIcon = wrapper.find('.el-table__expand-icon')
expandIcon.trigger('click')
await nextTick()
expect(expandIcon.classes()).toContain('el-table__expand-icon--expanded')
expect(wrapper.findAll('.el-table__row').length).toEqual(8)
})
it('tree-props & default-expand-all & expand-change', async () => {
const spy = jest.fn()
wrapper = mount({
components: {
ElTable,
ElTableColumn,
},
template: `
`,
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 {
testData,
}
},
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,
},
})
await nextTick()
const childRows = wrapper.findAll('.el-table__row--level-1')
childRows.forEach((item) => {
expect(item.attributes('style')).toBeUndefined()
})
const expandIcon = wrapper.find('.el-table__expand-icon')
expandIcon.trigger('click')
await nextTick()
expect(
expandIcon.classes().includes('el-table__expand-icon--expanded')
).toBeTruthy()
expect(wrapper.findAll('.el-table__row').length).toEqual(8)
expect(spy.mock.calls[0][0]).toBeInstanceOf(Object)
expect(spy.mock.calls[0][1]).toBeTruthy()
})
it('expand-row-keys & toggleRowExpansion', async () => {
wrapper = mount({
components: {
ElTable,
ElTableColumn,
},
template: `
`,
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 {
testData,
}
},
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)
},
},
})
await nextTick()
const childRows = wrapper.findAll('.el-table__row--level-1')
childRows.forEach((item) => {
expect(item.attributes('style')).toBeUndefined()
})
const expandIcon = childRows[0].find('.el-table__expand-icon')
expandIcon.trigger('click')
await nextTick()
expect(expandIcon.classes()).toContain('el-table__expand-icon--expanded')
;(wrapper.vm as any).closeExpandRow()
await nextTick()
expect(expandIcon.classes()).not.toContain(
'el-table__expand-icon--expanded'
)
})
it('v-if on el-table-column should patch correctly', async () => {
wrapper = mount({
components: {
ElTable,
ElTableColumn,
},
template: `
{{ row.name }}
{{ row.release }}
`,
data() {
return {
testData: getTestData() as any,
showName: true,
}
},
methods: {
hideName() {
this.showName = false
},
},
})
await nextTick()
const firstCellSpanBeforeHide = wrapper.find('.el-table__body tr td span')
expect(firstCellSpanBeforeHide.classes().includes('name')).toBeTruthy()
wrapper.find('button').trigger('click')
await nextTick()
const firstCellSpanAfterHide = wrapper.find('.el-table__body tr td span')
expect(firstCellSpanAfterHide.classes().includes('release')).toBeTruthy()
})
})
})