mirror of
https://github.com/prymitive/karma
synced 2026-05-23 04:42:58 +00:00
fix(tests): fix tests for react v17
This commit is contained in:
committed by
Łukasz Mierzwa
parent
34a5cfd9dd
commit
c3bfc77734
121
ui/package-lock.json
generated
121
ui/package-lock.json
generated
@@ -4546,36 +4546,6 @@
|
||||
"semver": "^5.7.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"react-test-renderer": {
|
||||
"version": "17.0.1",
|
||||
"resolved": "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-17.0.1.tgz",
|
||||
"integrity": "sha512-/dRae3mj6aObwkjCcxZPlxDFh73XZLgvwhhyON2haZGUEhiaY5EjfAdw+d/rQmlcFwdTpMXCSGVk374QbCTlrA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"object-assign": "^4.1.1",
|
||||
"react-is": "^17.0.1",
|
||||
"react-shallow-renderer": "^16.13.1",
|
||||
"scheduler": "^0.20.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"react-is": {
|
||||
"version": "17.0.1",
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.1.tgz",
|
||||
"integrity": "sha512-NAnt2iGDXohE5LI7uBnLnqvLQMtzhkiAOLXTmv+qnF9Ky7xAPcX8Up/xWIhxvLVGJvuLiNc4xQLtuqDRzb4fSA==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"scheduler": {
|
||||
"version": "0.20.1",
|
||||
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.20.1.tgz",
|
||||
"integrity": "sha512-LKTe+2xNJBNxu/QhHvDR14wUXHRQbVY5ZOYpOGWRzhydZUqrLb2JBvLPY7cAqFmqrWuDED0Mjk7013SZiOz6Bw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"loose-envify": "^1.1.0",
|
||||
"object-assign": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"semver": {
|
||||
"version": "5.7.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
|
||||
@@ -6725,9 +6695,9 @@
|
||||
}
|
||||
},
|
||||
"caniuse-lite": {
|
||||
"version": "1.0.30001156",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001156.tgz",
|
||||
"integrity": "sha512-z7qztybA2eFZTB6Z3yvaQBIoJpQtsewRD74adw2UbRWwsRq3jIPvgrQGawBMbfafekQaD21FWuXNcywtTDGGCw=="
|
||||
"version": "1.0.30001157",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001157.tgz",
|
||||
"integrity": "sha512-gOerH9Wz2IRZ2ZPdMfBvyOi3cjaz4O4dgNwPGzx8EhqAs4+2IL/O+fJsbt+znSigujoZG8bVcIAUM/I/E5K3MA=="
|
||||
},
|
||||
"capture-exit": {
|
||||
"version": "2.0.0",
|
||||
@@ -7510,9 +7480,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"yargs-parser": {
|
||||
"version": "20.2.3",
|
||||
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.3.tgz",
|
||||
"integrity": "sha512-emOFRT9WVHw03QSvN5qor9QQT9+sw5vwxfYweivSMHTcAXPefwVae2FjO7JJjj8hCE4CzPOPeFM83VwT29HCww==",
|
||||
"version": "20.2.4",
|
||||
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz",
|
||||
"integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
@@ -7562,16 +7532,16 @@
|
||||
}
|
||||
},
|
||||
"core-js": {
|
||||
"version": "3.6.5",
|
||||
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.6.5.tgz",
|
||||
"integrity": "sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA=="
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.7.0.tgz",
|
||||
"integrity": "sha512-NwS7fI5M5B85EwpWuIwJN4i/fbisQUwLwiSNUWeXlkAZ0sbBjLEvLvFLf1uzAUV66PcEPt4xCGCmOZSxVf3xzA=="
|
||||
},
|
||||
"core-js-compat": {
|
||||
"version": "3.6.5",
|
||||
"resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.6.5.tgz",
|
||||
"integrity": "sha512-7ItTKOhOZbznhXAQ2g/slGg1PJV5zDO/WdkTwi7UEOJmkvsE32PWvx6mKtDjiMpjnR2CNf6BAD6sSxIlv7ptng==",
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.7.0.tgz",
|
||||
"integrity": "sha512-V8yBI3+ZLDVomoWICO6kq/CD28Y4r1M7CWeO4AGpMdMfseu8bkSubBmUPySMGKRTS+su4XQ07zUkAsiu9FCWTg==",
|
||||
"requires": {
|
||||
"browserslist": "^4.8.5",
|
||||
"browserslist": "^4.14.6",
|
||||
"semver": "7.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -7583,9 +7553,9 @@
|
||||
}
|
||||
},
|
||||
"core-js-pure": {
|
||||
"version": "3.6.5",
|
||||
"resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.6.5.tgz",
|
||||
"integrity": "sha512-lacdXOimsiD0QyNf9BC/mxivNJ/ybBGJXQFKzRekp1WTHoVUWsUHEn+2T8GJAzzIhyOuXA+gOxCVN3l+5PLPUA=="
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.7.0.tgz",
|
||||
"integrity": "sha512-EZD2ckZysv8MMt4J6HSvS9K2GdtlZtdBncKAmF9lr2n0c9dJUaUN88PSTjvgwCgQPWKTkERXITgS6JJRAnljtg=="
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
@@ -8746,9 +8716,9 @@
|
||||
}
|
||||
},
|
||||
"electron-to-chromium": {
|
||||
"version": "1.3.589",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.589.tgz",
|
||||
"integrity": "sha512-rQItBTFnol20HaaLm26UgSUduX7iGerwW7pEYX17MB1tI6LzFajiLV7iZ7LVcUcsN/7HrZUoCLrBauChy/IqEg=="
|
||||
"version": "1.3.591",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.591.tgz",
|
||||
"integrity": "sha512-ol/0WzjL4NS4Kqy9VD6xXQON91xIihDT36sYCew/G/bnd1v0/4D+kahp26JauQhgFUjrdva3kRSo7URcUmQ+qw=="
|
||||
},
|
||||
"element-resize-detector": {
|
||||
"version": "1.2.1",
|
||||
@@ -8956,11 +8926,12 @@
|
||||
"integrity": "sha512-wd6JXUmyHmt8T5a2xreUwKcGPq6f1f+WwIJkijUqiGcJz1qqnZgP6XIK+QyIWU5lT7imeNxUll48bziG+TSYcA=="
|
||||
},
|
||||
"es-get-iterator": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/es-get-iterator/-/es-get-iterator-1.1.0.tgz",
|
||||
"integrity": "sha512-UfrmHuWQlNMTs35e1ypnvikg6jCz3SK8v8ImvmDsh36fCVUR1MqoFDiyn0/k52C8NqO3YsO8Oe0azeesNuqSsQ==",
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/es-get-iterator/-/es-get-iterator-1.1.1.tgz",
|
||||
"integrity": "sha512-qorBw8Y7B15DVLaJWy6WdEV/ZkieBcu6QCq/xzWzGOKJqgG1j754vXRfZ3NY7HSShneqU43mPB4OkQBTkvHhFw==",
|
||||
"requires": {
|
||||
"es-abstract": "^1.17.4",
|
||||
"call-bind": "^1.0.0",
|
||||
"get-intrinsic": "^1.0.1",
|
||||
"has-symbols": "^1.0.1",
|
||||
"is-arguments": "^1.0.4",
|
||||
"is-map": "^2.0.1",
|
||||
@@ -8969,24 +8940,6 @@
|
||||
"isarray": "^2.0.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"es-abstract": {
|
||||
"version": "1.17.7",
|
||||
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.7.tgz",
|
||||
"integrity": "sha512-VBl/gnfcJ7OercKA9MVaegWsBHFjV492syMudcnQZvt/Dw8ezpcOHYZXa/J96O8vx+g4x65YKhxOwDUh63aS5g==",
|
||||
"requires": {
|
||||
"es-to-primitive": "^1.2.1",
|
||||
"function-bind": "^1.1.1",
|
||||
"has": "^1.0.3",
|
||||
"has-symbols": "^1.0.1",
|
||||
"is-callable": "^1.2.2",
|
||||
"is-regex": "^1.1.1",
|
||||
"object-inspect": "^1.8.0",
|
||||
"object-keys": "^1.1.1",
|
||||
"object.assign": "^4.1.1",
|
||||
"string.prototype.trimend": "^1.0.1",
|
||||
"string.prototype.trimstart": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"isarray": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz",
|
||||
@@ -11040,9 +10993,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"yargs-parser": {
|
||||
"version": "20.2.3",
|
||||
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.3.tgz",
|
||||
"integrity": "sha512-emOFRT9WVHw03QSvN5qor9QQT9+sw5vwxfYweivSMHTcAXPefwVae2FjO7JJjj8hCE4CzPOPeFM83VwT29HCww==",
|
||||
"version": "20.2.4",
|
||||
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz",
|
||||
"integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
@@ -15429,9 +15382,9 @@
|
||||
}
|
||||
},
|
||||
"node-releases": {
|
||||
"version": "1.1.65",
|
||||
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.65.tgz",
|
||||
"integrity": "sha512-YpzJOe2WFIW0V4ZkJQd/DGR/zdVwc/pI4Nl1CZrBO19FdRcSTmsuhdttw9rsTzzJLrNcSloLiBbEYx1C4f6gpA=="
|
||||
"version": "1.1.66",
|
||||
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.66.tgz",
|
||||
"integrity": "sha512-JHEQ1iWPGK+38VLB2H9ef2otU4l8s3yAMt9Xf934r6+ojCYDMHPMqvCc9TnzfeFSP1QEOeU6YZEd3+De0LTCgg=="
|
||||
},
|
||||
"node-sass": {
|
||||
"version": "4.14.1",
|
||||
@@ -17705,9 +17658,9 @@
|
||||
}
|
||||
},
|
||||
"ws": {
|
||||
"version": "7.3.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.1.tgz",
|
||||
"integrity": "sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA==",
|
||||
"version": "7.4.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.0.tgz",
|
||||
"integrity": "sha512-kyFwXuV/5ymf+IXhS6f0+eAFvydbaBW3zjpT6hUdAh/hbVjTIB5EHBGi0bPoCLSK2wcuz3BrEkB9LrYv1Nm4NQ==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
@@ -21322,15 +21275,15 @@
|
||||
}
|
||||
},
|
||||
"tar-fs": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.0.tgz",
|
||||
"integrity": "sha512-9uW5iDvrIMCVpvasdFHW0wJPez0K4JnMZtsuIeDI7HyMGJNxmDZDOCQROr7lXyS+iL/QMpj07qcjGYTSdRFXUg==",
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz",
|
||||
"integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chownr": "^1.1.1",
|
||||
"mkdirp-classic": "^0.5.2",
|
||||
"pump": "^3.0.0",
|
||||
"tar-stream": "^2.0.0"
|
||||
"tar-stream": "^2.1.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"chownr": {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from "react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
|
||||
import { mount } from "enzyme";
|
||||
|
||||
@@ -27,7 +28,9 @@ describe("<FetchPauser />", () => {
|
||||
|
||||
it("unmounting FetchPauser resumes alertStore", () => {
|
||||
const tree = MountedFetchPauser();
|
||||
tree.unmount();
|
||||
act(() => {
|
||||
tree.unmount();
|
||||
});
|
||||
expect(alertStore.status.paused).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -69,16 +69,10 @@ const MockEmptyAPIResponseWithoutFilters = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const MountedFetcher = () => {
|
||||
return mount(
|
||||
<Fetcher alertStore={alertStore} settingsStore={settingsStore} />
|
||||
);
|
||||
};
|
||||
|
||||
describe("<Fetcher />", () => {
|
||||
it("changing interval changes how often fetch is called", () => {
|
||||
settingsStore.fetchConfig.setInterval(1);
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
advanceBy(3 * 1000);
|
||||
@@ -116,21 +110,23 @@ describe("<Fetcher />", () => {
|
||||
|
||||
it("calls alertStore.fetchWithThrottle on mount", () => {
|
||||
const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle");
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("calls alertStore.fetchWithThrottle again after filter change", () => {
|
||||
MockEmptyAPIResponseWithoutFilters();
|
||||
const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle");
|
||||
const tree = MountedFetcher();
|
||||
const tree = mount(
|
||||
<Fetcher alertStore={alertStore} settingsStore={settingsStore} />
|
||||
);
|
||||
alertStore.filters.setFilterValues([]);
|
||||
tree.setProps({});
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("keeps calling alertStore.fetchWithThrottle every minute", () => {
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
advanceBy(62 * 1000);
|
||||
@@ -156,7 +152,7 @@ describe("<Fetcher />", () => {
|
||||
MockEmptyAPIResponseWithoutFilters();
|
||||
const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle");
|
||||
settingsStore.gridConfig.setSortOrder("default");
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledWith("", false, "", "", "");
|
||||
});
|
||||
|
||||
@@ -165,7 +161,7 @@ describe("<Fetcher />", () => {
|
||||
const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle");
|
||||
settingsStore.gridConfig.setSortOrder("disabled");
|
||||
settingsStore.gridConfig.setSortReverse(false);
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledWith("", false, "disabled", "", "");
|
||||
});
|
||||
|
||||
@@ -174,7 +170,7 @@ describe("<Fetcher />", () => {
|
||||
const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle");
|
||||
settingsStore.gridConfig.setSortOrder("disabled");
|
||||
settingsStore.gridConfig.setSortReverse(true);
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledWith("", false, "disabled", "", "");
|
||||
});
|
||||
|
||||
@@ -183,7 +179,7 @@ describe("<Fetcher />", () => {
|
||||
const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle");
|
||||
settingsStore.gridConfig.setSortOrder("startsAt");
|
||||
settingsStore.gridConfig.setSortReverse(false);
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledWith("", false, "startsAt", "", "0");
|
||||
});
|
||||
|
||||
@@ -192,7 +188,7 @@ describe("<Fetcher />", () => {
|
||||
const fetchSpy = jest.spyOn(alertStore, "fetchWithThrottle");
|
||||
settingsStore.gridConfig.setSortOrder("startsAt");
|
||||
settingsStore.gridConfig.setSortReverse(true);
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledWith("", false, "startsAt", "", "1");
|
||||
});
|
||||
|
||||
@@ -202,7 +198,7 @@ describe("<Fetcher />", () => {
|
||||
settingsStore.gridConfig.setSortOrder("label");
|
||||
settingsStore.gridConfig.setSortLabel("cluster");
|
||||
settingsStore.gridConfig.setSortReverse(false);
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledWith("", false, "label", "cluster", "0");
|
||||
});
|
||||
|
||||
@@ -212,7 +208,7 @@ describe("<Fetcher />", () => {
|
||||
settingsStore.gridConfig.setSortOrder("label");
|
||||
settingsStore.gridConfig.setSortLabel("job");
|
||||
settingsStore.gridConfig.setSortReverse(true);
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledWith("", false, "label", "job", "1");
|
||||
});
|
||||
|
||||
@@ -222,7 +218,7 @@ describe("<Fetcher />", () => {
|
||||
settingsStore.gridConfig.setSortOrder("label");
|
||||
settingsStore.gridConfig.setSortLabel("instance");
|
||||
settingsStore.gridConfig.setSortReverse(null);
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledWith("", false, "label", "instance", "");
|
||||
});
|
||||
|
||||
@@ -232,7 +228,7 @@ describe("<Fetcher />", () => {
|
||||
settingsStore.gridConfig.setSortOrder("default");
|
||||
settingsStore.multiGridConfig.setGridLabel("cluster");
|
||||
settingsStore.multiGridConfig.setGridSortReverse(false);
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledWith("cluster", false, "", "", "");
|
||||
});
|
||||
|
||||
@@ -242,7 +238,7 @@ describe("<Fetcher />", () => {
|
||||
settingsStore.gridConfig.setSortOrder("default");
|
||||
settingsStore.multiGridConfig.setGridLabel("cluster");
|
||||
settingsStore.multiGridConfig.setGridSortReverse(true);
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledWith("cluster", true, "", "", "");
|
||||
});
|
||||
|
||||
@@ -252,21 +248,27 @@ describe("<Fetcher />", () => {
|
||||
settingsStore.gridConfig.setSortOrder("default");
|
||||
settingsStore.multiGridConfig.setGridLabel("");
|
||||
settingsStore.multiGridConfig.setGridSortReverse(true);
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledWith("", true, "", "", "");
|
||||
});
|
||||
|
||||
it("internal timer is null after unmount", () => {
|
||||
const tree = MountedFetcher();
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
tree.unmount();
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
settingsStore.gridConfig.setSortReverse(
|
||||
!settingsStore.gridConfig.config.reverseSort
|
||||
const tree = mount(
|
||||
<Fetcher alertStore={alertStore} settingsStore={settingsStore} />
|
||||
);
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
act(() => {
|
||||
tree.unmount();
|
||||
});
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
act(() => {
|
||||
settingsStore.gridConfig.setSortReverse(
|
||||
!settingsStore.gridConfig.config.reverseSort
|
||||
);
|
||||
});
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
act(() => {
|
||||
jest.runOnlyPendingTimers();
|
||||
});
|
||||
@@ -275,13 +277,13 @@ describe("<Fetcher />", () => {
|
||||
|
||||
it("doesn't fetch on mount when paused", () => {
|
||||
alertStore.status.pause();
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it("doesn't fetch on update when paused", () => {
|
||||
alertStore.status.pause();
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
settingsStore.gridConfig.setSortReverse(
|
||||
!settingsStore.gridConfig.config.reverseSort
|
||||
);
|
||||
@@ -290,7 +292,7 @@ describe("<Fetcher />", () => {
|
||||
|
||||
it("fetches on update when resumed", () => {
|
||||
alertStore.status.pause();
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
alertStore.status.resume();
|
||||
settingsStore.gridConfig.setSortReverse(
|
||||
!settingsStore.gridConfig.config.reverseSort
|
||||
@@ -303,7 +305,7 @@ describe("<Fetcher />", () => {
|
||||
|
||||
it("fetches on resume", () => {
|
||||
alertStore.status.pause();
|
||||
MountedFetcher();
|
||||
mount(<Fetcher alertStore={alertStore} settingsStore={settingsStore} />);
|
||||
alertStore.status.resume();
|
||||
advanceBy(2 * 1000);
|
||||
act(() => {
|
||||
@@ -315,7 +317,9 @@ describe("<Fetcher />", () => {
|
||||
|
||||
describe("<Fetcher /> children", () => {
|
||||
it("renders Dots when countdown is in progress", () => {
|
||||
const tree = MountedFetcher();
|
||||
const tree = mount(
|
||||
<Fetcher alertStore={alertStore} settingsStore={settingsStore} />
|
||||
);
|
||||
expect(tree.find("div.components-fetcher")).toHaveLength(1);
|
||||
});
|
||||
|
||||
@@ -323,12 +327,16 @@ describe("<Fetcher /> children", () => {
|
||||
act(() => {
|
||||
alertStore.info.upgradeNeeded = true;
|
||||
});
|
||||
const tree = MountedFetcher();
|
||||
const tree = mount(
|
||||
<Fetcher alertStore={alertStore} settingsStore={settingsStore} />
|
||||
);
|
||||
expect(tree.find("div.navbar-brand").children()).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("renders PauseButton when paused", () => {
|
||||
const tree = MountedFetcher();
|
||||
const tree = mount(
|
||||
<Fetcher alertStore={alertStore} settingsStore={settingsStore} />
|
||||
);
|
||||
act(() => {
|
||||
alertStore.status.pause();
|
||||
});
|
||||
@@ -336,7 +344,9 @@ describe("<Fetcher /> children", () => {
|
||||
});
|
||||
|
||||
it("renders PauseButton when paused and hovered", () => {
|
||||
const tree = MountedFetcher();
|
||||
const tree = mount(
|
||||
<Fetcher alertStore={alertStore} settingsStore={settingsStore} />
|
||||
);
|
||||
act(() => {
|
||||
alertStore.status.pause();
|
||||
});
|
||||
@@ -350,7 +360,9 @@ describe("<Fetcher /> children", () => {
|
||||
});
|
||||
|
||||
it("renders PlayButton when hovered", () => {
|
||||
const tree = MountedFetcher();
|
||||
const tree = mount(
|
||||
<Fetcher alertStore={alertStore} settingsStore={settingsStore} />
|
||||
);
|
||||
tree.find(".navbar-brand").simulate("mouseenter");
|
||||
tree.update();
|
||||
expect(toDiffableHtml(tree.html())).toMatch(/fa-play/);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from "react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
|
||||
import { mount, shallow } from "enzyme";
|
||||
|
||||
@@ -28,8 +29,12 @@ describe("<ReloadNeeded />", () => {
|
||||
const reloadSpy = jest
|
||||
.spyOn(global.window.location, "reload")
|
||||
.mockImplementation(() => {});
|
||||
|
||||
mount(<ReloadNeeded reloadAfter={100000000} />);
|
||||
jest.runOnlyPendingTimers();
|
||||
|
||||
act(() => {
|
||||
jest.runOnlyPendingTimers();
|
||||
});
|
||||
expect(reloadSpy).toBeCalled();
|
||||
});
|
||||
|
||||
@@ -37,9 +42,16 @@ describe("<ReloadNeeded />", () => {
|
||||
const reloadSpy = jest
|
||||
.spyOn(global.window.location, "reload")
|
||||
.mockImplementation(() => {});
|
||||
|
||||
const tree = mount(<ReloadNeeded reloadAfter={100000000} />);
|
||||
tree.unmount();
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(reloadSpy).not.toBeCalled();
|
||||
|
||||
act(() => {
|
||||
tree.unmount();
|
||||
});
|
||||
act(() => {
|
||||
jest.runOnlyPendingTimers();
|
||||
});
|
||||
expect(reloadSpy).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from "react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
|
||||
import { mount, shallow } from "enzyme";
|
||||
|
||||
@@ -30,8 +31,12 @@ describe("<UpgradeNeeded />", () => {
|
||||
const reloadSpy = jest
|
||||
.spyOn(global.window.location, "reload")
|
||||
.mockImplementation(() => {});
|
||||
|
||||
mount(<UpgradeNeeded newVersion="1.2.3" reloadAfter={100000000} />);
|
||||
jest.runOnlyPendingTimers();
|
||||
|
||||
act(() => {
|
||||
jest.runOnlyPendingTimers();
|
||||
});
|
||||
expect(reloadSpy).toBeCalled();
|
||||
});
|
||||
|
||||
@@ -39,11 +44,19 @@ describe("<UpgradeNeeded />", () => {
|
||||
const reloadSpy = jest
|
||||
.spyOn(global.window.location, "reload")
|
||||
.mockImplementation(() => {});
|
||||
|
||||
const tree = mount(
|
||||
<UpgradeNeeded newVersion="1.2.3" reloadAfter={100000000} />
|
||||
);
|
||||
tree.unmount();
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(reloadSpy).not.toBeCalled();
|
||||
|
||||
act(() => {
|
||||
tree.unmount();
|
||||
});
|
||||
|
||||
act(() => {
|
||||
jest.runOnlyPendingTimers();
|
||||
});
|
||||
expect(reloadSpy).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,11 +8,9 @@ import { InhibitedByModal } from ".";
|
||||
|
||||
let alertStore: AlertStore;
|
||||
|
||||
beforeAll(() => {
|
||||
jest.useFakeTimers();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
alertStore = new AlertStore([]);
|
||||
});
|
||||
|
||||
@@ -107,9 +105,13 @@ describe("<InhibitedByModal />", () => {
|
||||
const tree = mount(
|
||||
<InhibitedByModal alertStore={alertStore} fingerprints={["foo=bar"]} />
|
||||
);
|
||||
|
||||
const toggle = tree.find("span.badge.badge-light");
|
||||
toggle.simulate("click");
|
||||
tree.unmount();
|
||||
|
||||
act(() => {
|
||||
tree.unmount();
|
||||
});
|
||||
expect(document.body.className.split(" ")).not.toContain("modal-open");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,17 +59,6 @@ afterEach(() => {
|
||||
|
||||
const MockOnHide = jest.fn();
|
||||
|
||||
const MountedDeleteSilence = () => {
|
||||
return mount(
|
||||
<DeleteSilence
|
||||
alertStore={alertStore}
|
||||
silenceFormStore={silenceFormStore}
|
||||
cluster={cluster}
|
||||
silence={silence}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const MountedDeleteSilenceModalContent = () => {
|
||||
return mount(
|
||||
<DeleteSilenceModalContent
|
||||
@@ -84,18 +73,39 @@ const MountedDeleteSilenceModalContent = () => {
|
||||
|
||||
describe("<DeleteSilence />", () => {
|
||||
it("label is 'Delete' by default", () => {
|
||||
const tree = MountedDeleteSilence();
|
||||
const tree = mount(
|
||||
<DeleteSilence
|
||||
alertStore={alertStore}
|
||||
silenceFormStore={silenceFormStore}
|
||||
cluster={cluster}
|
||||
silence={silence}
|
||||
/>
|
||||
);
|
||||
expect(tree.text()).toBe("Delete");
|
||||
});
|
||||
|
||||
it("opens modal on click", () => {
|
||||
const tree = MountedDeleteSilence();
|
||||
const tree = mount(
|
||||
<DeleteSilence
|
||||
alertStore={alertStore}
|
||||
silenceFormStore={silenceFormStore}
|
||||
cluster={cluster}
|
||||
silence={silence}
|
||||
/>
|
||||
);
|
||||
tree.find("button.btn-danger").simulate("click");
|
||||
expect(tree.find(".modal-body")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("closes modal on close button click", () => {
|
||||
const tree = MountedDeleteSilence();
|
||||
const tree = mount(
|
||||
<DeleteSilence
|
||||
alertStore={alertStore}
|
||||
silenceFormStore={silenceFormStore}
|
||||
cluster={cluster}
|
||||
silence={silence}
|
||||
/>
|
||||
);
|
||||
tree.find("button.btn-danger").simulate("click");
|
||||
expect(tree.find(".modal-body")).toHaveLength(1);
|
||||
|
||||
@@ -108,7 +118,14 @@ describe("<DeleteSilence />", () => {
|
||||
});
|
||||
|
||||
it("closes modal on esc button press", () => {
|
||||
const tree = MountedDeleteSilence();
|
||||
const tree = mount(
|
||||
<DeleteSilence
|
||||
alertStore={alertStore}
|
||||
silenceFormStore={silenceFormStore}
|
||||
cluster={cluster}
|
||||
silence={silence}
|
||||
/>
|
||||
);
|
||||
tree.find("button.btn-danger").simulate("click");
|
||||
expect(tree.find(".modal-body")).toHaveLength(1);
|
||||
|
||||
@@ -122,7 +139,14 @@ describe("<DeleteSilence />", () => {
|
||||
|
||||
it("button is disabled when all alertmanager instances are read-only", () => {
|
||||
alertStore.data.upstreams.instances[0].readonly = true;
|
||||
const tree = MountedDeleteSilence();
|
||||
const tree = mount(
|
||||
<DeleteSilence
|
||||
alertStore={alertStore}
|
||||
silenceFormStore={silenceFormStore}
|
||||
cluster={cluster}
|
||||
silence={silence}
|
||||
/>
|
||||
);
|
||||
expect(tree.find("button").prop("disabled")).toBe(true);
|
||||
|
||||
tree.find("button").at(0).simulate("click");
|
||||
@@ -140,7 +164,9 @@ describe("<DeleteSilenceModalContent />", () => {
|
||||
it("unblurs silence form on unmount", () => {
|
||||
const tree = MountedDeleteSilenceModalContent();
|
||||
expect(silenceFormStore.toggle.blurred).toBe(true);
|
||||
tree.unmount();
|
||||
act(() => {
|
||||
tree.unmount();
|
||||
});
|
||||
expect(silenceFormStore.toggle.blurred).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from "react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
|
||||
import { mount } from "enzyme";
|
||||
|
||||
@@ -61,7 +62,9 @@ describe("<ModalInner />", () => {
|
||||
|
||||
it("'modal-open' class is removed from body node after modal is unmounted", () => {
|
||||
const tree = MountedModal(true);
|
||||
tree.unmount();
|
||||
act(() => {
|
||||
tree.unmount();
|
||||
});
|
||||
expect(document.body.className.split(" ")).not.toContain("modal-open");
|
||||
});
|
||||
|
||||
@@ -88,7 +91,9 @@ describe("<ModalInner />", () => {
|
||||
const tree = MountedModal(true, true);
|
||||
expect(document.body.className.split(" ")).toContain("modal-open");
|
||||
|
||||
tree.unmount();
|
||||
act(() => {
|
||||
tree.unmount();
|
||||
});
|
||||
expect(document.body.className.split(" ")).toContain("modal-open");
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from "react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
|
||||
import { renderHook } from "@testing-library/react-hooks";
|
||||
|
||||
@@ -176,7 +177,7 @@ describe("useFetchAny", () => {
|
||||
|
||||
const upstreams = [{ uri: "http://localhost/slow/ok", options: {} }];
|
||||
const Component = () => {
|
||||
const { response, error, inProgress } = useFetchAny(upstreams);
|
||||
const { response, error, inProgress } = useFetchAny<string>(upstreams);
|
||||
return (
|
||||
<span>
|
||||
<span>{response}</span>
|
||||
@@ -201,7 +202,7 @@ describe("useFetchAny", () => {
|
||||
|
||||
const upstreams = [{ uri: "http://localhost/slow/500", options: {} }];
|
||||
const Component = () => {
|
||||
const { response, error, inProgress } = useFetchAny(upstreams);
|
||||
const { response, error, inProgress } = useFetchAny<string>(upstreams);
|
||||
return (
|
||||
<span>
|
||||
<span>{response}</span>
|
||||
@@ -211,8 +212,10 @@ describe("useFetchAny", () => {
|
||||
);
|
||||
};
|
||||
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
act(() => {
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
});
|
||||
|
||||
await fetchMock.flush(true);
|
||||
});
|
||||
@@ -225,7 +228,7 @@ describe("useFetchAny", () => {
|
||||
|
||||
const upstreams = [{ uri: "http://localhost/slow/error", options: {} }];
|
||||
const Component = () => {
|
||||
const { response, error, inProgress } = useFetchAny(upstreams);
|
||||
const { response, error, inProgress } = useFetchAny<string>(upstreams);
|
||||
return (
|
||||
<span>
|
||||
<span>{response}</span>
|
||||
@@ -235,8 +238,10 @@ describe("useFetchAny", () => {
|
||||
);
|
||||
};
|
||||
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
act(() => {
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
});
|
||||
|
||||
await fetchMock.flush(true);
|
||||
});
|
||||
@@ -332,7 +337,9 @@ describe("useFetchAny", () => {
|
||||
get: () => "text/plain",
|
||||
},
|
||||
text: async () => {
|
||||
tree.unmount();
|
||||
act(() => {
|
||||
tree.unmount();
|
||||
});
|
||||
return "ok";
|
||||
},
|
||||
})
|
||||
@@ -340,7 +347,7 @@ describe("useFetchAny", () => {
|
||||
|
||||
const upstreams = [{ uri: "http://localhost/slow/body", options: {} }];
|
||||
const Component = () => {
|
||||
const { response, error, inProgress } = useFetchAny(upstreams, {
|
||||
const { response, error, inProgress } = useFetchAny<string>(upstreams, {
|
||||
fetcher: fetcher,
|
||||
});
|
||||
return (
|
||||
@@ -352,6 +359,8 @@ describe("useFetchAny", () => {
|
||||
);
|
||||
};
|
||||
|
||||
tree = mount(<Component />);
|
||||
act(() => {
|
||||
tree = mount(<Component />);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from "react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
|
||||
import { renderHook } from "@testing-library/react-hooks";
|
||||
|
||||
@@ -155,8 +156,10 @@ describe("useFetchDelete", () => {
|
||||
);
|
||||
};
|
||||
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
act(() => {
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
});
|
||||
|
||||
await fetchMock.flush(true);
|
||||
});
|
||||
@@ -181,8 +184,10 @@ describe("useFetchDelete", () => {
|
||||
);
|
||||
};
|
||||
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
act(() => {
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
});
|
||||
|
||||
await fetchMock.flush(true);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from "react";
|
||||
import { act as actReact } from "react-dom/test-utils";
|
||||
|
||||
import { renderHook, act } from "@testing-library/react-hooks";
|
||||
|
||||
@@ -252,8 +253,10 @@ describe("useFetchGet", () => {
|
||||
);
|
||||
};
|
||||
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
actReact(() => {
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
});
|
||||
|
||||
for (let i = 0; i <= FetchRetryConfig.retries; i++) {
|
||||
jest.runOnlyPendingTimers();
|
||||
@@ -281,8 +284,10 @@ describe("useFetchGet", () => {
|
||||
);
|
||||
};
|
||||
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
actReact(() => {
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
});
|
||||
|
||||
for (let i = 0; i <= FetchRetryConfig.retries; i++) {
|
||||
jest.runOnlyPendingTimers();
|
||||
@@ -309,8 +314,10 @@ describe("useFetchGet", () => {
|
||||
);
|
||||
};
|
||||
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
actReact(() => {
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
});
|
||||
|
||||
for (let i = 0; i <= FetchRetryConfig.retries; i++) {
|
||||
jest.runOnlyPendingTimers();
|
||||
@@ -338,8 +345,10 @@ describe("useFetchGet", () => {
|
||||
);
|
||||
};
|
||||
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
actReact(() => {
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
});
|
||||
|
||||
jest.runOnlyPendingTimers();
|
||||
await fetchMock.flush(true);
|
||||
@@ -364,8 +373,10 @@ describe("useFetchGet", () => {
|
||||
);
|
||||
};
|
||||
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
actReact(() => {
|
||||
const tree = mount(<Component />);
|
||||
tree.unmount();
|
||||
});
|
||||
|
||||
jest.runOnlyPendingTimers();
|
||||
await fetchMock.flush(true);
|
||||
@@ -381,7 +392,9 @@ describe("useFetchGet", () => {
|
||||
get: () => "text/plain",
|
||||
},
|
||||
text: async () => {
|
||||
tree.unmount();
|
||||
actReact(() => {
|
||||
tree.unmount();
|
||||
});
|
||||
return "ok";
|
||||
},
|
||||
} as any);
|
||||
@@ -401,6 +414,8 @@ describe("useFetchGet", () => {
|
||||
);
|
||||
};
|
||||
|
||||
tree = mount(<Component />);
|
||||
actReact(() => {
|
||||
tree = mount(<Component />);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user