@linzjs/step-ag-grid 32.7.1 → 33.0.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.
Files changed (58) hide show
  1. package/dist/src/components/gridFilter/GridFilterColumnsMultiSelect.d.ts +6 -25
  2. package/dist/step-ag-grid.cjs +117 -186
  3. package/dist/step-ag-grid.cjs.map +1 -1
  4. package/dist/step-ag-grid.esm.js +117 -186
  5. package/dist/step-ag-grid.esm.js.map +1 -1
  6. package/package.json +17 -17
  7. package/src/components/Grid.tsx +8 -10
  8. package/src/components/gridFilter/GridFilterColumnsMultiSelect.tsx +110 -199
  9. package/src/components/gridHook/useGridRangeSelection.ts +8 -6
  10. package/src/react-menu3/components/ControlledMenu.tsx +5 -3
  11. package/src/react-menu3/components/MenuList.tsx +6 -3
  12. package/src/react-menu3/hooks/useItems.ts +1 -1
  13. package/src/stories/components/ActionButton.stories.tsx +12 -11
  14. package/src/stories/decorators/withOpenInPanelDecorator.tsx +35 -0
  15. package/src/stories/grid/GridCopy.stories.tsx +38 -35
  16. package/src/stories/grid/GridDragRow.stories.tsx +41 -36
  17. package/src/stories/grid/GridFilterButtons.stories.tsx +25 -19
  18. package/src/stories/grid/GridFilterColumnsMultiSelect.stories.tsx +42 -37
  19. package/src/stories/grid/GridInlineText.stories.tsx +42 -35
  20. package/src/stories/grid/GridNoRowsOverlay.stories.tsx +28 -23
  21. package/src/stories/grid/GridNonEditableRow.stories.tsx +30 -24
  22. package/src/stories/grid/GridPinnedRow.stories.tsx +37 -31
  23. package/src/stories/grid/GridPopoutContextMenu.stories.tsx +29 -24
  24. package/src/stories/grid/GridPopoutEditBoolean.stories.tsx +89 -82
  25. package/src/stories/grid/GridPopoutEditGeneric.stories.tsx +27 -22
  26. package/src/stories/grid/GridPopoutEditGenericTextArea.stories.tsx +29 -24
  27. package/src/stories/grid/GridPopoverEditBearing.stories.tsx +30 -25
  28. package/src/stories/grid/GridPopoverEditDropDown.stories.tsx +29 -24
  29. package/src/stories/grid/GridPopoverEditMultiSelect.stories.tsx +29 -24
  30. package/src/stories/grid/GridPopoverEditMultiSelectGrid.stories.tsx +28 -24
  31. package/src/stories/grid/GridReadOnly.stories.tsx +56 -52
  32. package/src/stories/grid/GridSorting.stories.tsx +81 -79
  33. package/src/stories/grid/GridViewList.stories.tsx +31 -26
  34. package/src/stories/grid/GridViewSelectableList.stories.tsx +31 -26
  35. package/src/stories/grid/gridAutosize/GridAutoSize.stories.tsx +41 -37
  36. package/src/stories/grid/gridAutosize/GridFitSize.stories.tsx +40 -36
  37. package/src/stories/grid/gridAutosize/GridFitSizeFlex.stories.tsx +40 -36
  38. package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx +14 -6
  39. package/src/stories/grid/gridFormInteraction/GridFormDropDownInteraction.stories.tsx +74 -74
  40. package/src/stories/grid/gridFormInteraction/GridFormEditBearingCorrectionInteraction.stories.tsx +59 -59
  41. package/src/stories/grid/gridFormInteraction/GridFormEditBearingInteraction.stories.tsx +58 -58
  42. package/src/stories/grid/gridFormInteraction/GridFormMultiSelectGridInteraction.stories.tsx +62 -62
  43. package/src/stories/grid/gridFormInteraction/GridFormMultiSelectInteraction.stories.tsx +118 -118
  44. package/src/stories/grid/gridFormInteraction/GridFormPopoverMenuInteraction.stories.tsx +107 -105
  45. package/src/stories/grid/gridFormInteraction/GridFormTextAreaInteraction.stories.tsx +72 -64
  46. package/src/stories/grid/gridFormInteraction/GridFormTextInputInteraction.stories.tsx +82 -73
  47. package/src/stories/grid/gridFormStatic/GridFormDropDown.stories.tsx +12 -13
  48. package/src/stories/grid/gridFormStatic/GridFormEditBearing.stories.tsx +12 -13
  49. package/src/stories/grid/gridFormStatic/GridFormEditBearingCorrection.stories.tsx +11 -13
  50. package/src/stories/grid/gridFormStatic/GridFormMessage.stories.tsx +11 -13
  51. package/src/stories/grid/gridFormStatic/GridFormMultiSelect.stories.tsx +11 -13
  52. package/src/stories/grid/gridFormStatic/GridFormPopoverMenu.stories.tsx +11 -13
  53. package/src/stories/grid/gridFormStatic/GridFormTextArea.stories.tsx +11 -13
  54. package/src/stories/grid/gridFormStatic/GridFormTextInput.stories.tsx +11 -13
  55. package/src/stories/grid/interactions/GridKeyboardInteractions.stories.tsx +110 -107
  56. package/src/stories/react-menu/ReactMenu.stories.tsx +70 -73
  57. package/src/styles/GridLoadableCell.scss +1 -1
  58. package/src/utils/useSharedInterval.ts +3 -3
