From 286beb4b2699060da7e2173a3e28b0b730326dbd Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Mon, 19 Jul 2021 11:11:12 +0300 Subject: [PATCH] Adding RenderDelay tests Signed-off-by: Alex Andreev --- __mocks__/windowMock.ts | 32 ++++++++++++++++ package.json | 3 +- .../__tests__/render-delay.test.tsx | 38 +++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 __mocks__/windowMock.ts create mode 100644 src/renderer/components/render-delay/__tests__/render-delay.test.tsx diff --git a/__mocks__/windowMock.ts b/__mocks__/windowMock.ts new file mode 100644 index 0000000000..baf8fa1a65 --- /dev/null +++ b/__mocks__/windowMock.ts @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +Object.defineProperty(window, "requestIdleCallback", { + writable: true, + value: jest.fn().mockImplementation(callback => callback()), +}); + +Object.defineProperty(window, "cancelIdleCallback", { + writable: true, + value: jest.fn(), +}); + +export default {}; diff --git a/package.json b/package.json index e51b56986d..cc6c583332 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,8 @@ }, "moduleNameMapper": { "\\.(css|scss)$": "/__mocks__/styleMock.ts", - "\\.(svg)$": "/__mocks__/imageMock.ts" + "\\.(svg)$": "/__mocks__/imageMock.ts", + "src/(.*)": "/__mocks__/windowMock.ts" }, "modulePathIgnorePatterns": [ "/dist", diff --git a/src/renderer/components/render-delay/__tests__/render-delay.test.tsx b/src/renderer/components/render-delay/__tests__/render-delay.test.tsx new file mode 100644 index 0000000000..f81003e588 --- /dev/null +++ b/src/renderer/components/render-delay/__tests__/render-delay.test.tsx @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2021 OpenLens Authors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +import React from "react"; +import "@testing-library/jest-dom/extend-expect"; +import { render } from "@testing-library/react"; +import { RenderDelay } from "../render-delay"; + +describe("", () => { + it("renders w/o errors", () => { + const { container } = render(); + + expect(container).toBeInstanceOf(HTMLElement); + }); + + it("renders it's child", () => { + const { getByText } = render(); + + expect(getByText("My button")).toBeInTheDocument(); + }); +});