added greeter and icon tests
This commit is contained in:
parent
befbd2e67f
commit
e768a00dce
11 changed files with 121 additions and 17 deletions
|
@ -20,6 +20,10 @@ const DateText = styled.h3`
|
||||||
color: ${selectedTheme.accentColor};
|
color: ${selectedTheme.accentColor};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export interface IGreeterComponentProps {
|
||||||
|
data: IGreeterProps;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IGreeterProps {
|
export interface IGreeterProps {
|
||||||
months: Array<string>;
|
months: Array<string>;
|
||||||
days: Array<string>;
|
days: Array<string>;
|
||||||
|
@ -33,17 +37,13 @@ interface IGreetingProps {
|
||||||
end: number;
|
end: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IGreeterComponentProps {
|
|
||||||
data: IGreeterProps;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a number is between two numbers
|
* Checks if a number is between two numbers
|
||||||
* @param {number} a number that's supposed to be checked
|
* @param {number} a number that's supposed to be checked
|
||||||
* @param {number} b minimum
|
* @param {number} b minimum
|
||||||
* @param {number} c maximum
|
* @param {number} c maximum
|
||||||
*/
|
*/
|
||||||
const isBetween = (a: number, b: number, c: number): boolean =>
|
export const isBetween = (a: number, b: number, c: number): boolean =>
|
||||||
a >= b && a <= c;
|
a >= b && a <= c;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +51,7 @@ const isBetween = (a: number, b: number, c: number): boolean =>
|
||||||
* @param {Array<IGreetingProps>} greetings a list of greetings with start and end date
|
* @param {Array<IGreetingProps>} greetings a list of greetings with start and end date
|
||||||
* @returns {string} a greeting
|
* @returns {string} a greeting
|
||||||
*/
|
*/
|
||||||
const getGreeting = (greetings: Array<IGreetingProps>): string => {
|
export const getGreeting = (greetings: Array<IGreetingProps>): string => {
|
||||||
let hours = Math.floor(new Date().getHours());
|
let hours = Math.floor(new Date().getHours());
|
||||||
let result = "";
|
let result = "";
|
||||||
|
|
||||||
|
@ -68,17 +68,17 @@ const getGreeting = (greetings: Array<IGreetingProps>): string => {
|
||||||
* @param {number} day number of a day within a month
|
* @param {number} day number of a day within a month
|
||||||
* @returns {string} extension for that number
|
* @returns {string} extension for that number
|
||||||
*/
|
*/
|
||||||
const getExtension = (day: number) => {
|
export const getExtension = (day: number) => {
|
||||||
let extension = "";
|
let extension = "";
|
||||||
|
|
||||||
if ((day > 4 && day <= 20) || (day > 20 && day % 10 >= 4)) {
|
if (day % 10 === 1) {
|
||||||
extension = "th";
|
|
||||||
} else if (day % 10 === 1) {
|
|
||||||
extension = "st";
|
extension = "st";
|
||||||
} else if (day % 10 === 2) {
|
} else if (day % 10 === 2) {
|
||||||
extension = "nd";
|
extension = "nd";
|
||||||
} else if (day % 10 === 3) {
|
} else if (day % 10 === 3) {
|
||||||
extension = "rd";
|
extension = "rd";
|
||||||
|
} else if (isBetween(day, 4, 20) || (day > 20 && day % 10 >= 4)) {
|
||||||
|
extension = "th";
|
||||||
}
|
}
|
||||||
|
|
||||||
return extension;
|
return extension;
|
||||||
|
@ -89,7 +89,7 @@ const getExtension = (day: number) => {
|
||||||
* @param {string} format format of the date string
|
* @param {string} format format of the date string
|
||||||
* @returns {string} current date as a string
|
* @returns {string} current date as a string
|
||||||
*/
|
*/
|
||||||
const getDateString = (
|
export const getDateString = (
|
||||||
weekdays: Array<string>,
|
weekdays: Array<string>,
|
||||||
months: Array<string>,
|
months: Array<string>,
|
||||||
format: string,
|
format: string,
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`should take a snapshot 1`] = `[Function]`;
|
exports[`App snapshot test 1`] = `[Function]`;
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`should take a snapshot 1`] = `[Function]`;
|
exports[`AppCategory snapshot test 1`] = `[Function]`;
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`should take a snapshot 1`] = `[Function]`;
|
exports[`AppList snapshot test 1`] = `[Function]`;
|
||||||
|
|
3
src/test/components/__snapshots__/greeter.spec.tsx.snap
Normal file
3
src/test/components/__snapshots__/greeter.spec.tsx.snap
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Greeter snapshot test 1`] = `[Function]`;
|
5
src/test/components/__snapshots__/icon.spec.tsx.snap
Normal file
5
src/test/components/__snapshots__/icon.spec.tsx.snap
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Icon test 1`] = `[Function]`;
|
||||||
|
|
||||||
|
exports[`IconButton test 1`] = `[Function]`;
|
|
@ -9,7 +9,7 @@ const props: IAppProps = {
|
||||||
newTab: false,
|
newTab: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
it("should take a snapshot", () => {
|
it("App snapshot test", () => {
|
||||||
const { asFragment } = render(
|
const { asFragment } = render(
|
||||||
<App
|
<App
|
||||||
name={props.name}
|
name={props.name}
|
||||||
|
|
|
@ -21,7 +21,7 @@ const props: IAppCategoryProps = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
it("should take a snapshot", () => {
|
it("AppCategory snapshot test", () => {
|
||||||
const { asFragment } = render(
|
const { asFragment } = render(
|
||||||
<AppCategory name={props.name} items={props.items} />,
|
<AppCategory name={props.name} items={props.items} />,
|
||||||
);
|
);
|
||||||
|
|
|
@ -34,7 +34,7 @@ const props: IAppListProps = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
it("should take a snapshot", () => {
|
it("AppList snapshot test", () => {
|
||||||
const { asFragment } = render(
|
const { asFragment } = render(
|
||||||
<AppList categories={props.categories} apps={props.apps} />,
|
<AppList categories={props.categories} apps={props.apps} />,
|
||||||
);
|
);
|
||||||
|
|
73
src/test/components/greeter.spec.tsx
Normal file
73
src/test/components/greeter.spec.tsx
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
import { render } from "@testing-library/react";
|
||||||
|
import Greeter, { IGreeterProps, isBetween, getExtension } from "../../components/greeter";
|
||||||
|
|
||||||
|
const props: IGreeterProps = {
|
||||||
|
months: [
|
||||||
|
"January",
|
||||||
|
"February",
|
||||||
|
"March",
|
||||||
|
"April",
|
||||||
|
"May",
|
||||||
|
"June",
|
||||||
|
"July",
|
||||||
|
"August",
|
||||||
|
"September",
|
||||||
|
"October",
|
||||||
|
"November",
|
||||||
|
"December"
|
||||||
|
],
|
||||||
|
days: [
|
||||||
|
"Sunday",
|
||||||
|
"Monday",
|
||||||
|
"Tuesday",
|
||||||
|
"Wednesday",
|
||||||
|
"Thursday",
|
||||||
|
"Friday",
|
||||||
|
"Saturday"
|
||||||
|
],
|
||||||
|
greetings: [
|
||||||
|
{
|
||||||
|
greeting: "Good night!",
|
||||||
|
start: 0,
|
||||||
|
end: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
greeting: "Good morning!",
|
||||||
|
start: 6,
|
||||||
|
end: 12,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
greeting: "Good afternoon!",
|
||||||
|
start: 12,
|
||||||
|
end: 18
|
||||||
|
},
|
||||||
|
{
|
||||||
|
greeting: "Good evening!",
|
||||||
|
start: 18,
|
||||||
|
end: 24
|
||||||
|
}
|
||||||
|
],
|
||||||
|
dateformat: "%wd, %m %d%e %y"
|
||||||
|
}
|
||||||
|
|
||||||
|
it('isBetween test', () => {
|
||||||
|
expect(isBetween(5,1,3)).toBeFalsy
|
||||||
|
expect(isBetween(64,1,8)).toBeFalsy
|
||||||
|
expect(isBetween(-1,-5,-3)).toBeFalsy
|
||||||
|
expect(isBetween(4,4,4)).toBeTruthy
|
||||||
|
expect(isBetween(3,1,8)).toBeTruthy
|
||||||
|
expect(isBetween(-3,-5,-1)).toBeTruthy
|
||||||
|
})
|
||||||
|
|
||||||
|
it('getExtension test', () => {
|
||||||
|
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")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Greeter snapshot test", () => {
|
||||||
|
const { asFragment } = render(<Greeter data={props} />);
|
||||||
|
expect(asFragment).toMatchSnapshot();
|
||||||
|
});
|
23
src/test/components/icon.spec.tsx
Normal file
23
src/test/components/icon.spec.tsx
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import { fireEvent, render, screen } from "@testing-library/react";
|
||||||
|
import Icon, { IconButton } from "../../components/icon"
|
||||||
|
|
||||||
|
const props = {
|
||||||
|
name: "bug_report",
|
||||||
|
size: "20px",
|
||||||
|
onClick: () => console.log("test")
|
||||||
|
}
|
||||||
|
|
||||||
|
it('Icon test', () => {
|
||||||
|
const { asFragment } = render(<Icon name={props.name} size={props.size}/>);
|
||||||
|
expect(asFragment).toMatchSnapshot();
|
||||||
|
})
|
||||||
|
|
||||||
|
it('IconButton test', () => {
|
||||||
|
const { asFragment } = render(<IconButton icon={props.name} onClick={props.onClick} />);
|
||||||
|
expect(asFragment).toMatchSnapshot();
|
||||||
|
|
||||||
|
const handleClick = jest.fn()
|
||||||
|
render(<IconButton icon="question_answer" onClick={handleClick} />);
|
||||||
|
fireEvent.click(screen.getByText(/question_answer/i))
|
||||||
|
expect(handleClick).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
Loading…
Add table
Reference in a new issue