@@ -1,4 +1,4 @@
1
- import { Meta, StoryFn } from '@storybook/react-vite';
1
+ import { Meta, StoryObj } from '@storybook/react-vite';
2
2
  import { useMemo, useState } from 'react';
3
3
  import { expect } from 'storybook/test';
4
4
 
@@ -7,29 +7,9 @@ import { ChromaticAllowGridAutosize } from '../../../utils/isChromatic';
7
7
  import { findQuick } from '../../../utils/__tests__/testQuick';
8
8
  import { waitForGridReady } from '../../../utils/__tests__/storybookTestUtil';
9
9
  import { FormTest, IFormTestRow } from '../FormTest';
10
+ import { withOpenInPanelDecorator } from '../../decorators/withOpenInPanelDecorator';
10
11
 
11
- export default {
12
- title: 'Components / Grid Size',
13
- component: Grid,
14
- args: {
15
- quickFilterValue: '',
16
- selectable: true,
17
- },
18
- decorators: [
19
- (Story) => (
20
- <div style={{ width: 1024, height: 600, display: 'flex', flexDirection: 'column' }}>
21
- <GridUpdatingContextProvider>
22
- <GridContextProvider>
23
- <Story />
24
- </GridContextProvider>
25
- </GridUpdatingContextProvider>
26
- </div>
27
- ),
28
- ChromaticAllowGridAutosize,
29
- ],
30
- } as Meta<typeof Grid>;
31
-
32
- const GridPopoutEditGenericTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props: GridProps<IFormTestRow>) => {
12
+ const GridPopoutEditGenericTemplate = (props: GridProps<IFormTestRow>) => {
33
13
  const [externalSelectedItems, setExternalSelectedItems] = useState<any[]>([]);
34
14
  const columnDefs: ColDefT<IFormTestRow>[] = useMemo(
35
15
  () => [
@@ -81,20 +61,44 @@ const GridPopoutEditGenericTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props
81
61
  );
82
62
  };
83
63
 
84
- export const _FitSize = GridPopoutEditGenericTemplate.bind({});
85
- _FitSize.play = async (context) => {
86
- await waitForGridReady(context);
87
- const { canvasElement } = context;
64
+ const meta: Meta<typeof GridPopoutEditGenericTemplate> = {
65
+ title: 'Components / Grid Size',
66
+ component: GridPopoutEditGenericTemplate,
67
+ args: {
68
+ selectable: true,
69
+ },
70
+ decorators: [
71
+ (Story) => (
72
+ <div style={{ width: 1024, height: 600, display: 'flex', flexDirection: 'column' }}>
73
+ <GridUpdatingContextProvider>
74
+ <GridContextProvider>
75
+ <Story />
76
+ </GridContextProvider>
77
+ </GridUpdatingContextProvider>
78
+ </div>
79
+ ),
80
+ ChromaticAllowGridAutosize,
81
+ withOpenInPanelDecorator,
82
+ ],
83
+ };
84
+ export default meta;
85
+
86
+ type Story = StoryObj<typeof meta>;
88
87
 
89
- const idHeader = await findQuick({ selector: '.ag-header-cell[col-id="id"]' }, canvasElement);
90
- const nameHeader = await findQuick({ selector: '.ag-header-cell[col-id="name"]' }, canvasElement);
91
- const headerViewport = await findQuick({ selector: '.ag-header-viewport' }, canvasElement);
88
+ export const _FitSize: Story = {
89
+ play: async ({ canvasElement }) => {
90
+ await waitForGridReady({ canvasElement });
92
91
 
93
- const idWidth = idHeader.getBoundingClientRect().width;
94
- const nameWidth = nameHeader.getBoundingClientRect().width;
95
- const availableWidth = headerViewport.getBoundingClientRect().width;
92
+ const idHeader = await findQuick({ selector: '.ag-header-cell[col-id="id"]' }, canvasElement);
93
+ const nameHeader = await findQuick({ selector: '.ag-header-cell[col-id="name"]' }, canvasElement);
94
+ const headerViewport = await findQuick({ selector: '.ag-header-viewport' }, canvasElement);
96
95
 
97
- // Both columns default to flex: 1 under sizeColumns='fit', so they should split the container evenly
98
- await expect(Math.abs(idWidth - nameWidth)).toBeLessThanOrEqual(2);
99
- await expect(Math.abs(idWidth + nameWidth - availableWidth)).toBeLessThanOrEqual(4);
96
+ const idWidth = idHeader.getBoundingClientRect().width;
97
+ const nameWidth = nameHeader.getBoundingClientRect().width;
98
+ const availableWidth = headerViewport.getBoundingClientRect().width;
99
+
100
+ // Both columns default to flex: 1 under sizeColumns='fit', so they should split the container evenly
101
+ await expect(Math.abs(idWidth - nameWidth)).toBeLessThanOrEqual(2);
102
+ await expect(Math.abs(idWidth + nameWidth - availableWidth)).toBeLessThanOrEqual(4);
103
+ },
100
104
  };
@@ -1,4 +1,4 @@
1
- import { Meta, StoryFn } from '@storybook/react-vite';
1
+ import { Meta, StoryObj } from '@storybook/react-vite';
2
2
  import { useMemo, useState } from 'react';
3
3
  import { expect } from 'storybook/test';
4
4
 
@@ -7,29 +7,9 @@ import { ChromaticAllowGridAutosize } from '../../../utils/isChromatic';
7
7
  import { findQuick } from '../../../utils/__tests__/testQuick';
8
8
  import { waitForGridReady } from '../../../utils/__tests__/storybookTestUtil';
9
9
  import { FormTest, IFormTestRow } from '../FormTest';
10
+ import { withOpenInPanelDecorator } from '../../decorators/withOpenInPanelDecorator';
10
11
 
11
- export default {
12
- title: 'Components / Grid Size',
13
- component: Grid,
14
- args: {
15
- quickFilterValue: '',
16
- selectable: true,
17
- },
18
- decorators: [
19
- (Story) => (
20
- <div style={{ width: 1024, height: 600, display: 'flex', flexDirection: 'column' }}>
21
- <GridUpdatingContextProvider>
22
- <GridContextProvider>
23
- <Story />
24
- </GridContextProvider>
25
- </GridUpdatingContextProvider>
26
- </div>
27
- ),
28
- ChromaticAllowGridAutosize,
29
- ],
30
- } as Meta<typeof Grid>;
31
-
32
- const GridPopoutEditGenericTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props: GridProps<IFormTestRow>) => {
12
+ const GridPopoutEditGenericTemplate = (props: GridProps<IFormTestRow>) => {
33
13
  const [externalSelectedItems, setExternalSelectedItems] = useState<any[]>([]);
34
14
  const columnDefs: ColDefT<IFormTestRow>[] = useMemo(
35
15
  () => [
@@ -83,20 +63,44 @@ const GridPopoutEditGenericTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props
83
63
  );
84
64
  };
85
65
 
86
- export const _FitSizeFlex = GridPopoutEditGenericTemplate.bind({});
87
- _FitSizeFlex.play = async (context) => {
88
- await waitForGridReady(context);
89
- const { canvasElement } = context;
66
+ const meta: Meta<typeof GridPopoutEditGenericTemplate> = {
67
+ title: 'Components / Grid Size',
68
+ component: GridPopoutEditGenericTemplate,
69
+ args: {
70
+ selectable: true,
71
+ },
72
+ decorators: [
73
+ (Story) => (
74
+ <div style={{ width: 1024, height: 600, display: 'flex', flexDirection: 'column' }}>
75
+ <GridUpdatingContextProvider>
76
+ <GridContextProvider>
77
+ <Story />
78
+ </GridContextProvider>
79
+ </GridUpdatingContextProvider>
80
+ </div>
81
+ ),
82
+ ChromaticAllowGridAutosize,
83
+ withOpenInPanelDecorator,
84
+ ],
85
+ };
86
+ export default meta;
87
+
88
+ type Story = StoryObj<typeof meta>;
90
89
 
91
- const idHeader = await findQuick({ selector: '.ag-header-cell[col-id="id"]' }, canvasElement);
92
- const nameHeader = await findQuick({ selector: '.ag-header-cell[col-id="name"]' }, canvasElement);
93
- const headerViewport = await findQuick({ selector: '.ag-header-viewport' }, canvasElement);
90
+ export const _FitSizeFlex: Story = {
91
+ play: async ({ canvasElement }) => {
92
+ await waitForGridReady({ canvasElement });
94
93
 
95
- const idWidth = idHeader.getBoundingClientRect().width;
96
- const nameWidth = nameHeader.getBoundingClientRect().width;
97
- const availableWidth = headerViewport.getBoundingClientRect().width;
94
+ const idHeader = await findQuick({ selector: '.ag-header-cell[col-id="id"]' }, canvasElement);
95
+ const nameHeader = await findQuick({ selector: '.ag-header-cell[col-id="name"]' }, canvasElement);
96
+ const headerViewport = await findQuick({ selector: '.ag-header-viewport' }, canvasElement);
98
97
 
99
- // id has flex: 2, name has flex: 1, so id should be twice the width of name
100
- await expect(Math.abs(idWidth - nameWidth * 2)).toBeLessThan(2);
101
- await expect(Math.abs(idWidth + nameWidth - availableWidth)).toBeLessThan(4);
98
+ const idWidth = idHeader.getBoundingClientRect().width;
99
+ const nameWidth = nameHeader.getBoundingClientRect().width;
100
+ const availableWidth = headerViewport.getBoundingClientRect().width;
101
+
102
+ // id has flex: 2, name has flex: 1, so id should be twice the width of name
103
+ await expect(Math.abs(idWidth - nameWidth * 2)).toBeLessThan(2);
104
+ await expect(Math.abs(idWidth + nameWidth - availableWidth)).toBeLessThan(4);
105
+ },
102
106
  };
@@ -1,14 +1,14 @@
1
1
  // import '../story.scss';
2
- import '@linzjs/lui/dist/scss/base.scss';
3
2
  import '../../../../styles/Grid.scss';
4
3
 
5
4
  import {
6
- OpenPanelButton,
7
5
  Panel,
8
6
  PanelContent,
9
7
  PanelContext,
10
8
  PanelHeader,
11
9
  PanelsContextProvider,
10
+ RibbonButtonOpenPanel,
11
+ RibbonContainer,
12
12
  } from '@linzjs/windows';
13
13
  import { useContext, useEffect, useMemo, useState } from 'react';
14
14
 
@@ -52,10 +52,18 @@ export const TestPanelResizing = ({ data }: TestPanelProps) => {
52
52
 
53
53
  // #Example: Panel Invocation
54
54
  export const TestShowPanelResizingAgGrid = () => (
55
- <>
56
- <OpenPanelButton buttonText={'TestPanel resizing 1'} componentFn={() => <TestPanelResizing data={1} />} />{' '}
57
- <OpenPanelButton buttonText={'TestPanel resizing 2'} componentFn={() => <TestPanelResizing data={2} />} />
58
- </>
55
+ <RibbonContainer>
56
+ <RibbonButtonOpenPanel
57
+ title={'TestPanel resizing 1'}
58
+ icon={'ic_launch_modal'}
59
+ componentFn={() => <TestPanelResizing data={1} />}
60
+ />
61
+ <RibbonButtonOpenPanel
62
+ title={'TestPanel resizing 2'}
63
+ icon={'ic_launch_modal'}
64
+ componentFn={() => <TestPanelResizing data={2} />}
65
+ />
66
+ </RibbonContainer>
59
67
  );
60
68
 
61
69
  /* exclude */
@@ -1,8 +1,4 @@
1
- import '../../../react-menu3/styles/index.scss';
2
- import '../../../styles/index.scss';
3
- import '@linzjs/lui/dist/scss/base.scss';
4
-
5
- import { StoryFn } from '@storybook/react-vite';
1
+ import { Meta, StoryFn, StoryObj } from '@storybook/react-vite';
6
2
  import { GridPopoverContext } from '../../../contexts/GridPopoverContext';
7
3
  import { useRef } from 'react';
8
4
  import { expect, fn, userEvent, within } from 'storybook/test';
@@ -15,12 +11,6 @@ import {
15
11
  GridFormSubComponentTextInput,
16
12
  } from '../../..';
17
13
 
18
- export default {
19
- title: 'GridForm / Interactions',
20
- component: GridFormDropDown,
21
- args: {},
22
- };
23
-
24
14
  const updateValue = fn(async (saveFn: (selectedRows: any[]) => Promise<boolean>, _tabDirection: 1 | 0 | -1) =>
25
15
  saveFn([]),
26
16
  );
@@ -73,67 +63,77 @@ const Template: StoryFn<typeof GridFormDropDown<GridBaseRow, number>> = (
73
63
  );
74
64
  };
75
65
 
76
- export const GridFormDropDownInteractions_: typeof Template = Template.bind({});
77
- GridFormDropDownInteractions_.play = async ({ canvasElement }) => {
78
- const canvas = within(canvasElement);
79
-
80
- const getOption = (name: string) => canvas.findByRole('menuitem', { name });
81
-
82
- // Check enabled menu handles click
83
- const enabledMenuOption = await getOption('Enabled');
84
- expect(enabledMenuOption).toBeInTheDocument();
85
-
86
- await userEvent.click(enabledMenuOption);
87
- expect(updateValue).toHaveBeenCalled();
88
- expect(onSelectedItem).toHaveBeenCalled();
89
-
90
- // Check disabled menu ignores click
91
- updateValue.mockClear();
92
- onSelectedItem.mockClear();
93
- const disabledMenuOption = await getOption('Disabled');
94
- await userEvent.click(disabledMenuOption);
95
- expect(updateValue).not.toHaveBeenCalled();
96
- expect(onSelectedItem).not.toHaveBeenCalled();
97
-
98
- // Check sub menu works
99
- const subTextInput = await getOption('Sub menu...');
100
- expect(subTextInput).toBeInTheDocument();
101
-
102
- expect(canvas.queryByPlaceholderText('Text input')).not.toBeInTheDocument();
103
-
104
- await userEvent.click(subTextInput);
105
- const textInput = await canvas.findByPlaceholderText('Text input');
106
- expect(textInput).toBeInTheDocument();
107
- expect(await canvas.findByText('Must not be empty')).toBeInTheDocument();
108
-
109
- await userEvent.type(textInput, 'Hello');
110
- expect(await canvas.findByText('Press enter or tab to save')).toBeInTheDocument();
111
-
112
- // Test tab to save
113
- updateValue.mockClear();
114
- await userEvent.tab();
115
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), 1); // 1 = tab
116
-
117
- // Test shift+tab to save
118
- updateValue.mockClear();
119
- await userEvent.tab({ shift: true });
120
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), -1); // -1 = Shift + tab
121
-
122
- // Test escape to not save
123
- updateValue.mockClear();
124
- await userEvent.type(textInput, '{Escape}');
125
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), 0);
126
-
127
- // Test invalid value doesn't save
128
- updateValue.mockClear();
129
- await userEvent.clear(textInput);
130
- await userEvent.type(textInput, '{Enter}');
131
- expect(updateValue).not.toHaveBeenCalled();
132
-
133
- // Test filter
134
- const filterText = await canvas.findByPlaceholderText('Filter...');
135
- await userEvent.type(filterText, 'ena');
136
- expect(canvas.queryByText('Enabled')).toBeInTheDocument();
137
- expect(canvas.queryByText('Disabled')).not.toBeInTheDocument();
138
- expect(canvas.queryByText('Sub menu...')).not.toBeInTheDocument();
66
+ const meta: Meta<typeof Template> = {
67
+ title: 'GridForm / Interactions',
68
+ component: Template,
69
+ args: {},
70
+ };
71
+ export default meta;
72
+
73
+ type Story = StoryObj<typeof meta>;
74
+
75
+ export const GridFormDropDownInteractions_: Story = {
76
+ play: async ({ canvasElement }) => {
77
+ const canvas = within(canvasElement);
78
+
79
+ const getOption = (name: string) => canvas.findByRole('menuitem', { name });
80
+
81
+ // Check enabled menu handles click
82
+ const enabledMenuOption = await getOption('Enabled');
83
+ await expect(enabledMenuOption).toBeInTheDocument();
84
+
85
+ await userEvent.click(enabledMenuOption);
86
+ await expect(updateValue).toHaveBeenCalled();
87
+ await expect(onSelectedItem).toHaveBeenCalled();
88
+
89
+ // Check disabled menu ignores click
90
+ updateValue.mockClear();
91
+ onSelectedItem.mockClear();
92
+ const disabledMenuOption = await getOption('Disabled');
93
+ await userEvent.click(disabledMenuOption);
94
+ await expect(updateValue).not.toHaveBeenCalled();
95
+ await expect(onSelectedItem).not.toHaveBeenCalled();
96
+
97
+ // Check sub menu works
98
+ const subTextInput = await getOption('Sub menu...');
99
+ await expect(subTextInput).toBeInTheDocument();
100
+
101
+ await expect(canvas.queryByPlaceholderText('Text input')).not.toBeInTheDocument();
102
+
103
+ await userEvent.click(subTextInput);
104
+ const textInput = await canvas.findByPlaceholderText('Text input');
105
+ await expect(textInput).toBeInTheDocument();
106
+ await expect(await canvas.findByText('Must not be empty')).toBeInTheDocument();
107
+
108
+ await userEvent.type(textInput, 'Hello');
109
+ await expect(await canvas.findByText('Press enter or tab to save')).toBeInTheDocument();
110
+
111
+ // Test tab to save
112
+ updateValue.mockClear();
113
+ await userEvent.tab();
114
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), 1); // 1 = tab
115
+
116
+ // Test shift+tab to save
117
+ updateValue.mockClear();
118
+ await userEvent.tab({ shift: true });
119
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), -1); // -1 = Shift + tab
120
+
121
+ // Test escape to not save
122
+ updateValue.mockClear();
123
+ await userEvent.type(textInput, '{Escape}');
124
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), 0);
125
+
126
+ // Test invalid value doesn't save
127
+ updateValue.mockClear();
128
+ await userEvent.clear(textInput);
129
+ await userEvent.type(textInput, '{Enter}');
130
+ await expect(updateValue).not.toHaveBeenCalled();
131
+
132
+ // Test filter
133
+ const filterText = await canvas.findByPlaceholderText('Filter...');
134
+ await userEvent.type(filterText, 'ena');
135
+ await expect(canvas.queryByText('Enabled')).toBeInTheDocument();
136
+ await expect(canvas.queryByText('Disabled')).not.toBeInTheDocument();
137
+ await expect(canvas.queryByText('Sub menu...')).not.toBeInTheDocument();
138
+ },
139
139
  };
