Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jul 29, 2020
1 parent 9beec7c commit 8ebd3d2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 99 deletions.
37 changes: 28 additions & 9 deletions packages/grid/x-grid/test/XGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ async function sleep(duration: number) {
});
}

async function raf() {
return new Promise((resolve) => {
// Chrome and Safari have a bug where calling rAF once returns the current
// frame instead of the next frame, so we need to call a double rAF here.
// See crbug.com/675795 for more.
requestAnimationFrame(() => {
requestAnimationFrame(() => {
resolve();
});
});
});
}

describe('<XGrid />', () => {
const render = createClientRender();

Expand All @@ -48,39 +61,41 @@ describe('<XGrid />', () => {

it('cell navigation with arrows ', async () => {
render(<KeyboardTest />);
await sleep(10);
await raf();
// @ts-ignore
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);
await raf();
expect(getActiveCell()).to.equal('0-1');

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

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

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

it('Home / End navigation', async () => {
render(<KeyboardTest />);
await sleep(10);
await raf();
// @ts-ignore
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);
await raf();
expect(getActiveCell()).to.equal('1-0');

fireEvent.keyDown(document.activeElement, { code: 'End' });
await sleep(100);
await raf();
expect(getActiveCell()).to.equal('1-19');
});
});
Expand All @@ -93,6 +108,7 @@ describe('<XGrid />', () => {
<XGrid
rows={[
{
id: 0,
brand: 'Nike',
},
]}
Expand All @@ -108,13 +124,16 @@ describe('<XGrid />', () => {

const { container, setProps } = render(<App />);
let rect;
// @ts-ignore
rect = container.querySelector('[role="row"][data-rowindex="0"]').getBoundingClientRect();
expect(rect.width).to.equal(300 - 2);
setProps({ width: 400 });
act(() => {
window.dispatchEvent(new window.Event('resize', {}));
});
await sleep(200);
await sleep(100); // resize debounce
await raf();
// @ts-ignore
rect = container.querySelector('[role="row"][data-rowindex="0"]').getBoundingClientRect();
expect(rect.width).to.equal(400 - 2);
});
Expand Down
97 changes: 7 additions & 90 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,7 @@
semver "^5.4.1"
source-map "^0.5.0"

"@babel/generator@^7.10.4", "@babel/generator@^7.4.0", "@babel/generator@^7.9.6":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.10.4.tgz#e49eeed9fe114b62fa5b181856a43a5e32f5f243"
integrity sha512-toLIHUIAgcQygFZRAQcsLQV3CBuX6yOIru1kJk/qqqvcRmZrYe6WavZTSG+bB8MxhnL9YPf+pKQfuiP161q7ng==
dependencies:
"@babel/types" "^7.10.4"
jsesc "^2.5.1"
lodash "^4.17.13"
source-map "^0.5.0"

"@babel/generator@^7.6.2":
"@babel/generator@^7.10.4", "@babel/generator@^7.4.0", "@babel/generator@^7.6.2", "@babel/generator@^7.9.6":
version "7.10.5"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.10.5.tgz#1b903554bc8c583ee8d25f1e8969732e6b829a69"
integrity sha512-3vXxr3FEW7E7lJZiWQ3bM4+v/Vyr9C+hpolQ8BGFr9Y8Ri2tFLWTixmwKBafDujO1WVah4fhZBeU1bieKdghig==
Expand Down Expand Up @@ -987,18 +977,7 @@
"@babel/helper-plugin-utils" "^7.10.4"
"@babel/plugin-transform-typescript" "^7.10.4"

"@babel/register@^7.0.0":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/register/-/register-7.10.4.tgz#53004ba8b04c4af3cbd84508e03ad150669746e4"
integrity sha512-whHmgGiWNVyTVnYTSawtDWhaeYsc+noeU8Rmi+MPnbGhDYmr5QpEDMrQcIA07D2RUv0BlThPcN89XcHCqq/O4g==
dependencies:
find-cache-dir "^2.0.0"
lodash "^4.17.13"
make-dir "^2.1.0"
pirates "^4.0.0"
source-map-support "^0.5.16"

"@babel/register@^7.10.5":
"@babel/register@^7.0.0", "@babel/register@^7.10.5":
version "7.10.5"
resolved "https://registry.yarnpkg.com/@babel/register/-/register-7.10.5.tgz#354f3574895f1307f79efe37a51525e52fd38d89"
integrity sha512-eYHdLv43nyvmPn9bfNfrcC4+iYNwdQ8Pxk1MFJuU/U5LpSYl/PH4dFMazCYZDFVi8ueG3shvO+AQfLrxpYulQw==
Expand All @@ -1009,7 +988,7 @@
pirates "^4.0.0"
source-map-support "^0.5.16"

"@babel/runtime-corejs3@^7.10.2", "@babel/runtime-corejs3@^7.8.3":
"@babel/runtime-corejs3@^7.10.2":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/runtime-corejs3/-/runtime-corejs3-7.10.4.tgz#f29fc1990307c4c57b10dbd6ce667b27159d9e0d"
integrity sha512-BFlgP2SoLO9HJX9WBwN67gHWMBhDX/eDz64Jajd6mR/UAUzqrNMm99d4qHnVaKscAElZoFiPv+JpR/Siud5lXw==
Expand Down Expand Up @@ -1053,16 +1032,7 @@
globals "^11.1.0"
lodash "^4.17.13"

"@babel/types@^7.0.0", "@babel/types@^7.10.4", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.0", "@babel/types@^7.4.4", "@babel/types@^7.6.0", "@babel/types@^7.9.6":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.10.4.tgz#369517188352e18219981efd156bfdb199fff1ee"
integrity sha512-UTCFOxC3FsFHb7lkRMVvgLzaRVamXuAs2Tz4wajva4WxtVY82eZeaUBtC2Zt95FU9TiznuC0Zk35tsim8jeVpg==
dependencies:
"@babel/helper-validator-identifier" "^7.10.4"
lodash "^4.17.13"
to-fast-properties "^2.0.0"

"@babel/types@^7.10.5", "@babel/types@^7.6.1":
"@babel/types@^7.0.0", "@babel/types@^7.10.4", "@babel/types@^7.10.5", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.0", "@babel/types@^7.4.4", "@babel/types@^7.6.0", "@babel/types@^7.6.1", "@babel/types@^7.9.6":
version "7.10.5"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.10.5.tgz#d88ae7e2fde86bfbfe851d4d81afa70a997b5d15"
integrity sha512-ixV66KWfCI6GKoA/2H9v6bQdbfXEwwpOdQ8cRvb4F+eyvhlaHxWFMQB4+3d9QFJXZsiiiqVrewNV0DFEQpyT4Q==
Expand Down Expand Up @@ -2751,20 +2721,13 @@
resolved "https://registry.yarnpkg.com/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.3.tgz#5405ee8e444ed212db44e79351f0c70a582aae25"
integrity sha512-DetpxZw1fzPD5xUBrIAoplLChO2VB8DlL5Gg+I1IR9b2wPqYIca2WSUxL5g1vLeR4MsQq1NeWriXAVffV+U1Fw==

"@sinonjs/commons@^1", "@sinonjs/commons@^1.6.0", "@sinonjs/commons@^1.7.2":
"@sinonjs/commons@^1", "@sinonjs/commons@^1.6.0", "@sinonjs/commons@^1.7.0", "@sinonjs/commons@^1.7.2":
version "1.8.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.1.tgz#e7df00f98a203324f6dc7cc606cad9d4a8ab2217"
integrity sha512-892K+kWUUi3cl+LlqEWIDrhvLgdL79tECi8JZUyq6IviKy/DNhuzCRlbHUjxK89f4ypPMMaFnFuR9Ie6DoIMsw==
dependencies:
type-detect "4.0.8"

"@sinonjs/commons@^1.7.0":
version "1.8.0"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.0.tgz#c8d68821a854c555bba172f3b06959a0039b236d"
integrity sha512-wEj54PfsZ5jGSwMX68G8ZXFawcSglQSXqCftWX3ec8MDUzQdHgcKvw97awHbY0efQEL5iKUOAmmVtoYgmrSG4Q==
dependencies:
type-detect "4.0.8"

"@sinonjs/fake-timers@^6.0.0", "@sinonjs/fake-timers@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-6.0.1.tgz#293674fccb3262ac782c7aadfdeca86b10c75c40"
Expand Down Expand Up @@ -6080,7 +6043,7 @@ chokidar@^2.0.4, chokidar@^2.1.8:
optionalDependencies:
fsevents "^1.2.7"

chokidar@^3.0.0:
chokidar@^3.0.0, chokidar@^3.4.0:
version "3.4.1"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.4.1.tgz#e905bdecf10eaa0a0b1db0c664481cc4cbc22ba1"
integrity sha512-TQTJyr2stihpC4Sya9hs2Xh+O2wf+igjL36Y75xx2WdHuiICcn/XJza46Jwt0eT5hVpQOzo3FpY3cj3RVYLX0g==
Expand All @@ -6095,21 +6058,6 @@ chokidar@^3.0.0:
optionalDependencies:
fsevents "~2.1.2"

chokidar@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.4.0.tgz#b30611423ce376357c765b9b8f904b9fba3c0be8"
integrity sha512-aXAaho2VJtisB/1fg1+3nlLJqGOuewTzQpd/Tz0yTg2R0e4IGtshYvtjowyEumcBv2z+y4+kc75Mz7j5xJskcQ==
dependencies:
anymatch "~3.1.1"
braces "~3.0.2"
glob-parent "~5.1.0"
is-binary-path "~2.1.0"
is-glob "~4.0.1"
normalize-path "~3.0.0"
readdirp "~3.4.0"
optionalDependencies:
fsevents "~2.1.2"

chownr@^1.1.1, chownr@^1.1.2:
version "1.1.4"
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b"
Expand Down Expand Up @@ -7254,13 +7202,6 @@ decamelize@^1.0.0, decamelize@^1.1.0, decamelize@^1.1.2, decamelize@^1.2.0:
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
integrity sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=

decamelize@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-3.2.0.tgz#84b8e8f4f8c579f938e35e2cc7024907e0090851"
integrity sha512-4TgkVUsmmu7oCSyGBm5FvfMoACuoh9EOidm7V5/J2X2djAwwt57qb3F2KMP2ITqODTCSwb+YRV+0Zqrv18k/hw==
dependencies:
xregexp "^4.2.4"

decimal.js@^10.2.0:
version "10.2.0"
resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.2.0.tgz#39466113a9e036111d02f82489b5fd6b0b5ed231"
Expand Down Expand Up @@ -20080,13 +20021,6 @@ xmlhttprequest-ssl@~1.5.4:
resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz#c2876b06168aadc40e57d97e81191ac8f4398b3e"
integrity sha1-wodrBhaKrcQOV9l+gRkayPQ5iz4=

xregexp@^4.2.4:
version "4.3.0"
resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-4.3.0.tgz#7e92e73d9174a99a59743f67a4ce879a04b5ae50"
integrity sha512-7jXDIFXh5yJ/orPn4SXjuVrWWoi4Cr8jfV1eHv9CixKSbU+jY4mxfrBwAuDvupPNKpMUY+FeIqsVw/JLT9+B8g==
dependencies:
"@babel/runtime-corejs3" "^7.8.3"

xtend@^4.0.0, xtend@^4.0.1, xtend@~4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
Expand Down Expand Up @@ -20183,7 +20117,7 @@ yargs@^14.2.2:
y18n "^4.0.0"
yargs-parser "^15.0.1"

yargs@^15.0.2:
yargs@^15.0.2, yargs@^15.3.1:
version "15.4.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8"
integrity sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==
Expand All @@ -20200,23 +20134,6 @@ yargs@^15.0.2:
y18n "^4.0.0"
yargs-parser "^18.1.2"

yargs@^15.3.1:
version "15.4.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.0.tgz#53949fb768309bac1843de9b17b80051e9805ec2"
integrity sha512-D3fRFnZwLWp8jVAAhPZBsmeIHY8tTsb8ItV9KaAaopmC6wde2u6Yw29JBIZHXw14kgkRnYmDgmQU4FVMDlIsWw==
dependencies:
cliui "^6.0.0"
decamelize "^3.2.0"
find-up "^4.1.0"
get-caller-file "^2.0.1"
require-directory "^2.1.1"
require-main-filename "^2.0.0"
set-blocking "^2.0.0"
string-width "^4.2.0"
which-module "^2.0.0"
y18n "^4.0.0"
yargs-parser "^18.1.2"

yargs@~3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1"
Expand Down

0 comments on commit 8ebd3d2

Please sign in to comment.