Skip to content

Commit

Permalink
migrate a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jul 29, 2020
1 parent b7efa12 commit 9beec7c
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 142 deletions.
2 changes: 2 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = {
'babel-plugin-module-resolver',
{
root: ['./'],
extensions: ['.js', '.ts', '.tsx'],
alias: defaultAlias,
},
],
Expand All @@ -70,6 +71,7 @@ module.exports = {
'babel-plugin-module-resolver',
{
root: ['./'],
extensions: ['.js', '.ts', '.tsx'],
alias: defaultAlias,
},
],
Expand Down
73 changes: 69 additions & 4 deletions packages/grid/x-grid/test/XGrid.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import * as React from 'react';
import { createClientRender, act } from 'test/utils';
import { createClientRender, act, fireEvent } from 'test/utils';
import { expect } from 'chai';
import { XGrid } from '@material-ui/x-grid';
import { useData } from 'packages/storybook/src/hooks/useData';

function getActiveCell() {
const activeElement = document.activeElement;

if (!activeElement || !activeElement.parentElement) {
return null;
}

return `${activeElement.parentElement.getAttribute('data-rowindex')}-${activeElement.getAttribute(
'data-colindex',
)}`;
}

async function sleep(duration: number) {
return new Promise((resolve) => {
Expand All @@ -14,13 +27,65 @@ async function sleep(duration: number) {
describe('<XGrid />', () => {
const render = createClientRender();

it('should resize the width of the columns', async function test() {
before(function beforeHook() {
if (/jsdom/.test(window.navigator.userAgent)) {
// TODO: Unclear why this fails. Not important
// since a browser test gives us more confidence anyway
// Need layouting
this.skip();
}
});

describe('keyboard', () => {
const KeyboardTest = () => {
const data = useData(100, 20);
const transformColSizes = (columns) => columns.map((column) => ({ ...column, width: 60 }));

return (
<div style={{ width: 300, height: 300 }}>
<XGrid rows={data.rows} columns={transformColSizes(data.columns)} />
</div>
);
};

it('cell navigation with arrows ', async () => {
render(<KeyboardTest />);
await sleep(10);
document.querySelector('[data-rowindex="0"]').querySelector('[data-colindex="0"]').focus();
expect(getActiveCell()).to.equal('0-0');

fireEvent.keyDown(document.activeElement, { code: 'ArrowRight' });
await sleep(100);
expect(getActiveCell()).to.equal('0-1');

fireEvent.keyDown(document.activeElement, { code: 'ArrowDown' });
await sleep(100);
expect(getActiveCell()).to.equal('1-1');

fireEvent.keyDown(document.activeElement, { code: 'ArrowLeft' });
await sleep(100);
expect(getActiveCell()).to.equal('1-0');

fireEvent.keyDown(document.activeElement, { code: 'ArrowUp' });
await sleep(100);
expect(getActiveCell()).to.equal('0-0');
});

it('Home / End navigation', async () => {
render(<KeyboardTest />);
await sleep(10);
document.querySelector('[data-rowindex="1"]').querySelector('[data-colindex="1"]').focus();
expect(getActiveCell()).to.equal('1-1');

fireEvent.keyDown(document.activeElement, { code: 'Home' });
await sleep(100);
expect(getActiveCell()).to.equal('1-0');

fireEvent.keyDown(document.activeElement, { code: 'End' });
await sleep(100);
expect(getActiveCell()).to.equal('1-19');
});
});

it('should resize the width of the columns', async function test() {
function App(props) {
const { width = 300 } = props;
return (
Expand Down
4 changes: 1 addition & 3 deletions packages/license/bin/license-gen-script.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node

// eslint-disable-next-line no-global-assign
/* eslint-disable */
require = require('esm')(module);

// eslint-disable-next-line import/no-unresolved
require('../dist/cjs/license-cli').licenseGenCli(process.argv);
34 changes: 0 additions & 34 deletions packages/storybook/integration/components.test.ts

This file was deleted.

65 changes: 10 additions & 55 deletions packages/storybook/integration/keyboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,26 @@ describe('Keyboard Navigation', () => {
let browser;
const waitFnOptions = { timeout: 500 };

beforeAll(async (done) => {
beforeAll(async () => {
browser = await startBrowser();
done();
});
beforeEach(async (done) => {

beforeEach(async () => {
page = await getStoryPage(browser, '/story/x-grid-tests-columns--small-col-sizes', true);
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await page.waitFor(100);
done();
});

afterEach(async (done) => {
afterEach(async () => {
await page.close();
done();
});

afterAll(async (done) => {
afterAll(async () => {
await browser.close();
done();
});

test('Cell navigation with arrows ', async (done) => {
await page.keyboard.press('ArrowRight');
await page.waitForFunction(activeCell, waitFnOptions, 0, 1);

await page.keyboard.press('ArrowRight');
await page.waitForFunction(activeCell, waitFnOptions, 0, 2);

await page.keyboard.press('ArrowRight');
await page.waitForFunction(activeCell, waitFnOptions, 0, 3);

await page.keyboard.press('ArrowDown');
await page.waitForFunction(activeCell, waitFnOptions, 1, 3);

await page.keyboard.press('ArrowDown');
await page.waitForFunction(activeCell, waitFnOptions, 2, 3);

await page.keyboard.press('ArrowLeft');
await page.waitForFunction(activeCell, waitFnOptions, 2, 2);

await page.keyboard.press('ArrowUp');
await page.waitForFunction(activeCell, waitFnOptions, 1, 2);

done();
});

test('Home / End navigation', async (done) => {
await page.keyboard.press('End');
await page.waitForFunction(activeCell, waitFnOptions, 0, 19);

await page.keyboard.press('Home');
await page.waitForFunction(activeCell, waitFnOptions, 0, 0);

done();
});

test('CTRL Home / End navigation ', async (done) => {
test('CTRL Home / End navigation ', async () => {
await page.keyboard.down('Control');
await page.waitFor(100);
await page.keyboard.press('End');
Expand All @@ -72,21 +34,18 @@ describe('Keyboard Navigation', () => {
await page.waitFor(100);
await page.keyboard.up('Control');
await page.waitForFunction(activeCell, waitFnOptions, 0, 0);

done();
});

test('CTRL A to select all rows', async (done) => {
test('CTRL A to select all rows', async () => {
await page.keyboard.down('Control');
await page.waitFor(100);
await page.keyboard.press('a');
await page.waitFor(100);
const imageEnd = await page.screenshot();
expect(imageEnd).toMatchImageSnapshot();
done();
});

test('Shift space + arrows to select rows ', async (done) => {
test('Shift space + arrows to select rows ', async () => {
await page.keyboard.down('Shift');
await page.waitFor(100);
await page.keyboard.press('Space');
Expand All @@ -101,10 +60,9 @@ describe('Keyboard Navigation', () => {
const selectedScreen = await page.screenshot();

expect(selectedScreen).toMatchImageSnapshot();
done();
});

test('Next/Previous page', async (done) => {
test('Next/Previous page', async () => {
await page.keyboard.press('Space');
await page.waitForFunction(activeCell, waitFnOptions, 15, 0);

Expand All @@ -113,11 +71,9 @@ describe('Keyboard Navigation', () => {

await page.keyboard.press('PageUp');
await page.waitForFunction(activeCell, waitFnOptions, 15, 0);

done();
});

test('Copy to clipboard', async (done) => {
test('Copy to clipboard', async () => {
await page.keyboard.down('Shift');
await page.waitFor(100);
await page.keyboard.press('Space');
Expand Down Expand Up @@ -148,6 +104,5 @@ describe('Keyboard Navigation', () => {
'0, 17\n' +
'0, 18\n',
);
done();
});
});
75 changes: 37 additions & 38 deletions packages/storybook/integration/staticStories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import { snapshotTest } from './helper-fn';
jest.setTimeout(30000);

const stories = [
'/story/x-grid-demos-custom-components--custom-footer',
'/story/x-grid-demos-custom-components--custom-pagination',
'/story/x-grid-demos-custom-components--header-and-footer',
'/story/x-grid-demos-custom-components--icons',
'/story/x-grid-demos-custom-components--loading',
'/story/x-grid-demos-custom-components--no-rows',
'/story/x-grid-demos-custom-components--styled-columns',
'/story/x-grid-tests-columns--small-col-sizes',
'/story/x-grid-tests-columns--very-small-col-sizes',
{
Expand Down Expand Up @@ -31,73 +38,65 @@ const stories = [
},
'/story/x-grid-tests-columns--header-component',
'/story/x-grid-tests-columns--new-column-types',
'/story/x-grid-tests-dataset--no-rows',
'/story/x-grid-tests-dataset--no-rows-no-cols',
'/story/x-grid-tests-dataset--both-scroll-no-extend-and-borders',
'/story/x-grid-tests-dataset--both-scroll',
'/story/x-grid-tests-dataset--grid-100-by-100',
'/story/x-grid-tests-dataset--grid-20-by-2',
'/story/x-grid-tests-dataset--horizontal-scroll',
'/story/x-grid-tests-dataset--loading-rows-auto-height',
'/story/x-grid-tests-dataset--loading-rows',
'/story/x-grid-tests-dataset--no-rows-auto-height',
'/story/x-grid-tests-dataset--no-rows-no-cols-auto-height',
'/story/x-grid-tests-dataset--loading-rows-auto-height',
'/story/x-grid-tests-dataset--no-rows-no-cols',
'/story/x-grid-tests-dataset--no-rows',
'/story/x-grid-tests-dataset--vertical-scroll',
'/story/x-grid-tests-dataset--horizontal-scroll',
'/story/x-grid-tests-dataset--both-scroll',
'/story/x-grid-tests-dataset--both-scroll-no-extend-and-borders',
'/story/x-grid-tests-dataset--grid-20-by-2',
'/story/x-grid-tests-dataset--grid-100-by-100',

'/story/x-grid-tests-options--no-row-extend',
'/story/x-grid-tests-options--no-row-extend-cell-border',
'/story/x-grid-tests-options--auto-height-small',
'/story/x-grid-tests-options--auto-height-large',
'/story/x-grid-tests-options--auto-height-small',
'/story/x-grid-tests-options--cell-right-border',
'/story/x-grid-tests-options--column-right-border',

'/story/x-grid-tests-pagination--pagination-default',
'/story/x-grid-tests-options--no-row-extend-cell-border',
'/story/x-grid-tests-options--no-row-extend',
'/story/x-grid-tests-pagination--auto-pagination', // TODO click btns',
'/story/x-grid-tests-pagination--hidden-pagination',
'/story/x-grid-tests-pagination--page-size-100',
'/story/x-grid-tests-pagination--hidden-pagination',
'/story/x-grid-tests-pagination--page-size-100',
'/story/x-grid-tests-pagination--pagination-api-tests', // TODO click btns',
'/story/x-grid-tests-pagination--auto-pagination', // TODO click btns',

'/story/x-grid-tests-resize--resize-small-dataset',
'/story/x-grid-tests-pagination--pagination-default',
'/story/x-grid-tests-resize--resize-large-dataset',

'/story/x-grid-tests-resize--resize-small-dataset',
'/story/x-grid-tests-selection--api-pre-selected-rows',

'/story/x-grid-tests-sorting--string-sorting-desc',
'/story/x-grid-tests-sorting--string-sorting-asc',

'/story/x-grid-tests-sorting--number-sorting-asc',
'/story/x-grid-tests-sorting--number-sorting-desc',
'/story/x-grid-tests-sorting--api-multiple-sorted',
'/story/x-grid-tests-sorting--api-single-sorted',
'/story/x-grid-tests-sorting--custom-comparator',
'/story/x-grid-tests-sorting--date-sorting-asc',
'/story/x-grid-tests-sorting--date-sorting-desc',
'/story/x-grid-tests-sorting--date-time-sorting-asc',
'/story/x-grid-tests-sorting--date-time-sorting-desc',
'/story/x-grid-tests-sorting--multiple-sorting',
'/story/x-grid-tests-sorting--multiple-and-sort-index',
'/story/x-grid-tests-sorting--unsortable-last-col',
'/story/x-grid-tests-sorting--custom-comparator',
'/story/x-grid-tests-sorting--sorting-with-formatter',
'/story/x-grid-tests-sorting--api-single-sorted',
'/story/x-grid-tests-sorting--api-multiple-sorted',
'/story/x-grid-tests-sorting--multiple-sorting',
'/story/x-grid-tests-sorting--number-sorting-asc',
'/story/x-grid-tests-sorting--number-sorting-desc',
'/story/x-grid-tests-sorting--sorted-events-api',

'/story/x-grid-tests-sorting--sorting-with-formatter',
'/story/x-grid-tests-sorting--string-sorting-asc',
'/story/x-grid-tests-sorting--string-sorting-desc',
'/story/x-grid-tests-sorting--unsortable-last-col',
'/story/x-grid-tests-styling--big-rows-and-header',
'/story/x-grid-tests-styling--unset',
'/story/x-grid-tests-styling--small',
'/story/x-grid-tests-styling--column-cell-class',
'/story/x-grid-tests-styling--column-header-class',
'/story/x-grid-tests-styling--column-cell-class-rules',
'/story/x-grid-tests-styling--column-cell-class',
'/story/x-grid-tests-styling--column-cell-renderer',
'/story/x-grid-tests-styling--column-header-class',
'/story/x-grid-tests-styling--small',
'/story/x-grid-tests-styling--unset',
];

describe('snapshotTest', () => {
stories.forEach((config: any) => {
const path = typeof config === 'string' ? config : config.path;
const beforeTest = typeof config === 'string' ? undefined : config.beforeTest;

test(path, async (done) => {
test(path, async () => {
await snapshotTest(path, beforeTest);
done();
});
});
});
Loading

0 comments on commit 9beec7c

Please sign in to comment.