@@ -1,8 +1,4 @@
1
- import '../../../react-menu3/styles/index.scss';
2
- import '../../../styles/index.scss';
3
- import '@linzjs/lui/dist/scss/base.scss';
4
-
5
- import { StoryFn } from '@storybook/react-vite';
1
+ import { Meta, StoryFn, StoryObj } from '@storybook/react-vite';
6
2
  import { GridPopoverContext } from '../../../contexts/GridPopoverContext';
7
3
  import { useRef } from 'react';
8
4
  import { expect, fn, userEvent, within } from 'storybook/test';
@@ -14,12 +10,6 @@ import {
14
10
  GridPopoverEditBearingCorrectionEditorParams,
15
11
  } from '../../..';
16
12
 
17
- export default {
18
- title: 'GridForm / Interactions',
19
- component: GridFormEditBearing,
20
- args: {},
21
- };
22
-
23
13
  const updateValue = fn();
24
14
 
25
15
  const Template: StoryFn<typeof GridFormEditBearing> = (props: GridFormEditBearingProps<any>) => {
@@ -51,52 +41,62 @@ const Template: StoryFn<typeof GridFormEditBearing> = (props: GridFormEditBearin
51
41
  );
52
42
  };
53
43
 
54
- export const GridFormEditBearingCorrectionInteractions_: typeof Template = Template.bind({});
55
- GridFormEditBearingCorrectionInteractions_.play = async ({ canvasElement }) => {
56
- const canvas = within(canvasElement);
57
-
58
- expect(await canvas.findByText('Press enter or tab to save')).toBeInTheDocument();
59
-
60
- const inputField = canvas.getByPlaceholderText('Enter bearing correction');
61
-
62
- // Test formatting null
63
- expect(await canvas.findByText('–')).toBeInTheDocument();
64
-
65
- // Test formatting a bearing
66
- expect(inputField).toBeInTheDocument();
67
- await userEvent.type(inputField, '1.2345');
68
- expect(await canvas.findByText('+1° 23\' 45"')).toBeInTheDocument();
69
-
70
- // Test enter to save
71
- updateValue.mockClear();
72
- await userEvent.type(inputField, '{Enter}');
73
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), 0); // 0 = Enter
74
-
75
- // Test tab to save
76
- updateValue.mockClear();
77
- await userEvent.tab();
78
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), 1); // 1 = Tab
79
-
80
- // Test shift+tab to save
81
- updateValue.mockClear();
82
- await userEvent.tab({ shift: true });
83
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), -1); // -1 = Shift + tab
84
-
85
- // Test escape not to save
86
- updateValue.mockClear();
87
- await userEvent.type(inputField, '{Escape}');
88
- expect(updateValue).toHaveBeenCalledWith(expect.anything(), 0);
89
-
90
- // Test invalid value doesn't save
91
- updateValue.mockClear();
92
- await userEvent.type(inputField, 'xxx');
93
- expect(await canvas.findByText('?')).toBeInTheDocument();
94
-
95
- expect(canvas.getByText('Bearing must be a number in D.MMSSS format')).toBeInTheDocument();
96
- await userEvent.type(inputField, '{Enter}');
97
- expect(updateValue).not.toHaveBeenCalled();
98
- await userEvent.tab();
99
- expect(updateValue).not.toHaveBeenCalled();
100
- await userEvent.tab({ shift: true });
101
- expect(updateValue).not.toHaveBeenCalled();
44
+ const meta: Meta<typeof Template> = {
45
+ title: 'GridForm / Interactions',
46
+ component: Template,
47
+ args: {},
48
+ };
49
+ export default meta;
50
+
51
+ type Story = StoryObj<typeof meta>;
52
+
53
+ export const GridFormEditBearingCorrectionInteractions_: Story = {
54
+ play: async ({ canvasElement }) => {
55
+ const canvas = within(canvasElement);
56
+
57
+ await expect(await canvas.findByText('Press enter or tab to save')).toBeInTheDocument();
58
+
59
+ const inputField = canvas.getByPlaceholderText('Enter bearing correction');
60
+
61
+ // Test formatting null
62
+ await expect(await canvas.findByText('–')).toBeInTheDocument();
63
+
64
+ // Test formatting a bearing
65
+ await expect(inputField).toBeInTheDocument();
66
+ await userEvent.type(inputField, '1.2345');
67
+ await expect(await canvas.findByText('+1° 23\' 45"')).toBeInTheDocument();
68
+
69
+ // Test enter to save
70
+ updateValue.mockClear();
71
+ await userEvent.type(inputField, '{Enter}');
72
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), 0); // 0 = Enter
73
+
74
+ // Test tab to save
75
+ updateValue.mockClear();
76
+ await userEvent.tab();
77
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), 1); // 1 = Tab
78
+
79
+ // Test shift+tab to save
80
+ updateValue.mockClear();
81
+ await userEvent.tab({ shift: true });
82
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), -1); // -1 = Shift + tab
83
+
84
+ // Test escape not to save
85
+ updateValue.mockClear();
86
+ await userEvent.type(inputField, '{Escape}');
87
+ await expect(updateValue).toHaveBeenCalledWith(expect.anything(), 0);
88
+
89
+ // Test invalid value doesn't save
90
+ updateValue.mockClear();
91
+ await userEvent.type(inputField, 'xxx');
92
+ await expect(await canvas.findByText('?')).toBeInTheDocument();
93
+
94
+ await expect(canvas.getByText('Bearing must be a number in D.MMSSS format')).toBeInTheDocument();
95
+ await userEvent.type(inputField, '{Enter}');
96
+ await expect(updateValue).not.toHaveBeenCalled();
97
+ await userEvent.tab();
98
+ await expect(updateValue).not.toHaveBeenCalled();
99
+ await userEvent.tab({ shift: true });
100
+ await expect(updateValue).not.toHaveBeenCalled();
101
+ },
102
102
  };