From d8124d37e4011a308437f99bc11892ddb2395066 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 30 Sep 2022 18:27:59 +0100 Subject: [PATCH] Improve coverage (#23380) --- .../views/auth/VectorAuthHeaderLogo.tsx | 2 +- src/components/views/auth/VectorAuthPage.tsx | 8 +-- .../views/auth/VectorAuthFooter-test.tsx | 27 +++++++++ .../views/auth/VectorAuthHeaderLogo-test.tsx | 27 +++++++++ .../views/auth/VectorAuthPage-test.tsx | 27 +++++++++ .../VectorAuthFooter-test.tsx.snap | 39 +++++++++++++ .../VectorAuthHeaderLogo-test.tsx.snap | 14 +++++ .../VectorAuthPage-test.tsx.snap | 56 +++++++++++++++++++ .../vector/platform/WebPlatform-test.ts | 39 +++++++++++++ 9 files changed, 234 insertions(+), 5 deletions(-) create mode 100644 test/unit-tests/components/views/auth/VectorAuthFooter-test.tsx create mode 100644 test/unit-tests/components/views/auth/VectorAuthHeaderLogo-test.tsx create mode 100644 test/unit-tests/components/views/auth/VectorAuthPage-test.tsx create mode 100644 test/unit-tests/components/views/auth/__snapshots__/VectorAuthFooter-test.tsx.snap create mode 100644 test/unit-tests/components/views/auth/__snapshots__/VectorAuthHeaderLogo-test.tsx.snap create mode 100644 test/unit-tests/components/views/auth/__snapshots__/VectorAuthPage-test.tsx.snap diff --git a/src/components/views/auth/VectorAuthHeaderLogo.tsx b/src/components/views/auth/VectorAuthHeaderLogo.tsx index 2d66b08656..eaa60cf7ee 100644 --- a/src/components/views/auth/VectorAuthHeaderLogo.tsx +++ b/src/components/views/auth/VectorAuthHeaderLogo.tsx @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React from 'react'; +import * as React from 'react'; import SdkConfig from 'matrix-react-sdk/src/SdkConfig'; export default class VectorAuthHeaderLogo extends React.PureComponent { diff --git a/src/components/views/auth/VectorAuthPage.tsx b/src/components/views/auth/VectorAuthPage.tsx index d2e6d9f8db..6b0004cf1b 100644 --- a/src/components/views/auth/VectorAuthPage.tsx +++ b/src/components/views/auth/VectorAuthPage.tsx @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React, { CSSProperties } from 'react'; +import * as React from 'react'; import SdkConfig from 'matrix-react-sdk/src/SdkConfig'; import VectorAuthFooter from "./VectorAuthFooter"; @@ -47,12 +47,12 @@ export default class VectorAuthPage extends React.PureComponent { background: `center/cover fixed url(${VectorAuthPage.getWelcomeBackgroundUrl()})`, }; - const modalStyle: CSSProperties = { + const modalStyle: React.CSSProperties = { position: 'relative', background: 'initial', }; - const blurStyle: CSSProperties = { + const blurStyle: React.CSSProperties = { position: 'absolute', top: 0, right: 0, @@ -62,7 +62,7 @@ export default class VectorAuthPage extends React.PureComponent { background: pageStyle.background, }; - const modalContentStyle: CSSProperties = { + const modalContentStyle: React.CSSProperties = { display: 'flex', zIndex: 1, background: 'rgba(255, 255, 255, 0.59)', diff --git a/test/unit-tests/components/views/auth/VectorAuthFooter-test.tsx b/test/unit-tests/components/views/auth/VectorAuthFooter-test.tsx new file mode 100644 index 0000000000..22e13d3f7b --- /dev/null +++ b/test/unit-tests/components/views/auth/VectorAuthFooter-test.tsx @@ -0,0 +1,27 @@ +/* +Copyright 2022 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import * as React from "react"; +import { render } from "@testing-library/react"; + +import VectorAuthFooter from "../../../../../src/components/views/auth/VectorAuthFooter"; + +describe("", () => { + it("should match snapshot", () => { + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); + }); +}); diff --git a/test/unit-tests/components/views/auth/VectorAuthHeaderLogo-test.tsx b/test/unit-tests/components/views/auth/VectorAuthHeaderLogo-test.tsx new file mode 100644 index 0000000000..ff86d78425 --- /dev/null +++ b/test/unit-tests/components/views/auth/VectorAuthHeaderLogo-test.tsx @@ -0,0 +1,27 @@ +/* +Copyright 2022 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import * as React from "react"; +import { render } from "@testing-library/react"; + +import VectorAuthHeaderLogo from "../../../../../src/components/views/auth/VectorAuthHeaderLogo"; + +describe("", () => { + it("should match snapshot", () => { + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); + }); +}); diff --git a/test/unit-tests/components/views/auth/VectorAuthPage-test.tsx b/test/unit-tests/components/views/auth/VectorAuthPage-test.tsx new file mode 100644 index 0000000000..72e432506a --- /dev/null +++ b/test/unit-tests/components/views/auth/VectorAuthPage-test.tsx @@ -0,0 +1,27 @@ +/* +Copyright 2022 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import * as React from "react"; +import { render } from "@testing-library/react"; + +import VectorAuthPage from "../../../../../src/components/views/auth/VectorAuthPage"; + +describe("", () => { + it("should match snapshot", () => { + const { asFragment } = render(); + expect(asFragment()).toMatchSnapshot(); + }); +}); diff --git a/test/unit-tests/components/views/auth/__snapshots__/VectorAuthFooter-test.tsx.snap b/test/unit-tests/components/views/auth/__snapshots__/VectorAuthFooter-test.tsx.snap new file mode 100644 index 0000000000..04d04c4570 --- /dev/null +++ b/test/unit-tests/components/views/auth/__snapshots__/VectorAuthFooter-test.tsx.snap @@ -0,0 +1,39 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should match snapshot 1`] = ` + + + +`; diff --git a/test/unit-tests/components/views/auth/__snapshots__/VectorAuthHeaderLogo-test.tsx.snap b/test/unit-tests/components/views/auth/__snapshots__/VectorAuthHeaderLogo-test.tsx.snap new file mode 100644 index 0000000000..bb0fc945f1 --- /dev/null +++ b/test/unit-tests/components/views/auth/__snapshots__/VectorAuthHeaderLogo-test.tsx.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should match snapshot 1`] = ` + + + +`; diff --git a/test/unit-tests/components/views/auth/__snapshots__/VectorAuthPage-test.tsx.snap b/test/unit-tests/components/views/auth/__snapshots__/VectorAuthPage-test.tsx.snap new file mode 100644 index 0000000000..ebf6c5c305 --- /dev/null +++ b/test/unit-tests/components/views/auth/__snapshots__/VectorAuthPage-test.tsx.snap @@ -0,0 +1,56 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should match snapshot 1`] = ` + +
+
+ + +`; diff --git a/test/unit-tests/vector/platform/WebPlatform-test.ts b/test/unit-tests/vector/platform/WebPlatform-test.ts index 39d4af2b5f..ced944e688 100644 --- a/test/unit-tests/vector/platform/WebPlatform-test.ts +++ b/test/unit-tests/vector/platform/WebPlatform-test.ts @@ -37,6 +37,45 @@ describe('WebPlatform', () => { expect(navigator.serviceWorker.register).toHaveBeenCalled(); }); + it("should call reload on window location object", () => { + delete window.location; + window.location = { + reload: jest.fn(), + } as unknown as Location; + + const platform = new WebPlatform(); + expect(window.location.reload).not.toHaveBeenCalled(); + platform.reload(); + expect(window.location.reload).toHaveBeenCalled(); + }); + + it("should call reload to install update", () => { + delete window.location; + window.location = { + reload: jest.fn(), + } as unknown as Location; + + const platform = new WebPlatform(); + expect(window.location.reload).not.toHaveBeenCalled(); + platform.installUpdate(); + expect(window.location.reload).toHaveBeenCalled(); + }); + + describe("getDefaultDeviceDisplayName", () => { + it.each([[ + "https://develop.element.io/#/room/!foo:bar", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36", + "develop.element.io (Chrome, macOS)", + ]])("%s & %s = %s", (url, userAgent, result) => { + delete window.navigator; + window.navigator = { userAgent } as unknown as Navigator; + delete window.location; + window.location = { href: url } as unknown as Location; + const platform = new WebPlatform(); + expect(platform.getDefaultDeviceDisplayName()).toEqual(result); + }); + }); + describe('notification support', () => { const mockNotification = { requestPermission: jest.fn(),