Update existing tests

This commit is contained in:
phntxx 2021-06-24 12:25:25 +02:00
parent ee30f05e72
commit 9cdd8da178
6 changed files with 73 additions and 38 deletions

View file

@ -4,8 +4,8 @@ import { IAppProps } from "./app";
import { Headline, ListContainer } from "./elements"; import { Headline, ListContainer } from "./elements";
export interface IAppListProps { export interface IAppListProps {
categories: Array<IAppCategoryProps>; categories?: Array<IAppCategoryProps>;
apps: Array<IAppProps>; apps?: Array<IAppProps>;
} }
/** /**
@ -13,17 +13,26 @@ export interface IAppListProps {
* @param {IAppListProps} props props of the given list of apps * @param {IAppListProps} props props of the given list of apps
* @returns {React.ReactNode} the app list component * @returns {React.ReactNode} the app list component
*/ */
const AppList = ({ categories, apps }: IAppListProps) => ( const AppList = ({ categories, apps }: IAppListProps) => {
<ListContainer> if (apps || categories) {
<Headline>Applications</Headline> return (
{categories && <ListContainer>
categories.map(({ name, items }, idx) => ( <Headline>Applications</Headline>
<AppCategory key={[name, idx].join("")} name={name} items={items} /> {categories &&
))} categories.map(({ name, items }, idx) => (
{apps && ( <AppCategory key={[name, idx].join("")} name={name} items={items} />
<AppCategory name={categories ? "Uncategorized apps" : ""} items={apps} /> ))}
)} {apps && (
</ListContainer> <AppCategory
); name={categories ? "Uncategorized apps" : ""}
items={apps}
/>
)}
</ListContainer>
);
} else {
return <></>;
}
};
export default AppList; export default AppList;

View file

@ -1,4 +1,3 @@
import React from "react";
import Modal from "./modal"; import Modal from "./modal";
import styled from "styled-components"; import styled from "styled-components";
import selectedTheme from "../lib/theme"; import selectedTheme from "../lib/theme";
@ -63,6 +62,12 @@ export const ImprintField = ({ field }: IImprintFieldComponentProps) => (
<Link href={field.link}>{field.text}</Link> <Link href={field.link}>{field.text}</Link>
); );
export const onClose = () => {
if (window.location.href.endsWith("#imprint")) {
window.location.href = window.location.href.replace("#imprint", "");
}
};
/** /**
* Renders the imprint component * Renders the imprint component
* @param {IImprintProps} props contents of the imprint * @param {IImprintProps} props contents of the imprint
@ -80,14 +85,7 @@ const Imprint = ({ imprint }: IImprintComponentProps) => (
text="View Imprint" text="View Imprint"
title="Legal Disclosure" title="Legal Disclosure"
condition={!window.location.href.endsWith("#imprint")} condition={!window.location.href.endsWith("#imprint")}
onClose={() => { onClose={onClose}
if (window.location.href.endsWith("#imprint")) {
window.location.href = window.location.href.replace(
"#imprint",
"",
);
}
}}
> >
<div> <div>
<ModalSubHeadline> <ModalSubHeadline>

View file

@ -1,3 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // 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]`;

View file

@ -34,10 +34,27 @@ const props: IAppListProps = {
], ],
}; };
it("AppList snapshot test", () => { describe("appList.tsx", () => {
const { asFragment } = render( it("Tests AppList rendering with categories and apps", () => {
<AppList categories={props.categories} apps={props.apps} />, const { asFragment } = render(
); <AppList categories={props.categories} apps={props.apps} />,
);
expect(asFragment).toMatchSnapshot(); expect(asFragment).toMatchSnapshot();
});
it("Tests AppList rendering with categories", () => {
const { asFragment } = render(<AppList categories={props.categories} />);
expect(asFragment).toMatchSnapshot();
});
it("Tests AppList rendering with apps", () => {
const { asFragment } = render(<AppList apps={props.apps} />);
expect(asFragment).toMatchSnapshot();
});
it("Tests AppList rendering with neither", () => {
const { asFragment } = render(<AppList />);
expect(asFragment).toMatchSnapshot();
});
}); });

View file

@ -64,11 +64,11 @@ it("isBetween test", () => {
}); });
it("getExtension test", () => { it("getExtension test", () => {
expect(getExtension(0)).toEqual("");
expect(getExtension(1)).toEqual("st"); expect(getExtension(1)).toEqual("st");
expect(getExtension(2)).toEqual("nd"); expect(getExtension(2)).toEqual("nd");
expect(getExtension(3)).toEqual("rd"); expect(getExtension(3)).toEqual("rd");
expect(getExtension(4)).toEqual("th"); expect(getExtension(15)).toEqual("th");
expect(getExtension(55)).toEqual("th");
}); });
it("Greeter snapshot test", () => { it("Greeter snapshot test", () => {

View file

@ -1,5 +1,9 @@
import { fireEvent, render } from "@testing-library/react"; 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 = { const props: IImprintProps = {
name: { name: {
@ -43,15 +47,16 @@ describe("imprint.tsx", () => {
expect(asFragment).toMatchSnapshot(); expect(asFragment).toMatchSnapshot();
}); });
it("Tests #imprint", () => { it("Tests onClose with #imprint", () => {
const location = window.location.href; const location = window.location.href;
window.location.href = location + "#imprint"; window.location.href = location + "#imprint";
onClose();
expect(window.location.href).toEqual(location);
});
const imprintModal = render(<Imprint imprint={props} />); it("Tests onClose without #imprint", () => {
const location = window.location.href;
fireEvent.click(imprintModal.getByTestId("toggle-button")); onClose();
//fireEvent.click(imprintModal.getByTestId("close-button"));
expect(window.location.href).toEqual(location); expect(window.location.href).toEqual(location);
}); });