Table: fix sort icon (#15439)

pull/16320/head
bezany 2019-06-28 06:52:35 +03:00 committed by hetech
parent 5acf0101a8
commit ef719b9652
2 changed files with 39 additions and 0 deletions

View File

@ -266,6 +266,9 @@ export default Vue.extend({
},
updateSort(column, prop, order) {
if (this.states.sortingColumn && this.states.sortingColumn !== column) {
this.states.sortingColumn.order = null;
}
this.states.sortingColumn = column;
this.states.sortProp = prop;
this.states.sortOrder = order;

View File

@ -1753,11 +1753,47 @@ describe('Table', () => {
vm.$nextTick(() => {
expect(toArray(lastCells).map(node => node.textContent))
.to.eql(['-100', '-95', '-92', '-92', '-80']);
destroyVM(vm);
done();
});
});
}, DELAY);
});
it('sort correct change icon', async() => {
function assertSortIconCount($el, msg, count = 1) {
const sortIconCount = $el.querySelectorAll('th.ascending, th.descending').length;
expect(sortIconCount).to.equal(count, msg);
}
const vm = createVue({
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() };
}
});
await waitImmediate();
assertSortIconCount(vm.$el, 'sorting icon is not empty after mount', 0);
// manual click first column header
const elm = vm.$el.querySelector('.caret-wrapper');
elm.click();
await waitImmediate();
assertSortIconCount(vm.$el, 'sorting icon is not one after click header');
vm.$refs.table.sort('director', 'descending');
await waitImmediate();
assertSortIconCount(vm.$el, 'sorting icon is not one after call sort');
vm.$refs.table.sort('director', 'ascending');
await waitImmediate();
assertSortIconCount(vm.$el, 'sorting icon is not one after sort same column');
destroyVM(vm);
});
});
it('hover', async() => {