@databricks/design-system 1.11.0 → 1.12.1
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/dist/common-1fb3eeb9.js +35 -0
- package/dist/common-1fb3eeb9.js.map +1 -0
- package/dist/common-819b45d4.js +15 -0
- package/dist/common-819b45d4.js.map +1 -0
- package/dist/design-system/DesignSystemProvider/DesignSystemProvider.d.ts.map +1 -1
- package/dist/design-system/DialogCombobox/DialogCombobox.d.ts +10 -0
- package/dist/design-system/DialogCombobox/DialogCombobox.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/DialogComboboxButtonContainer.d.ts +2 -0
- package/dist/design-system/DialogCombobox/DialogComboboxButtonContainer.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/DialogComboboxContent.d.ts +14 -0
- package/dist/design-system/DialogCombobox/DialogComboboxContent.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/DialogComboboxCountBadge.d.ts +2 -0
- package/dist/design-system/DialogCombobox/DialogComboboxCountBadge.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/DialogComboboxLoadingSpinner.d.ts +2 -0
- package/dist/design-system/DialogCombobox/DialogComboboxLoadingSpinner.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/DialogComboboxOptionControlledList.d.ts +10 -0
- package/dist/design-system/DialogCombobox/DialogComboboxOptionControlledList.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/DialogComboboxOptionList.d.ts +9 -0
- package/dist/design-system/DialogCombobox/DialogComboboxOptionList.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/DialogComboboxOptionListCheckboxItem.d.ts +11 -0
- package/dist/design-system/DialogCombobox/DialogComboboxOptionListCheckboxItem.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/DialogComboboxOptionListSearch.d.ts +7 -0
- package/dist/design-system/DialogCombobox/DialogComboboxOptionListSearch.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/DialogComboboxOptionListSelectItem.d.ts +10 -0
- package/dist/design-system/DialogCombobox/DialogComboboxOptionListSelectItem.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/DialogComboboxSectionHeader.d.ts +2 -0
- package/dist/design-system/DialogCombobox/DialogComboboxSectionHeader.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/DialogComboboxSeparator.d.ts +2 -0
- package/dist/design-system/DialogCombobox/DialogComboboxSeparator.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/DialogComboboxTrigger.d.ts +15 -0
- package/dist/design-system/DialogCombobox/DialogComboboxTrigger.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/hooks/useDialogComboboxContext.d.ts +2 -0
- package/dist/design-system/DialogCombobox/hooks/useDialogComboboxContext.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/hooks/useDialogComboboxOptionListContext.d.ts +2 -0
- package/dist/design-system/DialogCombobox/hooks/useDialogComboboxOptionListContext.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/index.d.ts +14 -0
- package/dist/design-system/DialogCombobox/index.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/providers/DialogComboboxContext.d.ts +15 -0
- package/dist/design-system/DialogCombobox/providers/DialogComboboxContext.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/providers/DialogComboboxOptionListContext.d.ts +10 -0
- package/dist/design-system/DialogCombobox/providers/DialogComboboxOptionListContext.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/shared.d.ts +3 -0
- package/dist/design-system/DialogCombobox/shared.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/tests/DialogCombobox.test.d.ts +2 -0
- package/dist/design-system/DialogCombobox/tests/DialogCombobox.test.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/tests/DialogComboboxButtonContainer.test.d.ts +2 -0
- package/dist/design-system/DialogCombobox/tests/DialogComboboxButtonContainer.test.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/tests/DialogComboboxContent.test.d.ts +2 -0
- package/dist/design-system/DialogCombobox/tests/DialogComboboxContent.test.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/tests/DialogComboboxOptionList.test.d.ts +2 -0
- package/dist/design-system/DialogCombobox/tests/DialogComboboxOptionList.test.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/tests/DialogComboboxOptionListCheckboxItem.test.d.ts +2 -0
- package/dist/design-system/DialogCombobox/tests/DialogComboboxOptionListCheckboxItem.test.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/tests/DialogComboboxOptionListSelectItem.test.d.ts +2 -0
- package/dist/design-system/DialogCombobox/tests/DialogComboboxOptionListSelectItem.test.d.ts.map +1 -0
- package/dist/design-system/DialogCombobox/tests/DialogComboboxTrigger.test.d.ts +2 -0
- package/dist/design-system/DialogCombobox/tests/DialogComboboxTrigger.test.d.ts.map +1 -0
- package/dist/design-system/Drawer/Drawer.d.ts +6 -1
- package/dist/design-system/Drawer/Drawer.d.ts.map +1 -1
- package/dist/design-system/Notification/Notification.d.ts +1 -0
- package/dist/design-system/Notification/Notification.d.ts.map +1 -1
- package/dist/design-system/NotificationV2/NotificationV2.d.ts +1 -0
- package/dist/design-system/NotificationV2/NotificationV2.d.ts.map +1 -1
- package/dist/design-system/Sidebar/Sidebar.d.ts +3 -1
- package/dist/design-system/Sidebar/Sidebar.d.ts.map +1 -1
- package/dist/design-system/Spacer/Spacer.d.ts +2 -0
- package/dist/design-system/Spacer/Spacer.d.ts.map +1 -1
- package/dist/design-system/TableUI/TableUI.test.d.ts +2 -0
- package/dist/design-system/TableUI/TableUI.test.d.ts.map +1 -0
- package/dist/design-system/TableUI/index.d.ts +114 -0
- package/dist/design-system/TableUI/index.d.ts.map +1 -0
- package/dist/design-system/ToggleButton/ToggleButton.d.ts.map +1 -1
- package/dist/design-system/index.d.ts +2 -0
- package/dist/design-system/index.d.ts.map +1 -1
- package/dist/development/index.d.ts +0 -2
- package/dist/development/index.d.ts.map +1 -1
- package/dist/development.js +5 -1311
- package/dist/development.js.map +1 -1
- package/dist/index.js +4162 -528
- package/dist/index.js.map +1 -1
- package/dist/test-utils/common.d.ts +17 -0
- package/dist/test-utils/common.d.ts.map +1 -1
- package/dist/test-utils/enzyme/index.d.ts +1 -0
- package/dist/test-utils/enzyme/index.d.ts.map +1 -1
- package/dist/test-utils/enzyme/table.d.ts +49 -0
- package/dist/test-utils/enzyme/table.d.ts.map +1 -0
- package/dist/test-utils/enzyme/table.test.d.ts +2 -0
- package/dist/test-utils/enzyme/table.test.d.ts.map +1 -0
- package/dist/test-utils/enzyme/utils.d.ts +6 -0
- package/dist/test-utils/enzyme/utils.d.ts.map +1 -1
- package/dist/test-utils/enzyme.js +123 -18
- package/dist/test-utils/enzyme.js.map +1 -1
- package/dist/test-utils/rtl/index.d.ts +1 -0
- package/dist/test-utils/rtl/index.d.ts.map +1 -1
- package/dist/test-utils/rtl/table.d.ts +50 -0
- package/dist/test-utils/rtl/table.d.ts.map +1 -0
- package/dist/test-utils/rtl/table.test.d.ts +2 -0
- package/dist/test-utils/rtl/table.test.d.ts.map +1 -0
- package/dist/test-utils/rtl.js +109 -19
- package/dist/test-utils/rtl.js.map +1 -1
- package/dist/theme/colorList.d.ts +0 -1
- package/dist/theme/colorList.d.ts.map +1 -1
- package/dist/theme/colors.d.ts +0 -1
- package/dist/theme/colors.d.ts.map +1 -1
- package/dist/useDesignSystemTheme-6e6f5867.js +441 -0
- package/dist/useDesignSystemTheme-6e6f5867.js.map +1 -0
- package/dist/useDesignSystemTheme-ac536b0f.js +443 -0
- package/dist/useDesignSystemTheme-ac536b0f.js.map +1 -0
- package/package.json +3 -3
|
@@ -8,4 +8,21 @@ export declare const selectClasses: {
|
|
|
8
8
|
option: string;
|
|
9
9
|
selector: string;
|
|
10
10
|
};
|
|
11
|
+
export interface GetTableRowByCellTextOptions {
|
|
12
|
+
columnHeaderName?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @param columns List of column names
|
|
16
|
+
* @param rows List of rows, where each row is a list of cell texts
|
|
17
|
+
* @returns Markdown formatted string representing the data
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // returns the string:
|
|
21
|
+
* // | Name | Fruit |
|
|
22
|
+
* // | --- | --- |
|
|
23
|
+
* // | Alice | Apple |
|
|
24
|
+
* // | Brady | Banana |
|
|
25
|
+
* createMarkdownTable(['Name', 'Age'], [['Alice', 'Apple'], ['Brady', 'Banana']])
|
|
26
|
+
*/
|
|
27
|
+
export declare function createMarkdownTable(columns: string[], rows: string[][]): string;
|
|
11
28
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/test-utils/common.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;CAMzB,CAAC"}
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/test-utils/common.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;CAMzB,CAAC;AAEF,MAAM,WAAW,4BAA4B;IAC3C,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,UAMtE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/test-utils/enzyme/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,mBAAoB,YAAY,SAE5D,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/test-utils/enzyme/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAE7C,cAAc,SAAS,CAAC;AAExB;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,mBAAoB,YAAY,SAE5D,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ReactWrapper } from 'enzyme';
|
|
2
|
+
import type { GetTableRowByCellTextOptions } from '../common';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the table row that contains the specified `cellText`. The `cellText`
|
|
5
|
+
* must be in the column with name `columnHeaderName` if it is specified. Otherwise,
|
|
6
|
+
* the `cellText` must be in the first column. Throws an error if either multiple
|
|
7
|
+
* rows or no rows can be found that match the given options. Also throws an error
|
|
8
|
+
* if the column with name `columnHeaderName` cannot be found.
|
|
9
|
+
*
|
|
10
|
+
* @param tableWrapper The ReactWrapper containing the table to query in.
|
|
11
|
+
* @param cellText The cell text that uniquely identifies the row.
|
|
12
|
+
* @param columnHeaderName The name of the column to search the text for. If not provided,
|
|
13
|
+
* the first column will be used.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getTableRowByCellText(tableWrapper: ReactWrapper, cellText: string, { columnHeaderName }?: GetTableRowByCellTextOptions): ReactWrapper;
|
|
16
|
+
/**
|
|
17
|
+
* Converts a Du Bois table to a markdown table string. This means that each cell
|
|
18
|
+
* is separated by a pipe (including the edges), the header row is on its own line
|
|
19
|
+
* at the top, each data row is on its own line below, and the header row is separated
|
|
20
|
+
* by a row of dashes from the data rows. This is useful for checking table contents
|
|
21
|
+
* in tests.
|
|
22
|
+
*
|
|
23
|
+
* @param tableWrapper The ReactWrapper containing the table to query in.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* The HTML table:
|
|
27
|
+
* <Table>
|
|
28
|
+
* <TableRow isHeader>
|
|
29
|
+
* <TableHeader>Name</TableHeader>
|
|
30
|
+
* <TableHeader>Fruit</TableHeader>
|
|
31
|
+
* </TableRow>
|
|
32
|
+
* <TableRow>
|
|
33
|
+
* <TableCell>Alice</TableCell>
|
|
34
|
+
* <TableCell>Apple</TableCell>
|
|
35
|
+
* </TableRow>
|
|
36
|
+
* <TableRow>
|
|
37
|
+
* <TableCell>Brady</TableCell>
|
|
38
|
+
* <TableCell>Banana</TableCell>
|
|
39
|
+
* </TableRow>
|
|
40
|
+
* </Table>
|
|
41
|
+
*
|
|
42
|
+
* The Markdown table:
|
|
43
|
+
* | Name | Fruit |
|
|
44
|
+
* | --- | --- |
|
|
45
|
+
* | Alice | Apple |
|
|
46
|
+
* | Brady | Banana |
|
|
47
|
+
*/
|
|
48
|
+
export declare function toMarkdownTable(tableWrapper: ReactWrapper): string;
|
|
49
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/test-utils/enzyme/table.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAC;AAI9D;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,MAAM,EAChB,EAAE,gBAAgB,EAAE,GAAE,4BAAiC,GACtD,YAAY,CA8Cd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,CAKlE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.test.d.ts","sourceRoot":"","sources":["../../../src/test-utils/enzyme/table.test.tsx"],"names":[],"mappings":""}
|
|
@@ -29,5 +29,11 @@ interface WaitForOptions {
|
|
|
29
29
|
* https://reactjs.org/docs/test-utils.html#act for more info on `act`.
|
|
30
30
|
*/
|
|
31
31
|
export declare function waitFor<T>(callback: () => T | Promise<T>, options?: WaitForOptions): Promise<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Finds all elements (that are rendered in the DOM) in `wrapper` that have an explicit
|
|
34
|
+
* role of `role` specified. This is similar to `getAllByRole` from @testing-library/react
|
|
35
|
+
* but is much simpler because of the shortcomings of Enzyme's API.
|
|
36
|
+
*/
|
|
37
|
+
export declare function findAllByRole(wrapper: ReactWrapper, role: string): ReactWrapper[];
|
|
32
38
|
export {};
|
|
33
39
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/test-utils/enzyme/utils.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAG3C,UAAU,YAAY;IACpB,iFAAiF;IACjF,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAChC,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9B,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,YAAY,CAAC,EAAE,YAAY,kEAS5B;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACnC,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9B,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,EAAE,IAAY,EAAE,GAAE,YAAiB,oEA0BpC;AAkBD,UAAU,cAAc;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,KAAK,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAmED;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAYrG"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/test-utils/enzyme/utils.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAG3C,UAAU,YAAY;IACpB,iFAAiF;IACjF,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAChC,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9B,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,YAAY,CAAC,EAAE,YAAY,kEAS5B;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACnC,OAAO,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9B,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,EAAE,IAAY,EAAE,GAAE,YAAiB,oEA0BpC;AAkBD,UAAU,cAAc;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,KAAK,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAmED;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC,CAYrG;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CAKjF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as selectClasses } from '../common-
|
|
1
|
+
import { s as selectClasses, c as createMarkdownTable } from '../common-1fb3eeb9.js';
|
|
2
2
|
import { act } from 'react-dom/test-utils';
|
|
3
3
|
|
|
4
4
|
// eslint-disable-next-line @databricks/no-restricted-imports-regexp
|
|
@@ -10,7 +10,7 @@ import { act } from 'react-dom/test-utils';
|
|
|
10
10
|
function findByText(wrapper, text, queryOptions) {
|
|
11
11
|
const newWrappers = findAllByText(wrapper, text, queryOptions);
|
|
12
12
|
if (newWrappers.length !== 1) {
|
|
13
|
-
throw new Error(
|
|
13
|
+
throw new Error(`Expected to find 1 node but found ${newWrappers.length} nodes for text "${text}".\n${wrapper.debug()}`);
|
|
14
14
|
}
|
|
15
15
|
return newWrappers[0];
|
|
16
16
|
}
|
|
@@ -151,6 +151,15 @@ async function waitFor(callback, options) {
|
|
|
151
151
|
return result;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Finds all elements (that are rendered in the DOM) in `wrapper` that have an explicit
|
|
156
|
+
* role of `role` specified. This is similar to `getAllByRole` from @testing-library/react
|
|
157
|
+
* but is much simpler because of the shortcomings of Enzyme's API.
|
|
158
|
+
*/
|
|
159
|
+
function findAllByRole(wrapper, role) {
|
|
160
|
+
return wrapper.find(`[role="${role}"]`).hostNodes().map(n => n);
|
|
161
|
+
}
|
|
162
|
+
|
|
154
163
|
// eslint-disable-next-line @databricks/no-restricted-imports-regexp
|
|
155
164
|
|
|
156
165
|
/**
|
|
@@ -158,7 +167,7 @@ async function waitFor(callback, options) {
|
|
|
158
167
|
* the `allowClear` prop must be set to `true`.
|
|
159
168
|
*/
|
|
160
169
|
function clearAll(getSelect) {
|
|
161
|
-
getSelect().find(
|
|
170
|
+
getSelect().find(`.${selectClasses.clear}`).hostNodes().simulate('mousedown');
|
|
162
171
|
}
|
|
163
172
|
|
|
164
173
|
/**
|
|
@@ -166,14 +175,14 @@ function clearAll(getSelect) {
|
|
|
166
175
|
* the menu is already closed or if the menu is unable to be closed.
|
|
167
176
|
*/
|
|
168
177
|
async function closeMenu(getSelect) {
|
|
169
|
-
if (!getSelect().find(
|
|
170
|
-
throw new Error(
|
|
178
|
+
if (!getSelect().find(`.${selectClasses.open}`).exists()) {
|
|
179
|
+
throw new Error(`Select is already closed\n${getSelect().debug()}`);
|
|
171
180
|
}
|
|
172
|
-
getSelect().find(
|
|
181
|
+
getSelect().find(`.${selectClasses.selector}`).simulate('mousedown');
|
|
173
182
|
await waitFor(() => {
|
|
174
183
|
const select = getSelect();
|
|
175
|
-
if (select.find(
|
|
176
|
-
throw new Error(
|
|
184
|
+
if (select.find(`.${selectClasses.open}`).exists()) {
|
|
185
|
+
throw new Error(`Select did not close\n${select.debug()}`);
|
|
177
186
|
}
|
|
178
187
|
});
|
|
179
188
|
}
|
|
@@ -185,7 +194,7 @@ function getLabelText(getSelect) {
|
|
|
185
194
|
// Trim the text to avoid weird whitespace issues non-label elements being added.
|
|
186
195
|
// For example, the input mirror is an empty span with some whitespace that is
|
|
187
196
|
// nested under the selector but does not show up in the label text.
|
|
188
|
-
return getSelect().find(
|
|
197
|
+
return getSelect().find(`.${selectClasses.selector}`).text().trim();
|
|
189
198
|
}
|
|
190
199
|
|
|
191
200
|
/**
|
|
@@ -198,7 +207,7 @@ function getLabelText(getSelect) {
|
|
|
198
207
|
async function multiSelect(getSelect, options) {
|
|
199
208
|
await openMenu(getSelect);
|
|
200
209
|
options.forEach(option => {
|
|
201
|
-
findByText(getSelect().find(
|
|
210
|
+
findByText(getSelect().find(`.${selectClasses.list}`), option).simulate('click');
|
|
202
211
|
});
|
|
203
212
|
// Close the menu to indicate that selection has finished
|
|
204
213
|
await closeMenu(getSelect);
|
|
@@ -213,7 +222,7 @@ async function multiSelect(getSelect, options) {
|
|
|
213
222
|
*/
|
|
214
223
|
async function singleSelect(getSelect, option) {
|
|
215
224
|
await openMenu(getSelect);
|
|
216
|
-
findByText(getSelect().find(
|
|
225
|
+
findByText(getSelect().find(`.${selectClasses.list}`), option).simulate('click');
|
|
217
226
|
// Menu automatically closes for a single <Select/> (no mode="multiple")
|
|
218
227
|
}
|
|
219
228
|
|
|
@@ -222,14 +231,14 @@ async function singleSelect(getSelect, option) {
|
|
|
222
231
|
* the menu is already opened or if the menu is unable to be opened.
|
|
223
232
|
*/
|
|
224
233
|
async function openMenu(getSelect) {
|
|
225
|
-
if (getSelect().find(
|
|
226
|
-
throw new Error(
|
|
234
|
+
if (getSelect().find(`.${selectClasses.open}`).exists()) {
|
|
235
|
+
throw new Error(`Select is already open\n${getSelect().debug()}`);
|
|
227
236
|
}
|
|
228
|
-
getSelect().find(
|
|
237
|
+
getSelect().find(`.${selectClasses.selector}`).simulate('mousedown');
|
|
229
238
|
await waitFor(() => {
|
|
230
239
|
const select = getSelect();
|
|
231
|
-
if (!select.find(
|
|
232
|
-
throw new Error(
|
|
240
|
+
if (!select.find(`.${selectClasses.open}`).exists()) {
|
|
241
|
+
throw new Error(`Select did not open\n${select.debug()}`);
|
|
233
242
|
}
|
|
234
243
|
});
|
|
235
244
|
}
|
|
@@ -240,7 +249,7 @@ async function openMenu(getSelect) {
|
|
|
240
249
|
*/
|
|
241
250
|
async function getAllOptions(getSelect) {
|
|
242
251
|
await openMenu(getSelect);
|
|
243
|
-
const options = getSelect().find(
|
|
252
|
+
const options = getSelect().find(`.${selectClasses.list}`).find(`.${selectClasses.option}`).map(option => option.text());
|
|
244
253
|
await closeMenu(getSelect);
|
|
245
254
|
return options;
|
|
246
255
|
}
|
|
@@ -257,6 +266,102 @@ var selectEvent = /*#__PURE__*/Object.freeze({
|
|
|
257
266
|
});
|
|
258
267
|
|
|
259
268
|
// eslint-disable-next-line @databricks/no-restricted-imports-regexp
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Returns the table row that contains the specified `cellText`. The `cellText`
|
|
272
|
+
* must be in the column with name `columnHeaderName` if it is specified. Otherwise,
|
|
273
|
+
* the `cellText` must be in the first column. Throws an error if either multiple
|
|
274
|
+
* rows or no rows can be found that match the given options. Also throws an error
|
|
275
|
+
* if the column with name `columnHeaderName` cannot be found.
|
|
276
|
+
*
|
|
277
|
+
* @param tableWrapper The ReactWrapper containing the table to query in.
|
|
278
|
+
* @param cellText The cell text that uniquely identifies the row.
|
|
279
|
+
* @param columnHeaderName The name of the column to search the text for. If not provided,
|
|
280
|
+
* the first column will be used.
|
|
281
|
+
*/
|
|
282
|
+
function getTableRowByCellText(tableWrapper, cellText) {
|
|
283
|
+
let {
|
|
284
|
+
columnHeaderName
|
|
285
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
286
|
+
let columnHeaderIndex;
|
|
287
|
+
if (columnHeaderName === undefined) {
|
|
288
|
+
columnHeaderIndex = 0;
|
|
289
|
+
} else {
|
|
290
|
+
const columnHeaders = findAllByRole(tableWrapper, 'columnheader');
|
|
291
|
+
columnHeaderIndex = columnHeaders.findIndex(n => {
|
|
292
|
+
try {
|
|
293
|
+
findByText(n, columnHeaderName);
|
|
294
|
+
return true;
|
|
295
|
+
} catch {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
if (columnHeaderIndex === -1) {
|
|
300
|
+
throw new Error(`Unable to find a column with name "${columnHeaderName}"\n${tableWrapper.debug()}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const matchingRows = findAllByRole(tableWrapper, 'row')
|
|
304
|
+
// Skip first row (table header)
|
|
305
|
+
.slice(1).filter(row => {
|
|
306
|
+
const cells = findAllByRole(row, 'cell');
|
|
307
|
+
const cell = cells[columnHeaderIndex];
|
|
308
|
+
try {
|
|
309
|
+
findByText(cell, cellText);
|
|
310
|
+
return true;
|
|
311
|
+
} catch {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
if (matchingRows.length === 0) {
|
|
316
|
+
throw new Error(`Unable to find a table row with text "${cellText}" in the column "${columnHeaderName}"\n${tableWrapper.debug()}`);
|
|
317
|
+
}
|
|
318
|
+
if (matchingRows.length > 1) {
|
|
319
|
+
throw new Error(`Found multiple table rows with text "${cellText}" in the column "${columnHeaderName}"\n${tableWrapper.debug()}`);
|
|
320
|
+
}
|
|
321
|
+
return matchingRows[0].hostNodes();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Converts a Du Bois table to a markdown table string. This means that each cell
|
|
326
|
+
* is separated by a pipe (including the edges), the header row is on its own line
|
|
327
|
+
* at the top, each data row is on its own line below, and the header row is separated
|
|
328
|
+
* by a row of dashes from the data rows. This is useful for checking table contents
|
|
329
|
+
* in tests.
|
|
330
|
+
*
|
|
331
|
+
* @param tableWrapper The ReactWrapper containing the table to query in.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* The HTML table:
|
|
335
|
+
* <Table>
|
|
336
|
+
* <TableRow isHeader>
|
|
337
|
+
* <TableHeader>Name</TableHeader>
|
|
338
|
+
* <TableHeader>Fruit</TableHeader>
|
|
339
|
+
* </TableRow>
|
|
340
|
+
* <TableRow>
|
|
341
|
+
* <TableCell>Alice</TableCell>
|
|
342
|
+
* <TableCell>Apple</TableCell>
|
|
343
|
+
* </TableRow>
|
|
344
|
+
* <TableRow>
|
|
345
|
+
* <TableCell>Brady</TableCell>
|
|
346
|
+
* <TableCell>Banana</TableCell>
|
|
347
|
+
* </TableRow>
|
|
348
|
+
* </Table>
|
|
349
|
+
*
|
|
350
|
+
* The Markdown table:
|
|
351
|
+
* | Name | Fruit |
|
|
352
|
+
* | --- | --- |
|
|
353
|
+
* | Alice | Apple |
|
|
354
|
+
* | Brady | Banana |
|
|
355
|
+
*/
|
|
356
|
+
function toMarkdownTable(tableWrapper) {
|
|
357
|
+
const [firstRow, ...restRows] = findAllByRole(tableWrapper, 'row');
|
|
358
|
+
const columns = findAllByRole(firstRow, 'columnheader').map(column => column.text());
|
|
359
|
+
const rows = restRows.map(row => findAllByRole(row, 'cell').map(cell => cell.text()));
|
|
360
|
+
return createMarkdownTable(columns, rows);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// eslint-disable-next-line @databricks/no-restricted-imports-regexp
|
|
364
|
+
|
|
260
365
|
/**
|
|
261
366
|
* Open a dropdown menu by simulating a pointerDown event on the dropdown button.
|
|
262
367
|
*
|
|
@@ -269,5 +374,5 @@ const openDropdownMenu = dropdownButton => {
|
|
|
269
374
|
});
|
|
270
375
|
};
|
|
271
376
|
|
|
272
|
-
export { openDropdownMenu, selectEvent };
|
|
377
|
+
export { getTableRowByCellText, openDropdownMenu, selectEvent, toMarkdownTable };
|
|
273
378
|
//# sourceMappingURL=enzyme.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enzyme.js","sources":["../../src/test-utils/enzyme/utils.ts","../../src/test-utils/enzyme/selectEvent.ts","../../src/test-utils/enzyme/index.ts"],"sourcesContent":["// eslint-disable-next-line @databricks/no-restricted-imports-regexp\nimport type { ReactWrapper } from 'enzyme';\nimport { act } from 'react-dom/test-utils';\n\ninterface QueryOptions {\n /** Whether to trim the whitespace from DOM text using `String.prototype.trim` */\n trim?: boolean;\n}\n\n/**\n * Finds a single element that contains the specified text in the wrapper. If\n * there are 0 or more than 1 element that contains the specified text, an error\n * is thrown. Returns the element in an enzyme wrapper.\n */\nexport function findByText<P, S, C>(\n wrapper: ReactWrapper<P, S, C>,\n text: string | RegExp,\n queryOptions?: QueryOptions\n) {\n const newWrappers = findAllByText<P, S, C>(wrapper, text, queryOptions);\n if (newWrappers.length !== 1) {\n throw new Error(\n `Expected to find 1 node but found ${newWrappers.length} nodes for text \"${text}\".\\n${wrapper.debug()}`\n );\n }\n return newWrappers[0];\n}\n\n/**\n * Finds all elements that contain the specified text. To avoid duplicate results,\n * only the parents of text nodes are returned.\n */\nexport function findAllByText<P, S, C>(\n wrapper: ReactWrapper<P, S, C>,\n text: string | RegExp,\n { trim = false }: QueryOptions = {}\n) {\n const textNodes = wrapper.findWhere((n) => {\n if (n.type() !== undefined) {\n return false;\n }\n\n let nodeText = n.text();\n if (trim) {\n nodeText = nodeText.trim();\n }\n\n return typeof text === 'string' ? nodeText === text : text.test(nodeText);\n });\n const newWrappers = textNodes.map((n) => {\n const textNodeParent = n.parents().first();\n if (textNodeParent.name() === 'FormattedMessage') {\n // Try not to return FormattedMessage since it breaks `simulate` due to a bug in `enzyme-adapter-react-17`\n // Similar to https://github.com/wojtekmaj/enzyme-adapter-react-17/issues/45\n const formattedMessageParents = textNodeParent.parents();\n return formattedMessageParents.length > 0 ? formattedMessageParents.first() : textNodeParent;\n } else {\n return textNodeParent;\n }\n });\n return newWrappers;\n}\n\n// We need to keep ref to original setTimeout to avoid SinonJS fake timers if enabled\nconst originalSetTimeout = window.setTimeout;\n\n/**\n * This is so the stack trace the developer sees is one that's\n * closer to their code (because async stack traces are hard to follow).\n *\n * The code is taken from\n * https://github.com/testing-library/dom-testing-library/blob/f7b5c33c44632fba\n * 1579cb44f9f175be1ec46087/src/wait-for.js#L15-L19\n */\nfunction copyStackTrace(target: Error, source: Error) {\n // eslint-disable-next-line no-param-reassign\n target.stack = source.stack!.replace(source.message, target.message);\n}\n\ninterface WaitForOptions {\n interval?: number;\n stackTraceError?: Error;\n timeout?: number;\n}\n\n/**\n * Run an expectation until it succeeds or reaches the timeout. The timeout of 1500ms\n * is chosen to be under the default Karma test timeout of 2000ms. This function will\n * not work properly if fake timers are being used (since it expects the real setTimeout).\n *\n * The code is taken from\n * https://github.com/TheBrainFamily/wait-for-expect/blob/master/src/index.ts,\n * with slight modifications to support Karma (instead of Jest).\n *\n *\n * Example\n * The <App /> component does not render the header synchronously.\n * Therefore, we cannot check that the wrapper's text is equal to the string\n * immediately--this assertion will fail and cause the test to fail. To\n * remediate this issue, we can run the expectation until it succeeds:\n *\n * function App() {\n * const [value, setValue] = useState(null);\n * useEffect(() => {\n * const timeoutId = setTimeout(() => setValue(\"some value\"), 100);\n * return () => clearTimeout(timeoutId);\n * }, []);\n * return value === null ? null : <h1>The value is: {value}</h1>;\n * }\n *\n * it('renders value', async () => {\n * const wrapper = mount(<App />);\n * await waitFor(() =>\n * wrapper.update();\n * expect(wrapper.text()).to.equal(\"The value is: some value\")\n * );\n * });\n */\nfunction _waitFor<T>(\n f: () => T | Promise<T>,\n { interval = 50, stackTraceError, timeout = 1500 }: WaitForOptions = {}\n): Promise<T> {\n const maxTries = Math.ceil(timeout / interval);\n let tries = 0;\n return new Promise((resolve, reject) => {\n const rejectOrRerun = (error: Error) => {\n if (tries > maxTries) {\n if (stackTraceError !== undefined) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n originalSetTimeout(runExpectation, interval);\n };\n\n function runExpectation() {\n tries += 1;\n try {\n Promise.resolve(f()).then(resolve).catch(rejectOrRerun);\n } catch (error) {\n // @ts-expect-error ts-migrate(2571) Object is of type 'unknown'\n rejectOrRerun(error);\n }\n }\n\n originalSetTimeout(runExpectation, 0);\n });\n}\n\n/**\n * Wraps `_waitFor` in React's `act` testing utility. Used when the React component\n * updates during the execution of the callback (either because of indirect effects\n * being run or because of direct requests to update the component, like wrapper.update).\n * Prevents updates related to the callback from being affected by other updates\n * and more closely mimics how React runs in the browser. See\n * https://reactjs.org/docs/test-utils.html#act for more info on `act`.\n */\nexport async function waitFor<T>(callback: () => T | Promise<T>, options?: WaitForOptions): Promise<T> {\n let result: T | Promise<T>;\n // See https://github.com/testing-library/dom-testing-library/blob/f7b5c33c44\n // 632fba1579cb44f9f175be1ec46087/src/wait-for.js#L182-L184\n const stackTraceError = new Error('STACK_TRACE_ERROR');\n\n await act(async () => {\n result = await _waitFor(callback, { stackTraceError, ...options });\n });\n\n // @ts-expect-error: either `waitFor` will throw or `result` will be assigned\n return result;\n}\n","// eslint-disable-next-line @databricks/no-restricted-imports-regexp\nimport type { ReactWrapper } from 'enzyme';\n\nimport { selectClasses } from '../common';\nimport { findByText, waitFor } from './utils';\n\n/**\n * Clicks on the \"Clear\" button. In order for this function to work properly,\n * the `allowClear` prop must be set to `true`.\n */\nexport function clearAll(getSelect: () => ReactWrapper): void {\n getSelect().find(`.${selectClasses.clear}`).hostNodes().simulate('mousedown');\n}\n\n/**\n * Closes the dropdown menu for the <Select/> by clicking. Will throw an error if\n * the menu is already closed or if the menu is unable to be closed.\n */\nexport async function closeMenu(getSelect: () => ReactWrapper): Promise<void> {\n if (!getSelect().find(`.${selectClasses.open}`).exists()) {\n throw new Error(`Select is already closed\\n${getSelect().debug()}`);\n }\n getSelect().find(`.${selectClasses.selector}`).simulate('mousedown');\n await waitFor(() => {\n const select = getSelect();\n if (select.find(`.${selectClasses.open}`).exists()) {\n throw new Error(`Select did not close\\n${select.debug()}`);\n }\n });\n}\n\n/**\n * Returns a string concatenating the labels for all selected options.\n */\nexport function getLabelText(getSelect: () => ReactWrapper): string {\n // Trim the text to avoid weird whitespace issues non-label elements being added.\n // For example, the input mirror is an empty span with some whitespace that is\n // nested under the selector but does not show up in the label text.\n return getSelect().find(`.${selectClasses.selector}`).text().trim();\n}\n\n/**\n * Selects options from the dropdown menu for a <Select/> component with `mode=\"multiple\"`.\n * The provided strings must match the option labels exactly. There is a known\n * limitation for lists that are extremely long because AntD virtualizes the\n * options so not all may options may be rendered in the DOM. If this is causing\n * you issues, please let #help-frontend know.\n */\nexport async function multiSelect(getSelect: () => ReactWrapper, options: string[]): Promise<void> {\n await openMenu(getSelect);\n options.forEach((option) => {\n findByText(getSelect().find(`.${selectClasses.list}`), option).simulate('click');\n });\n // Close the menu to indicate that selection has finished\n await closeMenu(getSelect);\n}\n\n/**\n * Selects options from the dropdown menu for a <Select/> component without a\n * mode. The provided string must match an option label exactly. There is a known\n * limitation for lists that are extremely long because AntD virtualizes the\n * options so not all may options may be rendered in the DOM. If this is causing\n * you issues, please let #help-frontend know.\n */\nexport async function singleSelect(getSelect: () => ReactWrapper, option: string): Promise<void> {\n await openMenu(getSelect);\n findByText(getSelect().find(`.${selectClasses.list}`), option).simulate('click');\n // Menu automatically closes for a single <Select/> (no mode=\"multiple\")\n}\n\n/**\n * Opens the dropdown menu for the <Select/> by clicking. Will throw an error if\n * the menu is already opened or if the menu is unable to be opened.\n */\nexport async function openMenu(getSelect: () => ReactWrapper): Promise<void> {\n if (getSelect().find(`.${selectClasses.open}`).exists()) {\n throw new Error(`Select is already open\\n${getSelect().debug()}`);\n }\n getSelect().find(`.${selectClasses.selector}`).simulate('mousedown');\n await waitFor(() => {\n const select = getSelect();\n if (!select.find(`.${selectClasses.open}`).exists()) {\n throw new Error(`Select did not open\\n${select.debug()}`);\n }\n });\n}\n\n/**\n * Opens the dropdown menu, finds all of the options in the dropdown, closes\n * the menu, and returns a list of the text of each option in order.\n */\nexport async function getAllOptions(getSelect: () => ReactWrapper): Promise<string[]> {\n await openMenu(getSelect);\n const options = getSelect()\n .find(`.${selectClasses.list}`)\n .find(`.${selectClasses.option}`)\n .map((option) => option.text());\n await closeMenu(getSelect);\n return options;\n}\n","// eslint-disable-next-line @databricks/no-restricted-imports-regexp\nimport type { ReactWrapper } from 'enzyme';\n\nexport * as selectEvent from './selectEvent';\n\n/**\n * Open a dropdown menu by simulating a pointerDown event on the dropdown button.\n *\n * @param dropdownButton - The Dropdown Trigger button that opens the menu when clicked.\n */\nexport const openDropdownMenu = (dropdownButton: ReactWrapper) => {\n dropdownButton.hostNodes().simulate('pointerDown', { button: 0, ctrlKey: false });\n};\n"],"names":["findByText","wrapper","text","queryOptions","newWrappers","findAllByText","length","Error","debug","trim","textNodes","findWhere","n","type","undefined","nodeText","test","map","textNodeParent","parents","first","name","formattedMessageParents","originalSetTimeout","window","setTimeout","copyStackTrace","target","source","stack","replace","message","_waitFor","f","interval","stackTraceError","timeout","maxTries","Math","ceil","tries","Promise","resolve","reject","rejectOrRerun","error","runExpectation","then","catch","waitFor","callback","options","result","act","clearAll","getSelect","find","selectClasses","clear","hostNodes","simulate","closeMenu","open","exists","selector","select","getLabelText","multiSelect","openMenu","forEach","option","list","singleSelect","getAllOptions","openDropdownMenu","dropdownButton","button","ctrlKey"],"mappings":";;;AAAA;AASA;AACA;AACA;AACA;AACA;AACO,SAASA,UAAU,CACxBC,OAA8B,EAC9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EAAG,CAACC,MAAM,EAAE,EAAE;MACnD,MAAM,IAAIxD,KAAK,gCAAyB0D,MAAM,CAACzD,KAAK,EAAE,EAAG;;GAE5D,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACO,eAAeiE,aAAa,CAAClB,SAA6B,EAAqB;EACpF,MAAMa,QAAQ,CAACb,SAAS,CAAC;EACzB,MAAMJ,OAAO,GAAGI,SAAS,EAAE,CACxBC,IAAI,YAAKC,aAAa,CAACc,IAAI,EAAG,CAC9Bf,IAAI,YAAKC,aAAa,CAACa,MAAM,EAAG,CAChCrD,GAAG,CAAEqD,MAAM,IAAKA,MAAM,CAACpE,IAAI,EAAE,CAAC;EACjC,MAAM2D,SAAS,CAACN,SAAS,CAAC;EAC1B,OAAOJ,OAAO;AAChB;;;;;;;;;;;;;ACnGA;AAKA;AACA;AACA;AACA;AACA;MACauB,gBAAgB,GAAIC,cAA4B,IAAK;EAChEA,cAAc,CAAChB,SAAS,EAAE,CAACC,QAAQ,CAAC,aAAa,EAAE;IAAEgB,MAAM,EAAE,CAAC;IAAEC,OAAO,EAAE;GAAO,CAAC;AACnF;;;;"}
|
|
1
|
+
{"version":3,"file":"enzyme.js","sources":["../../src/test-utils/enzyme/utils.ts","../../src/test-utils/enzyme/selectEvent.ts","../../src/test-utils/enzyme/table.ts","../../src/test-utils/enzyme/index.ts"],"sourcesContent":["// eslint-disable-next-line @databricks/no-restricted-imports-regexp\nimport type { ReactWrapper } from 'enzyme';\nimport { act } from 'react-dom/test-utils';\n\ninterface QueryOptions {\n /** Whether to trim the whitespace from DOM text using `String.prototype.trim` */\n trim?: boolean;\n}\n\n/**\n * Finds a single element that contains the specified text in the wrapper. If\n * there are 0 or more than 1 element that contains the specified text, an error\n * is thrown. Returns the element in an enzyme wrapper.\n */\nexport function findByText<P, S, C>(\n wrapper: ReactWrapper<P, S, C>,\n text: string | RegExp,\n queryOptions?: QueryOptions\n) {\n const newWrappers = findAllByText<P, S, C>(wrapper, text, queryOptions);\n if (newWrappers.length !== 1) {\n throw new Error(\n `Expected to find 1 node but found ${newWrappers.length} nodes for text \"${text}\".\\n${wrapper.debug()}`\n );\n }\n return newWrappers[0];\n}\n\n/**\n * Finds all elements that contain the specified text. To avoid duplicate results,\n * only the parents of text nodes are returned.\n */\nexport function findAllByText<P, S, C>(\n wrapper: ReactWrapper<P, S, C>,\n text: string | RegExp,\n { trim = false }: QueryOptions = {}\n) {\n const textNodes = wrapper.findWhere((n) => {\n if (n.type() !== undefined) {\n return false;\n }\n\n let nodeText = n.text();\n if (trim) {\n nodeText = nodeText.trim();\n }\n\n return typeof text === 'string' ? nodeText === text : text.test(nodeText);\n });\n const newWrappers = textNodes.map((n) => {\n const textNodeParent = n.parents().first();\n if (textNodeParent.name() === 'FormattedMessage') {\n // Try not to return FormattedMessage since it breaks `simulate` due to a bug in `enzyme-adapter-react-17`\n // Similar to https://github.com/wojtekmaj/enzyme-adapter-react-17/issues/45\n const formattedMessageParents = textNodeParent.parents();\n return formattedMessageParents.length > 0 ? formattedMessageParents.first() : textNodeParent;\n } else {\n return textNodeParent;\n }\n });\n return newWrappers;\n}\n\n// We need to keep ref to original setTimeout to avoid SinonJS fake timers if enabled\nconst originalSetTimeout = window.setTimeout;\n\n/**\n * This is so the stack trace the developer sees is one that's\n * closer to their code (because async stack traces are hard to follow).\n *\n * The code is taken from\n * https://github.com/testing-library/dom-testing-library/blob/f7b5c33c44632fba\n * 1579cb44f9f175be1ec46087/src/wait-for.js#L15-L19\n */\nfunction copyStackTrace(target: Error, source: Error) {\n // eslint-disable-next-line no-param-reassign\n target.stack = source.stack!.replace(source.message, target.message);\n}\n\ninterface WaitForOptions {\n interval?: number;\n stackTraceError?: Error;\n timeout?: number;\n}\n\n/**\n * Run an expectation until it succeeds or reaches the timeout. The timeout of 1500ms\n * is chosen to be under the default Karma test timeout of 2000ms. This function will\n * not work properly if fake timers are being used (since it expects the real setTimeout).\n *\n * The code is taken from\n * https://github.com/TheBrainFamily/wait-for-expect/blob/master/src/index.ts,\n * with slight modifications to support Karma (instead of Jest).\n *\n *\n * Example\n * The <App /> component does not render the header synchronously.\n * Therefore, we cannot check that the wrapper's text is equal to the string\n * immediately--this assertion will fail and cause the test to fail. To\n * remediate this issue, we can run the expectation until it succeeds:\n *\n * function App() {\n * const [value, setValue] = useState(null);\n * useEffect(() => {\n * const timeoutId = setTimeout(() => setValue(\"some value\"), 100);\n * return () => clearTimeout(timeoutId);\n * }, []);\n * return value === null ? null : <h1>The value is: {value}</h1>;\n * }\n *\n * it('renders value', async () => {\n * const wrapper = mount(<App />);\n * await waitFor(() =>\n * wrapper.update();\n * expect(wrapper.text()).to.equal(\"The value is: some value\")\n * );\n * });\n */\nfunction _waitFor<T>(\n f: () => T | Promise<T>,\n { interval = 50, stackTraceError, timeout = 1500 }: WaitForOptions = {}\n): Promise<T> {\n const maxTries = Math.ceil(timeout / interval);\n let tries = 0;\n return new Promise((resolve, reject) => {\n const rejectOrRerun = (error: Error) => {\n if (tries > maxTries) {\n if (stackTraceError !== undefined) {\n copyStackTrace(error, stackTraceError);\n }\n reject(error);\n return;\n }\n originalSetTimeout(runExpectation, interval);\n };\n\n function runExpectation() {\n tries += 1;\n try {\n Promise.resolve(f()).then(resolve).catch(rejectOrRerun);\n } catch (error) {\n // @ts-expect-error ts-migrate(2571) Object is of type 'unknown'\n rejectOrRerun(error);\n }\n }\n\n originalSetTimeout(runExpectation, 0);\n });\n}\n\n/**\n * Wraps `_waitFor` in React's `act` testing utility. Used when the React component\n * updates during the execution of the callback (either because of indirect effects\n * being run or because of direct requests to update the component, like wrapper.update).\n * Prevents updates related to the callback from being affected by other updates\n * and more closely mimics how React runs in the browser. See\n * https://reactjs.org/docs/test-utils.html#act for more info on `act`.\n */\nexport async function waitFor<T>(callback: () => T | Promise<T>, options?: WaitForOptions): Promise<T> {\n let result: T | Promise<T>;\n // See https://github.com/testing-library/dom-testing-library/blob/f7b5c33c44\n // 632fba1579cb44f9f175be1ec46087/src/wait-for.js#L182-L184\n const stackTraceError = new Error('STACK_TRACE_ERROR');\n\n await act(async () => {\n result = await _waitFor(callback, { stackTraceError, ...options });\n });\n\n // @ts-expect-error: either `waitFor` will throw or `result` will be assigned\n return result;\n}\n\n/**\n * Finds all elements (that are rendered in the DOM) in `wrapper` that have an explicit\n * role of `role` specified. This is similar to `getAllByRole` from @testing-library/react\n * but is much simpler because of the shortcomings of Enzyme's API.\n */\nexport function findAllByRole(wrapper: ReactWrapper, role: string): ReactWrapper[] {\n return wrapper\n .find(`[role=\"${role}\"]`)\n .hostNodes()\n .map((n) => n);\n}\n","// eslint-disable-next-line @databricks/no-restricted-imports-regexp\nimport type { ReactWrapper } from 'enzyme';\n\nimport { selectClasses } from '../common';\nimport { findByText, waitFor } from './utils';\n\n/**\n * Clicks on the \"Clear\" button. In order for this function to work properly,\n * the `allowClear` prop must be set to `true`.\n */\nexport function clearAll(getSelect: () => ReactWrapper): void {\n getSelect().find(`.${selectClasses.clear}`).hostNodes().simulate('mousedown');\n}\n\n/**\n * Closes the dropdown menu for the <Select/> by clicking. Will throw an error if\n * the menu is already closed or if the menu is unable to be closed.\n */\nexport async function closeMenu(getSelect: () => ReactWrapper): Promise<void> {\n if (!getSelect().find(`.${selectClasses.open}`).exists()) {\n throw new Error(`Select is already closed\\n${getSelect().debug()}`);\n }\n getSelect().find(`.${selectClasses.selector}`).simulate('mousedown');\n await waitFor(() => {\n const select = getSelect();\n if (select.find(`.${selectClasses.open}`).exists()) {\n throw new Error(`Select did not close\\n${select.debug()}`);\n }\n });\n}\n\n/**\n * Returns a string concatenating the labels for all selected options.\n */\nexport function getLabelText(getSelect: () => ReactWrapper): string {\n // Trim the text to avoid weird whitespace issues non-label elements being added.\n // For example, the input mirror is an empty span with some whitespace that is\n // nested under the selector but does not show up in the label text.\n return getSelect().find(`.${selectClasses.selector}`).text().trim();\n}\n\n/**\n * Selects options from the dropdown menu for a <Select/> component with `mode=\"multiple\"`.\n * The provided strings must match the option labels exactly. There is a known\n * limitation for lists that are extremely long because AntD virtualizes the\n * options so not all may options may be rendered in the DOM. If this is causing\n * you issues, please let #help-frontend know.\n */\nexport async function multiSelect(getSelect: () => ReactWrapper, options: string[]): Promise<void> {\n await openMenu(getSelect);\n options.forEach((option) => {\n findByText(getSelect().find(`.${selectClasses.list}`), option).simulate('click');\n });\n // Close the menu to indicate that selection has finished\n await closeMenu(getSelect);\n}\n\n/**\n * Selects options from the dropdown menu for a <Select/> component without a\n * mode. The provided string must match an option label exactly. There is a known\n * limitation for lists that are extremely long because AntD virtualizes the\n * options so not all may options may be rendered in the DOM. If this is causing\n * you issues, please let #help-frontend know.\n */\nexport async function singleSelect(getSelect: () => ReactWrapper, option: string): Promise<void> {\n await openMenu(getSelect);\n findByText(getSelect().find(`.${selectClasses.list}`), option).simulate('click');\n // Menu automatically closes for a single <Select/> (no mode=\"multiple\")\n}\n\n/**\n * Opens the dropdown menu for the <Select/> by clicking. Will throw an error if\n * the menu is already opened or if the menu is unable to be opened.\n */\nexport async function openMenu(getSelect: () => ReactWrapper): Promise<void> {\n if (getSelect().find(`.${selectClasses.open}`).exists()) {\n throw new Error(`Select is already open\\n${getSelect().debug()}`);\n }\n getSelect().find(`.${selectClasses.selector}`).simulate('mousedown');\n await waitFor(() => {\n const select = getSelect();\n if (!select.find(`.${selectClasses.open}`).exists()) {\n throw new Error(`Select did not open\\n${select.debug()}`);\n }\n });\n}\n\n/**\n * Opens the dropdown menu, finds all of the options in the dropdown, closes\n * the menu, and returns a list of the text of each option in order.\n */\nexport async function getAllOptions(getSelect: () => ReactWrapper): Promise<string[]> {\n await openMenu(getSelect);\n const options = getSelect()\n .find(`.${selectClasses.list}`)\n .find(`.${selectClasses.option}`)\n .map((option) => option.text());\n await closeMenu(getSelect);\n return options;\n}\n","// eslint-disable-next-line @databricks/no-restricted-imports-regexp\nimport type { ReactWrapper } from 'enzyme';\n\nimport type { GetTableRowByCellTextOptions } from '../common';\nimport { createMarkdownTable } from '../common';\nimport { findAllByRole, findByText } from './utils';\n\n/**\n * Returns the table row that contains the specified `cellText`. The `cellText`\n * must be in the column with name `columnHeaderName` if it is specified. Otherwise,\n * the `cellText` must be in the first column. Throws an error if either multiple\n * rows or no rows can be found that match the given options. Also throws an error\n * if the column with name `columnHeaderName` cannot be found.\n *\n * @param tableWrapper The ReactWrapper containing the table to query in.\n * @param cellText The cell text that uniquely identifies the row.\n * @param columnHeaderName The name of the column to search the text for. If not provided,\n * the first column will be used.\n */\nexport function getTableRowByCellText(\n tableWrapper: ReactWrapper,\n cellText: string,\n { columnHeaderName }: GetTableRowByCellTextOptions = {}\n): ReactWrapper {\n let columnHeaderIndex: number;\n if (columnHeaderName === undefined) {\n columnHeaderIndex = 0;\n } else {\n const columnHeaders = findAllByRole(tableWrapper, 'columnheader');\n columnHeaderIndex = columnHeaders.findIndex((n) => {\n try {\n findByText(n, columnHeaderName);\n return true;\n } catch {\n return false;\n }\n });\n if (columnHeaderIndex === -1) {\n throw new Error(`Unable to find a column with name \"${columnHeaderName}\"\\n${tableWrapper.debug()}`);\n }\n }\n\n const matchingRows = findAllByRole(tableWrapper, 'row')\n // Skip first row (table header)\n .slice(1)\n .filter((row) => {\n const cells = findAllByRole(row, 'cell');\n const cell = cells[columnHeaderIndex];\n try {\n findByText(cell, cellText);\n return true;\n } catch {\n return false;\n }\n });\n\n if (matchingRows.length === 0) {\n throw new Error(\n `Unable to find a table row with text \"${cellText}\" in the column \"${columnHeaderName}\"\\n${tableWrapper.debug()}`\n );\n }\n\n if (matchingRows.length > 1) {\n throw new Error(\n `Found multiple table rows with text \"${cellText}\" in the column \"${columnHeaderName}\"\\n${tableWrapper.debug()}`\n );\n }\n\n return matchingRows[0].hostNodes();\n}\n\n/**\n * Converts a Du Bois table to a markdown table string. This means that each cell\n * is separated by a pipe (including the edges), the header row is on its own line\n * at the top, each data row is on its own line below, and the header row is separated\n * by a row of dashes from the data rows. This is useful for checking table contents\n * in tests.\n *\n * @param tableWrapper The ReactWrapper containing the table to query in.\n *\n * @example\n * The HTML table:\n * <Table>\n * <TableRow isHeader>\n * <TableHeader>Name</TableHeader>\n * <TableHeader>Fruit</TableHeader>\n * </TableRow>\n * <TableRow>\n * <TableCell>Alice</TableCell>\n * <TableCell>Apple</TableCell>\n * </TableRow>\n * <TableRow>\n * <TableCell>Brady</TableCell>\n * <TableCell>Banana</TableCell>\n * </TableRow>\n * </Table>\n *\n * The Markdown table:\n * | Name | Fruit |\n * | --- | --- |\n * | Alice | Apple |\n * | Brady | Banana |\n */\nexport function toMarkdownTable(tableWrapper: ReactWrapper): string {\n const [firstRow, ...restRows] = findAllByRole(tableWrapper, 'row');\n const columns = findAllByRole(firstRow, 'columnheader').map((column) => column.text());\n const rows = restRows.map((row) => findAllByRole(row, 'cell').map((cell) => cell.text()));\n return createMarkdownTable(columns, rows);\n}\n","// eslint-disable-next-line @databricks/no-restricted-imports-regexp\nimport type { ReactWrapper } from 'enzyme';\n\nexport * as selectEvent from './selectEvent';\n\nexport * from './table';\n\n/**\n * Open a dropdown menu by simulating a pointerDown event on the dropdown button.\n *\n * @param dropdownButton - The Dropdown Trigger button that opens the menu when clicked.\n */\nexport const openDropdownMenu = (dropdownButton: ReactWrapper) => {\n dropdownButton.hostNodes().simulate('pointerDown', { button: 0, ctrlKey: false });\n};\n"],"names":["findByText","wrapper","text","queryOptions","newWrappers","findAllByText","length","Error","debug","trim","textNodes","findWhere","n","type","undefined","nodeText","test","map","textNodeParent","parents","first","name","formattedMessageParents","originalSetTimeout","window","setTimeout","copyStackTrace","target","source","stack","replace","message","_waitFor","f","interval","stackTraceError","timeout","maxTries","Math","ceil","tries","Promise","resolve","reject","rejectOrRerun","error","runExpectation","then","catch","waitFor","callback","options","result","act","findAllByRole","role","find","hostNodes","clearAll","getSelect","selectClasses","clear","simulate","closeMenu","open","exists","selector","select","getLabelText","multiSelect","openMenu","forEach","option","list","singleSelect","getAllOptions","getTableRowByCellText","tableWrapper","cellText","columnHeaderName","columnHeaderIndex","columnHeaders","findIndex","matchingRows","slice","filter","row","cells","cell","toMarkdownTable","firstRow","restRows","columns","column","rows","createMarkdownTable","openDropdownMenu","dropdownButton","button","ctrlKey"],"mappings":";;;AAAA;AASA;AACA;AACA;AACA;AACA;AACO,SAASA,UAAU,CACxBC,OAA8B,EAC9BC,IAAqB,EACrBC,YAA2B,EAC3B;EACA,MAAMC,WAAW,GAAGC,aAAa,CAAUJ,OAAO,EAAEC,IAAI,EAAEC,YAAY,CAAC;EACvE,IAAIC,WAAW,CAACE,MAAM,KAAK,CAAC,EAAE;IAC5B,MAAM,IAAIC,KAAK,CACZ,qCAAoCH,WAAW,CAACE,MAAO,oBAAmBJ,IAAK,OAAMD,OAAO,CAACO,KAAK,EAAG,EAAC,CACxG;;EAEH,OAAOJ,WAAW,CAAC,CAAC,CAAC;AACvB;;AAEA;AACA;AACA;AACA;AACO,SAASC,aAAa,CAC3BJ,OAA8B,EAC9BC,IAAqB,EAErB;EAAA,IADA;IAAEO,IAAI,GAAG;GAAqB,uEAAG,EAAE;EAEnC,MAAMC,SAAS,GAAGT,OAAO,CAACU,SAAS,CAAEC,CAAC,IAAK;IACzC,IAAIA,CAAC,CAACC,IAAI,EAAE,KAAKC,SAAS,EAAE;MAC1B,OAAO,KAAK;;IAGd,IAAIC,QAAQ,GAAGH,CAAC,CAACV,IAAI,EAAE;IACvB,IAAIO,IAAI,EAAE;MACRM,QAAQ,GAAGA,QAAQ,CAACN,IAAI,EAAE;;IAG5B,OAAO,OAAOP,IAAI,KAAK,QAAQ,GAAGa,QAAQ,KAAKb,IAAI,GAAGA,IAAI,CAACc,IAAI,CAACD,QAAQ,CAAC;GAC1E,CAAC;EACF,MAAMX,WAAW,GAAGM,SAAS,CAACO,GAAG,CAAEL,CAAC,IAAK;IACvC,MAAMM,cAAc,GAAGN,CAAC,CAACO,OAAO,EAAE,CAACC,KAAK,EAAE;IAC1C,IAAIF,cAAc,CAACG,IAAI,EAAE,KAAK,kBAAkB,EAAE;;;MAGhD,MAAMC,uBAAuB,GAAGJ,cAAc,CAACC,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CAAC,CAAC1B,SAAS,EAAE;AACpC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASgC,eAAe,CAACZ,YAA0B,EAAU;EAClE,MAAM,CAACa,QAAQ,EAAE,GAAGC,QAAQ,CAAC,GAAGrC,aAAa,CAACuB,YAAY,EAAE,KAAK,CAAC;EAClE,MAAMe,OAAO,GAAGtC,aAAa,CAACoC,QAAQ,EAAE,cAAc,CAAC,CAACzE,GAAG,CAAE4E,MAAM,IAAKA,MAAM,CAAC3F,IAAI,EAAE,CAAC;EACtF,MAAM4F,IAAI,GAAGH,QAAQ,CAAC1E,GAAG,CAAEqE,GAAG,IAAKhC,aAAa,CAACgC,GAAG,EAAE,MAAM,CAAC,CAACrE,GAAG,CAAEuE,IAAI,IAAKA,IAAI,CAACtF,IAAI,EAAE,CAAC,CAAC;EACzF,OAAO6F,mBAAmB,CAACH,OAAO,EAAEE,IAAI,CAAC;AAC3C;;AC5GA;;AAOA;AACA;AACA;AACA;AACA;MACaE,gBAAgB,GAAIC,cAA4B,IAAK;EAChEA,cAAc,CAACxC,SAAS,EAAE,CAACK,QAAQ,CAAC,aAAa,EAAE;IAAEoC,MAAM,EAAE,CAAC;IAAEC,OAAO,EAAE;GAAO,CAAC;AACnF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/test-utils/rtl/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,mBAA0B,WAAW,kBAEjE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/test-utils/rtl/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAE7C,cAAc,SAAS,CAAC;AAExB;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,mBAA0B,WAAW,kBAEjE,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { GetTableRowByCellTextOptions } from '../common';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the table row that contains the specified `cellText`. The `cellText`
|
|
4
|
+
* must be in the column with name `columnHeaderName` if it is specified. Otherwise,
|
|
5
|
+
* the `cellText` must be in the first column. Throws an error if either multiple
|
|
6
|
+
* rows or no rows can be found that match the given options. Also throws an error
|
|
7
|
+
* if the column with name `columnHeaderName` cannot be found.
|
|
8
|
+
*
|
|
9
|
+
* @param tableElement The HTMLElement representing the table to query in. This is likely
|
|
10
|
+
* a <div role="table"> element, so it can be queried by `screen.getByRole('table')`.
|
|
11
|
+
* @param cellText The cell text that uniquely identifies the row.
|
|
12
|
+
* @param columnHeaderName The name of the column to search the text for. If not provided,
|
|
13
|
+
* the first column will be used.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getTableRowByCellText(tableElement: HTMLElement, cellText: string, { columnHeaderName }?: GetTableRowByCellTextOptions): HTMLElement;
|
|
16
|
+
/**
|
|
17
|
+
* Converts a Du Bois table to a markdown table string. This means that each cell
|
|
18
|
+
* is separated by a pipe (including the edges), the header row is on its own line
|
|
19
|
+
* at the top, each data row is on its own line below, and the header row is separated
|
|
20
|
+
* by a row of dashes from the data rows. This is useful for checking table contents
|
|
21
|
+
* in tests.
|
|
22
|
+
*
|
|
23
|
+
* @param tableElement The HTMLElement representing the table to query in. This is likely
|
|
24
|
+
* a <div role="table"> element, so it can be queried by `screen.getByRole('table')`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* The HTML table:
|
|
28
|
+
* <Table>
|
|
29
|
+
* <TableRow isHeader>
|
|
30
|
+
* <TableHeader>Name</TableHeader>
|
|
31
|
+
* <TableHeader>Fruit</TableHeader>
|
|
32
|
+
* </TableRow>
|
|
33
|
+
* <TableRow>
|
|
34
|
+
* <TableCell>Alice</TableCell>
|
|
35
|
+
* <TableCell>Apple</TableCell>
|
|
36
|
+
* </TableRow>
|
|
37
|
+
* <TableRow>
|
|
38
|
+
* <TableCell>Brady</TableCell>
|
|
39
|
+
* <TableCell>Banana</TableCell>
|
|
40
|
+
* </TableRow>
|
|
41
|
+
* </Table>
|
|
42
|
+
*
|
|
43
|
+
* The Markdown table:
|
|
44
|
+
* | Name | Fruit |
|
|
45
|
+
* | --- | --- |
|
|
46
|
+
* | Alice | Apple |
|
|
47
|
+
* | Brady | Banana |
|
|
48
|
+
*/
|
|
49
|
+
export declare function toMarkdownTable(tableElement: HTMLElement): string;
|
|
50
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/test-utils/rtl/table.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAC;AAG9D;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,WAAW,EACzB,QAAQ,EAAE,MAAM,EAChB,EAAE,gBAAgB,EAAE,GAAE,4BAAiC,GACtD,WAAW,CAmCb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,WAAW,GAAG,MAAM,CAWjE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.test.d.ts","sourceRoot":"","sources":["../../../src/test-utils/rtl/table.test.tsx"],"names":[],"mappings":""}
|