Update existing tests
This commit is contained in:
parent
ee30f05e72
commit
9cdd8da178
6 changed files with 73 additions and 38 deletions
|
@ -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,7 +13,9 @@ 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) => {
|
||||||
|
if (apps || categories) {
|
||||||
|
return (
|
||||||
<ListContainer>
|
<ListContainer>
|
||||||
<Headline>Applications</Headline>
|
<Headline>Applications</Headline>
|
||||||
{categories &&
|
{categories &&
|
||||||
|
@ -21,9 +23,16 @@ const AppList = ({ categories, apps }: IAppListProps) => (
|
||||||
<AppCategory key={[name, idx].join("")} name={name} items={items} />
|
<AppCategory key={[name, idx].join("")} name={name} items={items} />
|
||||||
))}
|
))}
|
||||||
{apps && (
|
{apps && (
|
||||||
<AppCategory name={categories ? "Uncategorized apps" : ""} items={apps} />
|
<AppCategory
|
||||||
|
name={categories ? "Uncategorized apps" : ""}
|
||||||
|
items={apps}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</ListContainer>
|
</ListContainer>
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export default AppList;
|
export default AppList;
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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]`;
|
||||||
|
|
|
@ -34,10 +34,27 @@ const props: IAppListProps = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
it("AppList snapshot test", () => {
|
describe("appList.tsx", () => {
|
||||||
|
it("Tests AppList rendering with categories and apps", () => {
|
||||||
const { asFragment } = render(
|
const { asFragment } = render(
|
||||||
<AppList categories={props.categories} apps={props.apps} />,
|
<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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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", () => {
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue