@wordpress/grid 0.7.1-next.v.202609031004.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -1
- package/README.md +38 -38
- package/build/dashboard-grid/grid-item.cjs.map +2 -2
- package/build/dashboard-grid/index.cjs.map +2 -2
- package/build/dashboard-grid/types.cjs.map +1 -1
- package/build/dashboard-lanes/index.cjs.map +2 -2
- package/build/dashboard-lanes/lanes-item.cjs.map +2 -2
- package/build/dashboard-lanes/types.cjs.map +1 -1
- package/build/dashboard-lanes/use-lane-placement.cjs.map +2 -2
- package/build/shared/grid-overlay.cjs.map +2 -2
- package/build-module/dashboard-grid/grid-item.mjs.map +2 -2
- package/build-module/dashboard-grid/index.mjs.map +2 -2
- package/build-module/dashboard-lanes/index.mjs.map +2 -2
- package/build-module/dashboard-lanes/lanes-item.mjs.map +2 -2
- package/build-module/dashboard-lanes/use-lane-placement.mjs.map +2 -2
- package/build-module/shared/grid-overlay.mjs.map +2 -2
- package/build-types/dashboard-grid/types.d.ts.map +1 -1
- package/build-types/dashboard-lanes/types.d.ts.map +1 -1
- package/package.json +13 -14
- package/src/dashboard-grid/grid-item.tsx +2 -2
- package/src/dashboard-grid/index.tsx +4 -4
- package/src/dashboard-grid/stories/index.story.tsx +6 -5
- package/src/dashboard-grid/test/item-interactions.browser.test.tsx +50 -0
- package/src/dashboard-grid/test/item-limits.jsdom.test.tsx +25 -22
- package/src/dashboard-grid/test/{keyboard-activation.jsdom.test.tsx → keyboard-activation.browser.test.tsx} +12 -31
- package/src/dashboard-grid/types.ts +4 -5
- package/src/dashboard-lanes/index.tsx +2 -2
- package/src/dashboard-lanes/lanes-item.tsx +1 -1
- package/src/dashboard-lanes/stories/index.story.tsx +2 -1
- package/src/dashboard-lanes/test/item-interactions.browser.test.tsx +50 -0
- package/src/dashboard-lanes/test/item-limits.jsdom.test.tsx +25 -22
- package/src/dashboard-lanes/test/{keyboard-activation.jsdom.test.tsx → keyboard-activation.browser.test.tsx} +12 -31
- package/src/dashboard-lanes/test/use-lane-placement.browser.test.tsx +74 -0
- package/src/dashboard-lanes/test/use-lane-placement.jsdom.test.tsx +11 -10
- package/src/dashboard-lanes/types.ts +4 -5
- package/src/dashboard-lanes/use-lane-placement.ts +1 -1
- package/src/shared/grid-overlay.tsx +1 -1
- package/src/shared/test/use-span-bounds.jsdom.test.ts +1 -0
- package/src/dashboard-grid/test/item-interactions.jsdom.test.tsx +0 -63
- package/src/dashboard-lanes/test/item-interactions.jsdom.test.tsx +0 -63
|
@@ -195,11 +195,10 @@ export type GridItemProps = {
|
|
|
195
195
|
* per-tile width floor that can reduce the count below the cap on
|
|
196
196
|
* narrow containers ("up to N columns, but never narrower than W px").
|
|
197
197
|
*/
|
|
198
|
-
export interface DashboardGridProps
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
> {
|
|
198
|
+
export interface DashboardGridProps extends Omit<
|
|
199
|
+
React.ComponentPropsWithoutRef< 'div' >,
|
|
200
|
+
'children' | 'className' | 'style'
|
|
201
|
+
> {
|
|
203
202
|
/**
|
|
204
203
|
* Array of layout items.
|
|
205
204
|
*/
|
|
@@ -254,7 +254,7 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
|
|
|
254
254
|
? Math.max(
|
|
255
255
|
1,
|
|
256
256
|
Math.min( item.width, effectiveColumns )
|
|
257
|
-
|
|
257
|
+
)
|
|
258
258
|
: 1;
|
|
259
259
|
const bounds = widthBoundsByKey.get( key );
|
|
260
260
|
map.set(
|
|
@@ -317,7 +317,7 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
|
|
|
317
317
|
actionableArea?: React.ReactNode;
|
|
318
318
|
} >,
|
|
319
319
|
{ actionableArea: undefined }
|
|
320
|
-
|
|
320
|
+
)
|
|
321
321
|
: ( child as React.ReactElement );
|
|
322
322
|
|
|
323
323
|
byKey.set( key, stripped );
|
|
@@ -5,7 +5,8 @@ import type { DashboardLanesLayoutItem } from '../types';
|
|
|
5
5
|
import type { GridOverlayRenderProps } from '../../shared/types';
|
|
6
6
|
|
|
7
7
|
const meta: Meta< typeof DashboardLanes > = {
|
|
8
|
-
|
|
8
|
+
id: 'grid-dashboardlanes',
|
|
9
|
+
title: 'Widgets/Grid/DashboardLanes',
|
|
9
10
|
component: DashboardLanes,
|
|
10
11
|
tags: [ 'status-experimental' ],
|
|
11
12
|
args: {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { render } from 'vitest-browser-react';
|
|
3
|
+
import { DashboardLanes } from '..';
|
|
4
|
+
|
|
5
|
+
async function renderItem( flags: {
|
|
6
|
+
draggable?: boolean;
|
|
7
|
+
resizable?: boolean;
|
|
8
|
+
} ) {
|
|
9
|
+
const { container } = await render(
|
|
10
|
+
<DashboardLanes
|
|
11
|
+
layout={ [ { key: 'a', width: 1, ...flags } ] }
|
|
12
|
+
columns={ 2 }
|
|
13
|
+
editMode
|
|
14
|
+
>
|
|
15
|
+
<div key="a">A</div>
|
|
16
|
+
</DashboardLanes>
|
|
17
|
+
);
|
|
18
|
+
return {
|
|
19
|
+
activator: container.querySelector(
|
|
20
|
+
'[aria-roledescription="sortable"]'
|
|
21
|
+
),
|
|
22
|
+
resizeHandle: container.querySelector(
|
|
23
|
+
'[aria-roledescription="draggable"]'
|
|
24
|
+
),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe( 'DashboardLanes item interactions', () => {
|
|
29
|
+
it( 'drags and resizes by default in edit mode', async () => {
|
|
30
|
+
const { activator, resizeHandle } = await renderItem( {} );
|
|
31
|
+
expect( activator ).toHaveAttribute( 'aria-disabled', 'false' );
|
|
32
|
+
expect( resizeHandle ).not.toBeNull();
|
|
33
|
+
} );
|
|
34
|
+
|
|
35
|
+
it( 'keeps an item in place when draggable is false', async () => {
|
|
36
|
+
const { activator, resizeHandle } = await renderItem( {
|
|
37
|
+
draggable: false,
|
|
38
|
+
} );
|
|
39
|
+
expect( activator ).toHaveAttribute( 'aria-disabled', 'true' );
|
|
40
|
+
expect( resizeHandle ).not.toBeNull();
|
|
41
|
+
} );
|
|
42
|
+
|
|
43
|
+
it( 'keeps an item at its size when resizable is false', async () => {
|
|
44
|
+
const { activator, resizeHandle } = await renderItem( {
|
|
45
|
+
resizable: false,
|
|
46
|
+
} );
|
|
47
|
+
expect( activator ).toHaveAttribute( 'aria-disabled', 'false' );
|
|
48
|
+
expect( resizeHandle ).toBeNull();
|
|
49
|
+
} );
|
|
50
|
+
} );
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
1
2
|
import { act, fireEvent, render } from '@testing-library/react';
|
|
2
3
|
import { DashboardLanes } from '..';
|
|
3
4
|
import type { DashboardLanesLayoutItem } from '../types';
|
|
@@ -8,9 +9,6 @@ class MockResizeObserver {
|
|
|
8
9
|
disconnect() {}
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
let originalResizeObserver: typeof ResizeObserver;
|
|
12
|
-
let originalGetBoundingClientRect: typeof HTMLElement.prototype.getBoundingClientRect;
|
|
13
|
-
|
|
14
12
|
function rect( left: number, top: number, width: number, height: number ) {
|
|
15
13
|
return {
|
|
16
14
|
left,
|
|
@@ -48,38 +46,39 @@ function setGeometry( containerWidth: number ) {
|
|
|
48
46
|
async function activateAndStepRight( activator: Element ) {
|
|
49
47
|
fireEvent.keyDown( activator, { code: 'Space' } );
|
|
50
48
|
act( () => {
|
|
51
|
-
|
|
49
|
+
vi.runOnlyPendingTimers();
|
|
52
50
|
} );
|
|
53
51
|
fireEvent.keyDown( activator, { code: 'ArrowRight' } );
|
|
54
52
|
fireEvent.keyDown( activator, { code: 'Space' } );
|
|
55
53
|
await act( async () => {
|
|
56
|
-
|
|
54
|
+
vi.runOnlyPendingTimers();
|
|
57
55
|
} );
|
|
58
56
|
}
|
|
59
57
|
|
|
60
58
|
beforeEach( () => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
vi.useFakeTimers();
|
|
60
|
+
vi.stubGlobal( 'ResizeObserver', MockResizeObserver );
|
|
61
|
+
vi.spyOn(
|
|
62
|
+
HTMLElement.prototype,
|
|
63
|
+
'getBoundingClientRect'
|
|
64
|
+
).mockImplementation( function ( this: HTMLElement ) {
|
|
67
65
|
// eslint-disable-next-line testing-library/no-node-access
|
|
68
66
|
const key = this.closest( '[data-wp-grid-item-key]' )?.getAttribute(
|
|
69
67
|
'data-wp-grid-item-key'
|
|
70
68
|
);
|
|
71
69
|
return ( key && itemRects[ key ] ) || containerRect;
|
|
72
|
-
};
|
|
70
|
+
} );
|
|
73
71
|
} );
|
|
74
72
|
|
|
75
73
|
afterEach( () => {
|
|
76
|
-
(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
jest.useRealTimers();
|
|
74
|
+
vi.restoreAllMocks();
|
|
75
|
+
vi.unstubAllGlobals();
|
|
76
|
+
vi.useRealTimers();
|
|
80
77
|
} );
|
|
81
78
|
|
|
82
|
-
function renderLanes(
|
|
79
|
+
function renderLanes(
|
|
80
|
+
onChangeLayout: ( layout: DashboardLanesLayoutItem[] ) => void
|
|
81
|
+
) {
|
|
83
82
|
const layout: DashboardLanesLayoutItem[] = [ { key: 'a', width: 1 } ];
|
|
84
83
|
return render(
|
|
85
84
|
<DashboardLanes
|
|
@@ -106,14 +105,17 @@ function getResizeHandle( container: HTMLElement, key: string ) {
|
|
|
106
105
|
describe( 'DashboardLanes item limits', () => {
|
|
107
106
|
it( 'renders a stored span below the floor lifted to it', () => {
|
|
108
107
|
setGeometry( 240 );
|
|
109
|
-
const { container } = renderLanes(
|
|
110
|
-
const itemA = container.querySelector
|
|
111
|
-
|
|
108
|
+
const { container } = renderLanes( vi.fn() );
|
|
109
|
+
const itemA = container.querySelector< HTMLElement >(
|
|
110
|
+
'[data-wp-grid-item-key="a"]'
|
|
111
|
+
);
|
|
112
|
+
expect( itemA?.style.gridColumn ).toBe( 'span 2' );
|
|
112
113
|
} );
|
|
113
114
|
|
|
114
115
|
it( 'resizes from the rendered span, not the stored one', async () => {
|
|
115
116
|
setGeometry( 240 );
|
|
116
|
-
const onChangeLayout =
|
|
117
|
+
const onChangeLayout =
|
|
118
|
+
vi.fn< ( layout: DashboardLanesLayoutItem[] ) => void >();
|
|
117
119
|
const { container } = renderLanes( onChangeLayout );
|
|
118
120
|
|
|
119
121
|
// One lane to the right of the rendered two-lane span.
|
|
@@ -129,7 +131,8 @@ describe( 'DashboardLanes item limits', () => {
|
|
|
129
131
|
|
|
130
132
|
it( 'commits nothing while the gesture stays inside the rendered span', async () => {
|
|
131
133
|
setGeometry( 360 );
|
|
132
|
-
const onChangeLayout =
|
|
134
|
+
const onChangeLayout =
|
|
135
|
+
vi.fn< ( layout: DashboardLanesLayoutItem[] ) => void >();
|
|
133
136
|
const { container } = renderLanes( onChangeLayout );
|
|
134
137
|
|
|
135
138
|
await activateAndStepRight( getResizeHandle( container, 'a' ) );
|
|
@@ -1,39 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { userEvent } from 'vitest/browser';
|
|
2
|
+
import { render } from 'vitest-browser-react';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
2
4
|
import { DashboardLanes } from '..';
|
|
3
5
|
|
|
4
|
-
class MockResizeObserver {
|
|
5
|
-
observed: Set< Element > = new Set();
|
|
6
|
-
observe( element: Element ) {
|
|
7
|
-
this.observed.add( element );
|
|
8
|
-
}
|
|
9
|
-
unobserve( element: Element ) {
|
|
10
|
-
this.observed.delete( element );
|
|
11
|
-
}
|
|
12
|
-
disconnect() {
|
|
13
|
-
this.observed.clear();
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
let originalResizeObserver: typeof ResizeObserver;
|
|
18
|
-
|
|
19
|
-
beforeEach( () => {
|
|
20
|
-
originalResizeObserver = global.ResizeObserver;
|
|
21
|
-
( global as unknown as { ResizeObserver: unknown } ).ResizeObserver =
|
|
22
|
-
MockResizeObserver;
|
|
23
|
-
} );
|
|
24
|
-
|
|
25
|
-
afterEach( () => {
|
|
26
|
-
( global as unknown as { ResizeObserver: unknown } ).ResizeObserver =
|
|
27
|
-
originalResizeObserver;
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
6
|
describe( 'DashboardLanes keyboard activation', () => {
|
|
31
|
-
it( 'places the dnd-kit keyboard activator on the inner wrapper, not the outer item', () => {
|
|
7
|
+
it( 'places the dnd-kit keyboard activator on the inner wrapper, not the outer item', async () => {
|
|
32
8
|
// Verifies the DOM hierarchy: keyboard activation needs the
|
|
33
9
|
// focused node and the keydown listener to share a node, so
|
|
34
10
|
// the activator must live nested inside the outer item.
|
|
35
|
-
|
|
36
|
-
const { container } = render(
|
|
11
|
+
const { container } = await render(
|
|
37
12
|
<DashboardLanes layout={ [ { key: 'a' } ] } columns={ 2 } editMode>
|
|
38
13
|
<div key="a">A</div>
|
|
39
14
|
</DashboardLanes>
|
|
@@ -55,6 +30,12 @@ describe( 'DashboardLanes keyboard activation', () => {
|
|
|
55
30
|
expect( lanesItem ).not.toBeNull();
|
|
56
31
|
expect( activator ).not.toBe( lanesItem );
|
|
57
32
|
expect( lanesItem!.contains( activator! ) ).toBe( true );
|
|
58
|
-
|
|
33
|
+
|
|
34
|
+
await userEvent.tab();
|
|
35
|
+
expect( activator ).toHaveFocus();
|
|
36
|
+
await userEvent.keyboard( '[Space]' );
|
|
37
|
+
expect( activator ).toHaveAttribute( 'aria-pressed', 'true' );
|
|
38
|
+
await userEvent.keyboard( '[Escape]' );
|
|
39
|
+
expect( activator ).not.toHaveAttribute( 'aria-pressed' );
|
|
59
40
|
} );
|
|
60
41
|
} );
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import { render } from 'vitest-browser-react';
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
import { GRID_ITEM_DATA_KEY } from '../../shared/grid-item-key';
|
|
6
|
+
import { useLanePlacement } from '../use-lane-placement';
|
|
7
|
+
|
|
8
|
+
const originalSupports = CSS.supports;
|
|
9
|
+
|
|
10
|
+
beforeEach( () => {
|
|
11
|
+
CSS.supports = ( property: string, value?: string ) => {
|
|
12
|
+
if ( property === 'display' && value === 'grid-lanes' ) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return value === undefined
|
|
16
|
+
? originalSupports( property )
|
|
17
|
+
: originalSupports( property, value );
|
|
18
|
+
};
|
|
19
|
+
} );
|
|
20
|
+
|
|
21
|
+
afterEach( () => {
|
|
22
|
+
CSS.supports = originalSupports;
|
|
23
|
+
} );
|
|
24
|
+
|
|
25
|
+
function Harness( { firstHeight }: { firstHeight: number } ) {
|
|
26
|
+
const [ container, setContainer ] = useState< HTMLDivElement | null >(
|
|
27
|
+
null
|
|
28
|
+
);
|
|
29
|
+
const items = [
|
|
30
|
+
{ key: 'a', span: 1 },
|
|
31
|
+
{ key: 'b', span: 1 },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const result = useLanePlacement( container, {
|
|
35
|
+
items,
|
|
36
|
+
lanes: 1,
|
|
37
|
+
gap: 0,
|
|
38
|
+
flowTolerance: 0,
|
|
39
|
+
rowUnit: 4,
|
|
40
|
+
} );
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div ref={ setContainer }>
|
|
44
|
+
{ items.map( ( item ) => (
|
|
45
|
+
<div
|
|
46
|
+
key={ item.key }
|
|
47
|
+
{ ...{ [ GRID_ITEM_DATA_KEY ]: item.key } }
|
|
48
|
+
data-testid={ `item-${ item.key }` }
|
|
49
|
+
style={ {
|
|
50
|
+
...result.itemStyles.get( item.key ),
|
|
51
|
+
height: item.key === 'a' ? firstHeight : 50,
|
|
52
|
+
} }
|
|
53
|
+
/>
|
|
54
|
+
) ) }
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe( 'useLanePlacement browser measurements', () => {
|
|
60
|
+
it( 'recomputes lane placement when an item resizes', async () => {
|
|
61
|
+
const view = await render( <Harness firstHeight={ 100 } /> );
|
|
62
|
+
const secondItem = screen.getByTestId( 'item-b' );
|
|
63
|
+
|
|
64
|
+
await waitFor( () => {
|
|
65
|
+
expect( secondItem ).toHaveStyle( { gridRowStart: '26' } );
|
|
66
|
+
} );
|
|
67
|
+
|
|
68
|
+
await view.rerender( <Harness firstHeight={ 200 } /> );
|
|
69
|
+
|
|
70
|
+
await waitFor( () => {
|
|
71
|
+
expect( secondItem ).toHaveStyle( { gridRowStart: '51' } );
|
|
72
|
+
} );
|
|
73
|
+
} );
|
|
74
|
+
} );
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { render, act, screen } from '@testing-library/react';
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
3
|
import { useState } from '@wordpress/element';
|
|
3
4
|
import { GRID_ITEM_DATA_KEY } from '../../shared/grid-item-key';
|
|
4
5
|
import { useLanePlacement } from '../use-lane-placement';
|
|
@@ -54,20 +55,20 @@ let originalSupports: typeof CSS.supports | undefined;
|
|
|
54
55
|
let originalRaf: typeof requestAnimationFrame;
|
|
55
56
|
|
|
56
57
|
function installMockObserver() {
|
|
57
|
-
originalResizeObserver =
|
|
58
|
+
originalResizeObserver = globalThis.ResizeObserver;
|
|
58
59
|
MockResizeObserver.reset();
|
|
59
|
-
(
|
|
60
|
+
( globalThis as unknown as { ResizeObserver: unknown } ).ResizeObserver =
|
|
60
61
|
MockResizeObserver;
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
function restoreObserver() {
|
|
64
|
-
(
|
|
65
|
+
( globalThis as unknown as { ResizeObserver: unknown } ).ResizeObserver =
|
|
65
66
|
originalResizeObserver;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
function setNativeSupport( supported: boolean ) {
|
|
69
70
|
if ( typeof CSS === 'undefined' ) {
|
|
70
|
-
(
|
|
71
|
+
( globalThis as unknown as { CSS: unknown } ).CSS = {
|
|
71
72
|
supports: () => supported,
|
|
72
73
|
};
|
|
73
74
|
return;
|
|
@@ -100,20 +101,20 @@ function restoreSupport() {
|
|
|
100
101
|
function flushRaf() {
|
|
101
102
|
// jsdom polyfills `requestAnimationFrame` via `setTimeout`; an
|
|
102
103
|
// `act` boundary lets React commit any state set inside the rAF.
|
|
103
|
-
|
|
104
|
+
vi.runAllTimers();
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
beforeEach( () => {
|
|
107
108
|
installMockObserver();
|
|
108
|
-
originalRaf =
|
|
109
|
-
|
|
109
|
+
originalRaf = globalThis.requestAnimationFrame;
|
|
110
|
+
globalThis.requestAnimationFrame = ( cb ) =>
|
|
110
111
|
setTimeout( () => cb( performance.now() ), 0 ) as unknown as number;
|
|
111
|
-
|
|
112
|
+
vi.useFakeTimers();
|
|
112
113
|
} );
|
|
113
114
|
|
|
114
115
|
afterEach( () => {
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
vi.useRealTimers();
|
|
117
|
+
globalThis.requestAnimationFrame = originalRaf;
|
|
117
118
|
restoreObserver();
|
|
118
119
|
restoreSupport();
|
|
119
120
|
} );
|
|
@@ -69,11 +69,10 @@ export type DashboardLanesLayoutItem = {
|
|
|
69
69
|
* - Both together: `columns` caps the count, `minColumnWidth` enforces
|
|
70
70
|
* a per-tile width floor that can reduce the count below the cap.
|
|
71
71
|
*/
|
|
72
|
-
export interface DashboardLanesProps
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
> {
|
|
72
|
+
export interface DashboardLanesProps extends Omit<
|
|
73
|
+
React.ComponentPropsWithoutRef< 'div' >,
|
|
74
|
+
'children' | 'className' | 'style'
|
|
75
|
+
> {
|
|
77
76
|
/**
|
|
78
77
|
* Array of layout items.
|
|
79
78
|
*/
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { render } from '@testing-library/react';
|
|
2
|
-
import { DashboardGrid } from '..';
|
|
3
|
-
|
|
4
|
-
class MockResizeObserver {
|
|
5
|
-
observe() {}
|
|
6
|
-
unobserve() {}
|
|
7
|
-
disconnect() {}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
let originalResizeObserver: typeof ResizeObserver;
|
|
11
|
-
|
|
12
|
-
beforeEach( () => {
|
|
13
|
-
originalResizeObserver = global.ResizeObserver;
|
|
14
|
-
( global as unknown as { ResizeObserver: unknown } ).ResizeObserver =
|
|
15
|
-
MockResizeObserver;
|
|
16
|
-
} );
|
|
17
|
-
|
|
18
|
-
afterEach( () => {
|
|
19
|
-
( global as unknown as { ResizeObserver: unknown } ).ResizeObserver =
|
|
20
|
-
originalResizeObserver;
|
|
21
|
-
} );
|
|
22
|
-
|
|
23
|
-
/* eslint-disable testing-library/no-container */
|
|
24
|
-
function renderItem( flags: { draggable?: boolean; resizable?: boolean } ) {
|
|
25
|
-
const { container } = render(
|
|
26
|
-
<DashboardGrid
|
|
27
|
-
layout={ [ { key: 'a', width: 1, ...flags } ] }
|
|
28
|
-
columns={ 2 }
|
|
29
|
-
editMode
|
|
30
|
-
>
|
|
31
|
-
<div key="a">A</div>
|
|
32
|
-
</DashboardGrid>
|
|
33
|
-
);
|
|
34
|
-
return {
|
|
35
|
-
activator: container.querySelector(
|
|
36
|
-
'[aria-roledescription="sortable"]'
|
|
37
|
-
),
|
|
38
|
-
resizeHandle: container.querySelector(
|
|
39
|
-
'[aria-roledescription="draggable"]'
|
|
40
|
-
),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/* eslint-enable testing-library/no-container */
|
|
44
|
-
|
|
45
|
-
describe( 'DashboardGrid item interactions', () => {
|
|
46
|
-
it( 'drags and resizes by default in edit mode', () => {
|
|
47
|
-
const { activator, resizeHandle } = renderItem( {} );
|
|
48
|
-
expect( activator ).toHaveAttribute( 'aria-disabled', 'false' );
|
|
49
|
-
expect( resizeHandle ).not.toBeNull();
|
|
50
|
-
} );
|
|
51
|
-
|
|
52
|
-
it( 'keeps an item in place when draggable is false', () => {
|
|
53
|
-
const { activator, resizeHandle } = renderItem( { draggable: false } );
|
|
54
|
-
expect( activator ).toHaveAttribute( 'aria-disabled', 'true' );
|
|
55
|
-
expect( resizeHandle ).not.toBeNull();
|
|
56
|
-
} );
|
|
57
|
-
|
|
58
|
-
it( 'keeps an item at its size when resizable is false', () => {
|
|
59
|
-
const { activator, resizeHandle } = renderItem( { resizable: false } );
|
|
60
|
-
expect( activator ).toHaveAttribute( 'aria-disabled', 'false' );
|
|
61
|
-
expect( resizeHandle ).toBeNull();
|
|
62
|
-
} );
|
|
63
|
-
} );
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { render } from '@testing-library/react';
|
|
2
|
-
import { DashboardLanes } from '..';
|
|
3
|
-
|
|
4
|
-
class MockResizeObserver {
|
|
5
|
-
observe() {}
|
|
6
|
-
unobserve() {}
|
|
7
|
-
disconnect() {}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
let originalResizeObserver: typeof ResizeObserver;
|
|
11
|
-
|
|
12
|
-
beforeEach( () => {
|
|
13
|
-
originalResizeObserver = global.ResizeObserver;
|
|
14
|
-
( global as unknown as { ResizeObserver: unknown } ).ResizeObserver =
|
|
15
|
-
MockResizeObserver;
|
|
16
|
-
} );
|
|
17
|
-
|
|
18
|
-
afterEach( () => {
|
|
19
|
-
( global as unknown as { ResizeObserver: unknown } ).ResizeObserver =
|
|
20
|
-
originalResizeObserver;
|
|
21
|
-
} );
|
|
22
|
-
|
|
23
|
-
/* eslint-disable testing-library/no-container */
|
|
24
|
-
function renderItem( flags: { draggable?: boolean; resizable?: boolean } ) {
|
|
25
|
-
const { container } = render(
|
|
26
|
-
<DashboardLanes
|
|
27
|
-
layout={ [ { key: 'a', width: 1, ...flags } ] }
|
|
28
|
-
columns={ 2 }
|
|
29
|
-
editMode
|
|
30
|
-
>
|
|
31
|
-
<div key="a">A</div>
|
|
32
|
-
</DashboardLanes>
|
|
33
|
-
);
|
|
34
|
-
return {
|
|
35
|
-
activator: container.querySelector(
|
|
36
|
-
'[aria-roledescription="sortable"]'
|
|
37
|
-
),
|
|
38
|
-
resizeHandle: container.querySelector(
|
|
39
|
-
'[aria-roledescription="draggable"]'
|
|
40
|
-
),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/* eslint-enable testing-library/no-container */
|
|
44
|
-
|
|
45
|
-
describe( 'DashboardLanes item interactions', () => {
|
|
46
|
-
it( 'drags and resizes by default in edit mode', () => {
|
|
47
|
-
const { activator, resizeHandle } = renderItem( {} );
|
|
48
|
-
expect( activator ).toHaveAttribute( 'aria-disabled', 'false' );
|
|
49
|
-
expect( resizeHandle ).not.toBeNull();
|
|
50
|
-
} );
|
|
51
|
-
|
|
52
|
-
it( 'keeps an item in place when draggable is false', () => {
|
|
53
|
-
const { activator, resizeHandle } = renderItem( { draggable: false } );
|
|
54
|
-
expect( activator ).toHaveAttribute( 'aria-disabled', 'true' );
|
|
55
|
-
expect( resizeHandle ).not.toBeNull();
|
|
56
|
-
} );
|
|
57
|
-
|
|
58
|
-
it( 'keeps an item at its size when resizable is false', () => {
|
|
59
|
-
const { activator, resizeHandle } = renderItem( { resizable: false } );
|
|
60
|
-
expect( activator ).toHaveAttribute( 'aria-disabled', 'false' );
|
|
61
|
-
expect( resizeHandle ).toBeNull();
|
|
62
|
-
} );
|
|
63
|
-
} );
|