Skip to content

Commit

Permalink
Fix test reorder-column.js (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
hangxingliu committed Jan 18, 2022
1 parent 2453206 commit c61e1fc
Showing 1 changed file with 30 additions and 36 deletions.
66 changes: 30 additions & 36 deletions test/reorder-columns.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mouseup, mousedown, mousemove, contextmenu, g } from './util.js';

export default function () {
it('Hide columns by context menu item after reordering', function (done) {
it('Hide columns by context menu item after reordering', async function () {
const data = [{ c1: 'c1', c2: 'c2', c3: 'c3', c4: 'c4', c5: 'c5' }];
const schema = Object.keys(data[0]).map((name) => ({ name, width: 50 }));
for (let i = 0; i < 3; i++) data.push(Object.assign({}, data[0]));
Expand All @@ -11,6 +11,7 @@ export default function () {
test: test,
schema,
data,
allowRowReordering: true,
showFilter: false,
});
const dnd = (x1, y1, x2, y2) => {
Expand All @@ -19,45 +20,38 @@ export default function () {
mousemove(document.body, x2, y2, grid.canvas);
mouseup(document.body, x2, y2, grid.canvas);
};
const delay = (ms = 1) => new Promise((resolve) => setTimeout(resolve, ms));
let error;
testFlows()
.catch((e) => {
error = e;
console.error(e.message);
})
.then(() => done(error));

async function testFlows() {
let contextMenuItems = [];
grid.addEventListener('contextmenu', function (e) {
contextMenuItems = e.items;
});

grid.focus();
// c1, c2, c3, c4, c5 => c2, c1, c3, c4, c5
dnd(85, 15, 125, 15);
await delay();

contextmenu(grid.canvas, 85, 10);
await delay();

const hideColumnItem = contextMenuItems.find((it) =>
it.title.startsWith('Hide '),
);
if (!hideColumnItem) throw new Error(`No menu item for hidding column`);
hideColumnItem.click(new Event('keyup'));
await delay(30);
let contextMenuItems = [];
grid.addEventListener('contextmenu', function (e) {
contextMenuItems = e.items;
});

const cells = getVisibleCells(grid);
cells.forEach((it) => {
if (it.header.name === 'c2')
throw new Error(`There are column c2 after hidding first column`);
});
}
grid.focus();
// c1, c2, c3, c4, c5 => c2, c1, c3, c4, c5
dnd(85, 15, 125, 15);
await delay();

contextmenu(grid.canvas, 85, 10);
await delay();

const hideColumnItem = contextMenuItems.find((it) =>
it.title.startsWith('Hide '),
);
if (!hideColumnItem) throw new Error(`No menu item for hidding column`);
hideColumnItem.click(new Event('keyup'));
await delay(30);

const cells = getVisibleCells(grid);
cells.forEach((it) => {
if (it.header.name === 'c2')
throw new Error(`There are column c2 after hidding first column`);
});
});
}

function delay(ms = 1) {
return new Promise((resolve) => setTimeout(resolve, ms))
}

/** @returns {any[]} */
function getVisibleCells(grid) {
return grid.visibleCells.filter(
Expand Down

0 comments on commit c61e1fc

Please sign in to comment.