From 9cdd8da178db923c47f773f54bf9953eb45c8dca Mon Sep 17 00:00:00 2001 From: phntxx Date: Thu, 24 Jun 2021 12:25:25 +0200 Subject: [PATCH] Update existing tests --- src/components/appList.tsx | 37 ++++++++++++------- src/components/imprint.tsx | 16 ++++---- .../__snapshots__/appList.spec.tsx.snap | 8 +++- src/test/components/appList.spec.tsx | 27 +++++++++++--- src/test/components/greeter.spec.tsx | 4 +- src/test/components/imprint.spec.tsx | 19 ++++++---- 6 files changed, 73 insertions(+), 38 deletions(-) diff --git a/src/components/appList.tsx b/src/components/appList.tsx index 6319acf..57d607a 100644 --- a/src/components/appList.tsx +++ b/src/components/appList.tsx @@ -4,8 +4,8 @@ import { IAppProps } from "./app"; import { Headline, ListContainer } from "./elements"; export interface IAppListProps { - categories: Array; - apps: Array; + categories?: Array; + apps?: Array; } /** @@ -13,17 +13,26 @@ export interface IAppListProps { * @param {IAppListProps} props props of the given list of apps * @returns {React.ReactNode} the app list component */ -const AppList = ({ categories, apps }: IAppListProps) => ( - - Applications - {categories && - categories.map(({ name, items }, idx) => ( - - ))} - {apps && ( - - )} - -); +const AppList = ({ categories, apps }: IAppListProps) => { + if (apps || categories) { + return ( + + Applications + {categories && + categories.map(({ name, items }, idx) => ( + + ))} + {apps && ( + + )} + + ); + } else { + return <>; + } +}; export default AppList; diff --git a/src/components/imprint.tsx b/src/components/imprint.tsx index ad2f828..68b07a3 100644 --- a/src/components/imprint.tsx +++ b/src/components/imprint.tsx @@ -1,4 +1,3 @@ -import React from "react"; import Modal from "./modal"; import styled from "styled-components"; import selectedTheme from "../lib/theme"; @@ -63,6 +62,12 @@ export const ImprintField = ({ field }: IImprintFieldComponentProps) => ( {field.text} ); +export const onClose = () => { + if (window.location.href.endsWith("#imprint")) { + window.location.href = window.location.href.replace("#imprint", ""); + } +}; + /** * Renders the imprint component * @param {IImprintProps} props contents of the imprint @@ -80,14 +85,7 @@ const Imprint = ({ imprint }: IImprintComponentProps) => ( text="View Imprint" title="Legal Disclosure" condition={!window.location.href.endsWith("#imprint")} - onClose={() => { - if (window.location.href.endsWith("#imprint")) { - window.location.href = window.location.href.replace( - "#imprint", - "", - ); - } - }} + onClose={onClose} >
diff --git a/src/test/components/__snapshots__/appList.spec.tsx.snap b/src/test/components/__snapshots__/appList.spec.tsx.snap index 6cdc7df..9535b28 100644 --- a/src/test/components/__snapshots__/appList.spec.tsx.snap +++ b/src/test/components/__snapshots__/appList.spec.tsx.snap @@ -1,3 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`AppList snapshot test 1`] = `[Function]`; +exports[`appList.tsx Tests AppList rendering with apps 1`] = `[Function]`; + +exports[`appList.tsx Tests AppList rendering with categories 1`] = `[Function]`; + +exports[`appList.tsx Tests AppList rendering with categories and apps 1`] = `[Function]`; + +exports[`appList.tsx Tests AppList rendering with neither 1`] = `[Function]`; diff --git a/src/test/components/appList.spec.tsx b/src/test/components/appList.spec.tsx index 32916b4..4c879b0 100644 --- a/src/test/components/appList.spec.tsx +++ b/src/test/components/appList.spec.tsx @@ -34,10 +34,27 @@ const props: IAppListProps = { ], }; -it("AppList snapshot test", () => { - const { asFragment } = render( - , - ); +describe("appList.tsx", () => { + it("Tests AppList rendering with categories and apps", () => { + const { asFragment } = render( + , + ); - expect(asFragment).toMatchSnapshot(); + expect(asFragment).toMatchSnapshot(); + }); + + it("Tests AppList rendering with categories", () => { + const { asFragment } = render(); + expect(asFragment).toMatchSnapshot(); + }); + + it("Tests AppList rendering with apps", () => { + const { asFragment } = render(); + expect(asFragment).toMatchSnapshot(); + }); + + it("Tests AppList rendering with neither", () => { + const { asFragment } = render(); + expect(asFragment).toMatchSnapshot(); + }); }); diff --git a/src/test/components/greeter.spec.tsx b/src/test/components/greeter.spec.tsx index 49818fa..62caa4e 100644 --- a/src/test/components/greeter.spec.tsx +++ b/src/test/components/greeter.spec.tsx @@ -64,11 +64,11 @@ it("isBetween test", () => { }); it("getExtension test", () => { + expect(getExtension(0)).toEqual(""); expect(getExtension(1)).toEqual("st"); expect(getExtension(2)).toEqual("nd"); expect(getExtension(3)).toEqual("rd"); - expect(getExtension(4)).toEqual("th"); - expect(getExtension(55)).toEqual("th"); + expect(getExtension(15)).toEqual("th"); }); it("Greeter snapshot test", () => { diff --git a/src/test/components/imprint.spec.tsx b/src/test/components/imprint.spec.tsx index 5afc709..4aeccfc 100644 --- a/src/test/components/imprint.spec.tsx +++ b/src/test/components/imprint.spec.tsx @@ -1,5 +1,9 @@ import { fireEvent, render } from "@testing-library/react"; -import Imprint, { IImprintProps, ImprintField } from "../../components/imprint"; +import Imprint, { + IImprintProps, + ImprintField, + onClose, +} from "../../components/imprint"; const props: IImprintProps = { name: { @@ -43,15 +47,16 @@ describe("imprint.tsx", () => { expect(asFragment).toMatchSnapshot(); }); - it("Tests #imprint", () => { + it("Tests onClose with #imprint", () => { const location = window.location.href; window.location.href = location + "#imprint"; + onClose(); + expect(window.location.href).toEqual(location); + }); - const imprintModal = render(); - - fireEvent.click(imprintModal.getByTestId("toggle-button")); - //fireEvent.click(imprintModal.getByTestId("close-button")); - + it("Tests onClose without #imprint", () => { + const location = window.location.href; + onClose(); expect(window.location.href).toEqual(location); });