diff --git a/src/components/greeter.tsx b/src/components/greeter.tsx index f27ffd0..25170d8 100644 --- a/src/components/greeter.tsx +++ b/src/components/greeter.tsx @@ -20,6 +20,10 @@ const DateText = styled.h3` color: ${selectedTheme.accentColor}; `; +export interface IGreeterComponentProps { + data: IGreeterProps; +} + export interface IGreeterProps { months: Array; days: Array; @@ -33,17 +37,13 @@ interface IGreetingProps { end: number; } -interface IGreeterComponentProps { - data: IGreeterProps; -} - /** * Checks if a number is between two numbers * @param {number} a number that's supposed to be checked * @param {number} b minimum * @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; /** @@ -51,7 +51,7 @@ const isBetween = (a: number, b: number, c: number): boolean => * @param {Array} greetings a list of greetings with start and end date * @returns {string} a greeting */ -const getGreeting = (greetings: Array): string => { +export const getGreeting = (greetings: Array): string => { let hours = Math.floor(new Date().getHours()); let result = ""; @@ -68,17 +68,17 @@ const getGreeting = (greetings: Array): string => { * @param {number} day number of a day within a month * @returns {string} extension for that number */ -const getExtension = (day: number) => { +export const getExtension = (day: number) => { let extension = ""; - if ((day > 4 && day <= 20) || (day > 20 && day % 10 >= 4)) { - extension = "th"; - } else if (day % 10 === 1) { + if (day % 10 === 1) { extension = "st"; } else if (day % 10 === 2) { extension = "nd"; } else if (day % 10 === 3) { extension = "rd"; + } else if (isBetween(day, 4, 20) || (day > 20 && day % 10 >= 4)) { + extension = "th"; } return extension; @@ -89,7 +89,7 @@ const getExtension = (day: number) => { * @param {string} format format of the date string * @returns {string} current date as a string */ -const getDateString = ( +export const getDateString = ( weekdays: Array, months: Array, format: string, diff --git a/src/test/components/__snapshots__/app.spec.tsx.snap b/src/test/components/__snapshots__/app.spec.tsx.snap index b7c9a35..8935f25 100644 --- a/src/test/components/__snapshots__/app.spec.tsx.snap +++ b/src/test/components/__snapshots__/app.spec.tsx.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`should take a snapshot 1`] = `[Function]`; +exports[`App snapshot test 1`] = `[Function]`; diff --git a/src/test/components/__snapshots__/appCategory.spec.tsx.snap b/src/test/components/__snapshots__/appCategory.spec.tsx.snap index b7c9a35..0b26ca0 100644 --- a/src/test/components/__snapshots__/appCategory.spec.tsx.snap +++ b/src/test/components/__snapshots__/appCategory.spec.tsx.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`should take a snapshot 1`] = `[Function]`; +exports[`AppCategory snapshot test 1`] = `[Function]`; diff --git a/src/test/components/__snapshots__/appList.spec.tsx.snap b/src/test/components/__snapshots__/appList.spec.tsx.snap index b7c9a35..6cdc7df 100644 --- a/src/test/components/__snapshots__/appList.spec.tsx.snap +++ b/src/test/components/__snapshots__/appList.spec.tsx.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`should take a snapshot 1`] = `[Function]`; +exports[`AppList snapshot test 1`] = `[Function]`; diff --git a/src/test/components/__snapshots__/greeter.spec.tsx.snap b/src/test/components/__snapshots__/greeter.spec.tsx.snap new file mode 100644 index 0000000..7e0c23b --- /dev/null +++ b/src/test/components/__snapshots__/greeter.spec.tsx.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Greeter snapshot test 1`] = `[Function]`; diff --git a/src/test/components/__snapshots__/icon.spec.tsx.snap b/src/test/components/__snapshots__/icon.spec.tsx.snap new file mode 100644 index 0000000..076de6c --- /dev/null +++ b/src/test/components/__snapshots__/icon.spec.tsx.snap @@ -0,0 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Icon test 1`] = `[Function]`; + +exports[`IconButton test 1`] = `[Function]`; diff --git a/src/test/components/app.spec.tsx b/src/test/components/app.spec.tsx index e732c04..b275382 100644 --- a/src/test/components/app.spec.tsx +++ b/src/test/components/app.spec.tsx @@ -9,7 +9,7 @@ const props: IAppProps = { newTab: false, }; -it("should take a snapshot", () => { +it("App snapshot test", () => { const { asFragment } = render( { +it("AppCategory snapshot test", () => { const { asFragment } = render( , ); diff --git a/src/test/components/appList.spec.tsx b/src/test/components/appList.spec.tsx index d85147d..32916b4 100644 --- a/src/test/components/appList.spec.tsx +++ b/src/test/components/appList.spec.tsx @@ -34,7 +34,7 @@ const props: IAppListProps = { ], }; -it("should take a snapshot", () => { +it("AppList snapshot test", () => { const { asFragment } = render( , ); diff --git a/src/test/components/greeter.spec.tsx b/src/test/components/greeter.spec.tsx new file mode 100644 index 0000000..45791e9 --- /dev/null +++ b/src/test/components/greeter.spec.tsx @@ -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(); + expect(asFragment).toMatchSnapshot(); +}); diff --git a/src/test/components/icon.spec.tsx b/src/test/components/icon.spec.tsx new file mode 100644 index 0000000..da75ac2 --- /dev/null +++ b/src/test/components/icon.spec.tsx @@ -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(); + expect(asFragment).toMatchSnapshot(); +}) + +it('IconButton test', () => { + const { asFragment } = render(); + expect(asFragment).toMatchSnapshot(); + + const handleClick = jest.fn() + render(); + fireEvent.click(screen.getByText(/question_answer/i)) + expect(handleClick).toHaveBeenCalledTimes(1) +}) \ No newline at end of file