Skip to content

Commit

Permalink
Table: not trigger sort-change event when mounted (ElemeFE#17113)
Browse files Browse the repository at this point in the history
  • Loading branch information
a631807682 authored and lzq4047 committed May 22, 2020
1 parent d1c3666 commit c81be31
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
6 changes: 3 additions & 3 deletions packages/table/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ Watcher.prototype.mutations = {
},

sort(states, options) {
const { prop, order } = options;
const { prop, order, init } = options;
if (prop) {
const column = arrayFind(states.columns, column => column.property === prop);
if (column) {
column.order = order;
this.updateSort(column, prop, order);
this.commit('changeSortCondition');
this.commit('changeSortCondition', { init });
}
}
},
Expand All @@ -89,7 +89,7 @@ Watcher.prototype.mutations = {
const ingore = { filter: true };
this.execQuery(ingore);

if (!options || !options.silent) {
if (!options || !(options.silent || options.init)) {
this.table.$emit('sort-change', {
column,
prop,
Expand Down
53 changes: 32 additions & 21 deletions test/unit/specs/table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,38 @@ describe('Table', () => {
done();
}, DELAY);
});

it('sort-change', async() => {
const vm = createVue({
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" sortable/>
</el-table>
`,

created() {
this.testData = getTestData();
},

data() {
return { testData: this.testData };
}
});

const spy = sinon.spy();
vm.$refs.table.$on('sort-change', spy);
await waitImmediate();
expect(spy.notCalled).to.be.true;// not emit when mounted

const elm = vm.$el.querySelector('.caret-wrapper');
elm.click();
await waitImmediate();
expect(spy.calledOnce).to.be.true;
destroyVM(vm);
});
});

describe('column attributes', () => {
Expand Down Expand Up @@ -1144,27 +1176,6 @@ describe('Table', () => {
}, DELAY);
}, DELAY);
});

it('sort-change', done => {
let result;
const vm = createTable('sortable="custom"', '', '', '', {
methods: {
sortChange(...args) {
result = args;
}
}
}, '@sort-change="sortChange"');
setTimeout(_ => {
const elm = vm.$el.querySelector('.caret-wrapper');

elm.click();
setTimeout(_ => {
expect(result).to.exist;
destroyVM(vm);
done();
}, DELAY);
}, DELAY);
});
});

describe('click sortable column', () => {
Expand Down

0 comments on commit c81be31

Please sign in to comment.