bezany пре 6 година
родитељ
комит
ef719b9652
2 измењених фајлова са 39 додато и 0 уклоњено
  1. 3 0
      packages/table/src/store/watcher.js
  2. 36 0
      test/unit/specs/table.spec.js

+ 3 - 0
packages/table/src/store/watcher.js

@@ -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;

+ 36 - 0
test/unit/specs/table.spec.js

@@ -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() => {