+ {options.map(option =>
)}
+
+ ),
+ ...obj,
+ };
+}
-describe('AnchorSelectorField', () => {
- let props = null;
- let field = null;
-
- beforeEach(() => {
- props = {
- id: 'Form_Test',
- name: 'Test',
- data: {
- endpoint: 'url-callback',
- },
- pageId: 4,
- anchors: ['anchor1', 'anchor2'],
- value: 'selectedanchor',
- loadingState: anchorSelectorStates.SUCCESS,
- actions: {
- anchorSelector: {
- beginUpdating: jest.fn(),
- updated: jest.fn(),
- updateFailed: jest.fn(),
- },
+test('AnchorSelectorField componentDidMount() Loads dirty selectors', async () => {
+ const beginUpdating = jest.fn();
+ render(
{},
+ updateFailed: () => {},
},
- };
- });
+ },
+ })}
+ />);
+ await screen.findByTestId('test-creatable-select');
+ expect(beginUpdating).toBeCalledWith(4);
+});
- describe('componentDidMount()', () => {
- it('Loads dirty selectors', () => {
- props.loadingState = anchorSelectorStates.DIRTY;
- field = ReactTestUtils.renderIntoDocument();
- expect(props.actions.anchorSelector.beginUpdating)
- .toHaveBeenCalledWith(4);
- });
- it('Does not load success selectors', () => {
- props.loadingState = anchorSelectorStates.SUCCESS;
- field = ReactTestUtils.renderIntoDocument();
- expect(props.actions.anchorSelector.beginUpdating)
- .not
- .toHaveBeenCalled();
- });
- });
+test('AnchorSelectorField Merges value with page anchors', async () => {
+ const beginUpdating = jest.fn();
+ const { container } = render( {},
+ updateFailed: () => {},
+ },
+ },
+ })}
+ />);
+ const select = await screen.findByTestId('test-creatable-select');
+ const options = select.querySelectorAll('[data-option]');
+ expect(options).toHaveLength(3);
+ expect(options[0].getAttribute('data-option')).toBe('selectedanchor');
+ expect(options[1].getAttribute('data-option')).toBe('anchor1');
+ expect(options[2].getAttribute('data-option')).toBe('anchor2');
+});
- describe('getDropdownOptions()', () => {
- it('Merges value with page anchors', () => {
- field = ReactTestUtils.renderIntoDocument();
- expect(field.getDropdownOptions()).toEqual([
- { value: 'selectedanchor' },
- { value: 'anchor1' },
- { value: 'anchor2' },
- ]);
- });
- });
+test('AnchorSelectorField componentDidMount() Does not load success selectors', async () => {
+ const beginUpdating = jest.fn();
+ render( {},
+ updateFailed: () => {},
+ },
+ },
+ })}
+ />);
+ await screen.findByTestId('test-creatable-select');
+ expect(beginUpdating).not.toBeCalled();
+});
- describe('ensurePagesLoaded', () => {
- it('Triggers loading on dirty', () => {
- props.loadingState = anchorSelectorStates.DIRTY;
- field = ReactTestUtils.renderIntoDocument();
- return field
- .ensurePagesLoaded()
- .then((result) => {
- expect(props.actions.anchorSelector.beginUpdating)
- .toHaveBeenCalledWith(4);
- expect(props.actions.anchorSelector.updated)
- .toHaveBeenCalledWith(4, ['anchor3', 'anchor4']);
- expect(props.actions.anchorSelector.updateFailed)
- .not
- .toHaveBeenCalled();
- expect(result).toEqual(['anchor3', 'anchor4']);
- });
- });
+test('AnchorSelectorField ensurePagesLoaded Triggers loading on dirty', async () => {
+ const beginUpdating = jest.fn();
+ const updated = jest.fn();
+ const updateFailed = jest.fn();
+ render();
+ await screen.findByTestId('test-creatable-select');
+ expect(beginUpdating).toBeCalledWith(4);
+ expect(updated).toBeCalledWith(4, ['anchor3', 'anchor4']);
+ expect(updateFailed).not.toBeCalled();
+});
- it('Does not trigger updating', () => {
- props.loadingState = anchorSelectorStates.UPDATING;
- field = ReactTestUtils.renderIntoDocument();
- return field
- .ensurePagesLoaded()
- .then((result) => {
- expect(props.actions.anchorSelector.beginUpdating)
- .not
- .toHaveBeenCalled();
- expect(props.actions.anchorSelector.updated)
- .not
- .toHaveBeenCalled();
- expect(props.actions.anchorSelector.updateFailed)
- .not
- .toHaveBeenCalled();
- expect(result).toBe(undefined);
- });
- });
- });
+test('AnchorSelectorField ensurePagesLoaded Does not trigger updating', async () => {
+ const beginUpdating = jest.fn();
+ const updated = jest.fn();
+ const updateFailed = jest.fn();
+ render();
+ await screen.findByTestId('test-creatable-select');
+ expect(beginUpdating).not.toBeCalled();
+ expect(updated).not.toBeCalled();
+ expect(updateFailed).not.toBeCalled();
});
diff --git a/package.json b/package.json
index 927eb468e1..f171b4abba 100644
--- a/package.json
+++ b/package.json
@@ -54,13 +54,12 @@
"devDependencies": {
"@silverstripe/eslint-config": "^1.0.0",
"@silverstripe/webpack-config": "^2.0.0",
+ "@testing-library/react": "^14.0.0",
"babel-jest": "^29.3.0",
"copy-webpack-plugin": "^11.0.0",
"core-js": "^3.26.0",
"jest-cli": "^29.3.0",
"jest-environment-jsdom": "^29.3.1",
- "react-16": "npm:react@^16.14.0",
- "react-dom-16": "npm:react-dom@^16.14.0",
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0"
},
@@ -72,11 +71,6 @@
"roots": [
"client/src"
],
- "moduleNameMapper": {
- "^react-dom/client$": "react-dom-16",
- "^react-dom((/.*)?)$": "react-dom-16$1",
- "^react((/.*)?)$": "react-16$1"
- },
"moduleDirectories": [
"client/src",
"node_modules",
diff --git a/yarn.lock b/yarn.lock
index d490d2390b..7fb174b2af 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -36,6 +36,13 @@
dependencies:
"@babel/highlight" "^7.18.6"
+"@babel/code-frame@^7.10.4":
+ version "7.21.4"
+ resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.21.4.tgz#d0fa9e4413aca81f2b23b9442797bda1826edb39"
+ integrity sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==
+ dependencies:
+ "@babel/highlight" "^7.18.6"
+
"@babel/compat-data@^7.17.7", "@babel/compat-data@^7.20.1", "@babel/compat-data@^7.20.5":
version "7.20.10"
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.20.10.tgz#9d92fa81b87542fff50e848ed585b4212c1d34ec"
@@ -1757,11 +1764,39 @@
dependencies:
"@sinonjs/commons" "^1.7.0"
+"@testing-library/dom@^9.0.0":
+ version "9.2.0"
+ resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-9.2.0.tgz#0e1f45e956f2a16f471559c06edd8827c4832f04"
+ integrity sha512-xTEnpUKiV/bMyEsE5bT4oYA0x0Z/colMtxzUY8bKyPXBNLn/e0V4ZjBZkEhms0xE4pv9QsPfSRu9AWS4y5wGvA==
+ dependencies:
+ "@babel/code-frame" "^7.10.4"
+ "@babel/runtime" "^7.12.5"
+ "@types/aria-query" "^5.0.1"
+ aria-query "^5.0.0"
+ chalk "^4.1.0"
+ dom-accessibility-api "^0.5.9"
+ lz-string "^1.5.0"
+ pretty-format "^27.0.2"
+
+"@testing-library/react@^14.0.0":
+ version "14.0.0"
+ resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-14.0.0.tgz#59030392a6792450b9ab8e67aea5f3cc18d6347c"
+ integrity sha512-S04gSNJbYE30TlIMLTzv6QCTzt9AqIF5y6s6SzVFILNcNvbV/jU96GeiTPillGQo+Ny64M/5PV7klNYYgv5Dfg==
+ dependencies:
+ "@babel/runtime" "^7.12.5"
+ "@testing-library/dom" "^9.0.0"
+ "@types/react-dom" "^18.0.0"
+
"@tootallnate/once@2":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf"
integrity sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==
+"@types/aria-query@^5.0.1":
+ version "5.0.1"
+ resolved "https://registry.yarnpkg.com/@types/aria-query/-/aria-query-5.0.1.tgz#3286741fb8f1e1580ac28784add4c7a1d49bdfbc"
+ integrity sha512-XTIieEY+gvJ39ChLcB4If5zHtPxt3Syj5rgZR+e1ctpmK8NjPf0zFqsz4JpLJT0xla9GFDKjy8Cpu331nrmE1Q==
+
"@types/babel__core@^7.1.14":
version "7.1.20"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.20.tgz#e168cdd612c92a2d335029ed62ac94c95b362359"
@@ -1894,6 +1929,13 @@
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==
+"@types/react-dom@^18.0.0":
+ version "18.2.1"
+ resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.2.1.tgz#663b2612feb5f6431a70207430d7c04881b87f29"
+ integrity sha512-8QZEV9+Kwy7tXFmjJrp3XUKQSs9LTnE0KnoUb0YCguWBiNW0Yfb2iBMYZ08WPg35IR6P3Z0s00B15SwZnO26+w==
+ dependencies:
+ "@types/react" "*"
+
"@types/react-transition-group@^4.4.0":
version "4.4.5"
resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-4.4.5.tgz#aae20dcf773c5aa275d5b9f7cdbca638abc5e416"
@@ -2342,7 +2384,7 @@ argparse@^2.0.1:
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==
-aria-query@^5.1.3:
+aria-query@^5.0.0, aria-query@^5.1.3:
version "5.1.3"
resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-5.1.3.tgz#19db27cd101152773631396f7a95a3b58c22c35e"
integrity sha512-R5iJ5lkuHybztUfuOAznmboyjWq8O6sqNqtK7CLOqdydi54VNbORp49mb14KbWgG1QD3JFO9hJdZ+y4KutfdOQ==
@@ -3255,6 +3297,11 @@ doctrine@^3.0.0:
dependencies:
esutils "^2.0.2"
+dom-accessibility-api@^0.5.9:
+ version "0.5.16"
+ resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz#5a7429e6066eb3664d911e33fb0e45de8eb08453"
+ integrity sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==
+
dom-helpers@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-3.4.0.tgz#e9b369700f959f62ecde5a6babde4bccd9169af8"
@@ -5744,6 +5791,11 @@ lru-cache@^7.4.4, lru-cache@^7.5.1, lru-cache@^7.7.1:
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.14.1.tgz#8da8d2f5f59827edb388e63e459ac23d6d408fea"
integrity sha512-ysxwsnTKdAx96aTRdhDOCQfDgbHnt8SK0KY8SEjO0wHinhWOFTESbjVCMPbU1uGXg/ch4lifqx0wfjOawU2+WA==
+lz-string@^1.5.0:
+ version "1.5.0"
+ resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.5.0.tgz#c1ab50f77887b712621201ba9fd4e3a6ed099941"
+ integrity sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==
+
make-dir@^3.0.0, make-dir@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
@@ -6684,6 +6736,15 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==
+pretty-format@^27.0.2:
+ version "27.5.1"
+ resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.5.1.tgz#2181879fdea51a7a5851fb39d920faa63f01d88e"
+ integrity sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==
+ dependencies:
+ ansi-regex "^5.0.1"
+ ansi-styles "^5.0.0"
+ react-is "^17.0.1"
+
pretty-format@^29.3.1:
version "29.3.1"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-29.3.1.tgz#1841cac822b02b4da8971dacb03e8a871b4722da"
@@ -6796,25 +6857,6 @@ randombytes@^2.1.0:
dependencies:
safe-buffer "^5.1.0"
-"react-16@npm:react@^16.14.0":
- version "16.14.0"
- resolved "https://registry.yarnpkg.com/react/-/react-16.14.0.tgz#94d776ddd0aaa37da3eda8fc5b6b18a4c9a3114d"
- integrity sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==
- dependencies:
- loose-envify "^1.1.0"
- object-assign "^4.1.1"
- prop-types "^15.6.2"
-
-"react-dom-16@npm:react-dom@^16.14.0":
- version "16.14.0"
- resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.14.0.tgz#7ad838ec29a777fb3c75c3a190f661cf92ab8b89"
- integrity sha512-1gCeQXDLoIqMgqD3IO2Ah9bnf0w9kzhwN5q4FGnHZ67hBm9yePzB5JJAIQCc8x3pFnNlwFq4RidZggNAAkzWWw==
- dependencies:
- loose-envify "^1.1.0"
- object-assign "^4.1.1"
- prop-types "^15.6.2"
- scheduler "^0.19.1"
-
react-dom@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"
@@ -6828,6 +6870,11 @@ react-is@^16.13.1, react-is@^16.4.2, react-is@^16.7.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
+react-is@^17.0.1:
+ version "17.0.2"
+ resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
+ integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
+
react-is@^18.0.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
@@ -7309,14 +7356,6 @@ saxes@^6.0.0:
dependencies:
xmlchars "^2.2.0"
-scheduler@^0.19.1:
- version "0.19.1"
- resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.19.1.tgz#4f3e2ed2c1a7d65681f4c854fa8c5a1ccb40f196"
- integrity sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==
- dependencies:
- loose-envify "^1.1.0"
- object-assign "^4.1.1"
-
scheduler@^0.23.0:
version "0.23.0"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.0.tgz#ba8041afc3d30eb206a487b6b384002e4e61fdfe"