Update tests, apply formatting
This commit is contained in:
parent
f469c1de67
commit
786aca82f1
12 changed files with 70 additions and 24 deletions
|
@ -68,7 +68,7 @@ export const getGreeting = (greetings: Array<IGreetingProps>): string => {
|
||||||
* @returns {string} extension for that number
|
* @returns {string} extension for that number
|
||||||
*/
|
*/
|
||||||
export const getExtension = (day: number) => {
|
export const getExtension = (day: number) => {
|
||||||
let extension = "";
|
let extension = "th";
|
||||||
|
|
||||||
if (day % 10 === 1) {
|
if (day % 10 === 1) {
|
||||||
extension = "st";
|
extension = "st";
|
||||||
|
@ -76,8 +76,6 @@ export const getExtension = (day: number) => {
|
||||||
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;
|
||||||
|
|
|
@ -48,9 +48,7 @@ const IconContainer = styled.i`
|
||||||
* @returns {React.ReactNode} the icon node
|
* @returns {React.ReactNode} the icon node
|
||||||
*/
|
*/
|
||||||
export const Icon = ({ name, size }: IIconProps) => (
|
export const Icon = ({ name, size }: IIconProps) => (
|
||||||
<IconContainer about={size}>
|
<IconContainer about={size}>{name}</IconContainer>
|
||||||
{name}
|
|
||||||
</IconContainer>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,8 +8,9 @@ export interface IItemProps {
|
||||||
export interface ISelectProps {
|
export interface ISelectProps {
|
||||||
items: Array<IItemProps>;
|
items: Array<IItemProps>;
|
||||||
onChange: (item: any) => void;
|
onChange: (item: any) => void;
|
||||||
current: string;
|
current?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
testId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const update = (
|
const update = (
|
||||||
|
@ -20,18 +21,24 @@ const update = (
|
||||||
onChange(items.find((item) => item.value.toString() === e.target.value));
|
onChange(items.find((item) => item.value.toString() === e.target.value));
|
||||||
};
|
};
|
||||||
|
|
||||||
const Select = ({ items, onChange, current, className }: ISelectProps) => (
|
const Select = ({
|
||||||
|
items,
|
||||||
|
onChange,
|
||||||
|
current,
|
||||||
|
className,
|
||||||
|
testId,
|
||||||
|
}: ISelectProps) => (
|
||||||
<select
|
<select
|
||||||
data-testid="select"
|
data-testid={"select" + (testId ? "-" + testId : "")}
|
||||||
onChange={(e) => update(items, onChange, e)}
|
onChange={(e) => update(items, onChange, e)}
|
||||||
className={className}
|
className={className}
|
||||||
|
defaultValue={current}
|
||||||
>
|
>
|
||||||
{items.map(({ label, value }, index) => (
|
{items.map(({ label, value }, index) => (
|
||||||
<option
|
<option
|
||||||
data-testid={"option-" + index}
|
data-testid={"option-" + (testId ? testId + "-" : "") + index}
|
||||||
key={[label, index].join("")}
|
key={[label, index].join("")}
|
||||||
value={value.toString()}
|
value={value.toString()}
|
||||||
selected={current === label}
|
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
</option>
|
</option>
|
||||||
|
|
|
@ -91,7 +91,6 @@ const Settings = ({ themes, search }: ISettingsProps) => {
|
||||||
|
|
||||||
const currentLightTheme = getTheme("light").label;
|
const currentLightTheme = getTheme("light").label;
|
||||||
const currentDarkTheme = getTheme("dark").label;
|
const currentDarkTheme = getTheme("dark").label;
|
||||||
console.log(currentLightTheme, currentDarkTheme);
|
|
||||||
|
|
||||||
if (themes || search) {
|
if (themes || search) {
|
||||||
return (
|
return (
|
||||||
|
@ -105,12 +104,14 @@ const Settings = ({ themes, search }: ISettingsProps) => {
|
||||||
items={themes}
|
items={themes}
|
||||||
onChange={(theme: IThemeProps) => setNewLightTheme(theme)}
|
onChange={(theme: IThemeProps) => setNewLightTheme(theme)}
|
||||||
current={currentLightTheme}
|
current={currentLightTheme}
|
||||||
|
testId="light"
|
||||||
></ThemeSelect>
|
></ThemeSelect>
|
||||||
<ThemeHeader>Dark</ThemeHeader>
|
<ThemeHeader>Dark</ThemeHeader>
|
||||||
<ThemeSelect
|
<ThemeSelect
|
||||||
items={themes}
|
items={themes}
|
||||||
onChange={(theme: IThemeProps) => setNewDarkTheme(theme)}
|
onChange={(theme: IThemeProps) => setNewDarkTheme(theme)}
|
||||||
current={currentDarkTheme}
|
current={currentDarkTheme}
|
||||||
|
testId="dark"
|
||||||
></ThemeSelect>
|
></ThemeSelect>
|
||||||
</FormContainer>
|
</FormContainer>
|
||||||
<Button
|
<Button
|
||||||
|
|
|
@ -68,7 +68,7 @@ export const defaults = {
|
||||||
},
|
},
|
||||||
search: {
|
search: {
|
||||||
search: {
|
search: {
|
||||||
placeholder: '',
|
placeholder: "",
|
||||||
defaultProvider: "https://google.com/search?q=",
|
defaultProvider: "https://google.com/search?q=",
|
||||||
providers: [],
|
providers: [],
|
||||||
},
|
},
|
||||||
|
|
|
@ -54,7 +54,10 @@ export const getTheme = (scheme?: string): IThemeProps => {
|
||||||
currentScheme = "dark-theme";
|
currentScheme = "dark-theme";
|
||||||
}
|
}
|
||||||
|
|
||||||
let theme = currentScheme === "dark-theme" ? localStorage.getItem("dark-theme") : localStorage.getItem("light-theme");
|
let theme =
|
||||||
|
currentScheme === "dark-theme"
|
||||||
|
? localStorage.getItem("dark-theme")
|
||||||
|
: localStorage.getItem("light-theme");
|
||||||
if (theme !== null) selectedTheme = JSON.parse(theme || "{}");
|
if (theme !== null) selectedTheme = JSON.parse(theme || "{}");
|
||||||
|
|
||||||
return selectedTheme;
|
return selectedTheme;
|
||||||
|
|
|
@ -17,7 +17,7 @@ const useMediaQuery = (query: string) => {
|
||||||
}, [matches, query]);
|
}, [matches, query]);
|
||||||
|
|
||||||
return matches;
|
return matches;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const IsDark = () => useMediaQuery("(prefers-color-scheme: dark");
|
export const IsDark = () => useMediaQuery("(prefers-color-scheme: dark");
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,18 @@
|
||||||
import { render } from "@testing-library/react";
|
import { render } from "@testing-library/react";
|
||||||
import App, { GlobalStyle } from "../app";
|
import App, { GlobalStyle } from "../app";
|
||||||
|
import { IThemeProps } from "../lib/theme";
|
||||||
|
|
||||||
|
const props: IThemeProps = {
|
||||||
|
label: "Classic",
|
||||||
|
value: 0,
|
||||||
|
mainColor: "#000000",
|
||||||
|
accentColor: "#1e272e",
|
||||||
|
backgroundColor: "#ffffff",
|
||||||
|
};
|
||||||
|
|
||||||
describe("app.tsx", () => {
|
describe("app.tsx", () => {
|
||||||
it("Tests GlobalStyle", () => {
|
it("Tests GlobalStyle", () => {
|
||||||
const { asFragment } = render(<GlobalStyle />);
|
const { asFragment } = render(<GlobalStyle theme={props} />);
|
||||||
expect(asFragment).toMatchSnapshot();
|
expect(asFragment).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -64,7 +64,7 @@ it("isBetween test", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("getExtension test", () => {
|
it("getExtension test", () => {
|
||||||
expect(getExtension(0)).toEqual("");
|
expect(getExtension(0)).toEqual("th");
|
||||||
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");
|
||||||
|
|
|
@ -7,6 +7,7 @@ import SearchBar, {
|
||||||
|
|
||||||
const props: ISearchProps = {
|
const props: ISearchProps = {
|
||||||
defaultProvider: "https://test.com?q=",
|
defaultProvider: "https://test.com?q=",
|
||||||
|
placeholder: "",
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
name: "Allmusic",
|
name: "Allmusic",
|
||||||
|
@ -73,6 +74,7 @@ describe("searchBar.tsx", () => {
|
||||||
it("Tests handleQueryWithProvider without providers", () => {
|
it("Tests handleQueryWithProvider without providers", () => {
|
||||||
const test: ISearchProps = {
|
const test: ISearchProps = {
|
||||||
defaultProvider: "https://test.com?q=",
|
defaultProvider: "https://test.com?q=",
|
||||||
|
placeholder: "",
|
||||||
providers: undefined,
|
providers: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ const themes: Array<IThemeProps> = [
|
||||||
|
|
||||||
const search: ISearchProps = {
|
const search: ISearchProps = {
|
||||||
defaultProvider: "https://test.com?q=",
|
defaultProvider: "https://test.com?q=",
|
||||||
|
placeholder: "",
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
name: "Allmusic",
|
name: "Allmusic",
|
||||||
|
@ -130,10 +131,23 @@ describe("settings.tsx", () => {
|
||||||
expect(window.location.reload).toHaveBeenCalledTimes(1);
|
expect(window.location.reload).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Tests theme selection", () => {
|
it("Tests light theme selection", () => {
|
||||||
const settings = render(<Settings themes={themes} search={search} />);
|
const settings = render(<Settings themes={themes} search={search} />);
|
||||||
|
|
||||||
fireEvent.change(settings.getByTestId("select"), { target: { value: 0 } });
|
fireEvent.change(settings.getByTestId("select-light"), {
|
||||||
|
target: { value: 0 },
|
||||||
|
});
|
||||||
|
|
||||||
|
fireEvent.click(settings.getByTestId("button-submit"));
|
||||||
|
expect(window.location.reload).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Tests dark theme selection", () => {
|
||||||
|
const settings = render(<Settings themes={themes} search={search} />);
|
||||||
|
|
||||||
|
fireEvent.change(settings.getByTestId("select-dark"), {
|
||||||
|
target: { value: 0 },
|
||||||
|
});
|
||||||
|
|
||||||
fireEvent.click(settings.getByTestId("button-submit"));
|
fireEvent.click(settings.getByTestId("button-submit"));
|
||||||
expect(window.location.reload).toHaveBeenCalledTimes(1);
|
expect(window.location.reload).toHaveBeenCalledTimes(1);
|
||||||
|
@ -142,7 +156,9 @@ describe("settings.tsx", () => {
|
||||||
it("Tests theme selection", () => {
|
it("Tests theme selection", () => {
|
||||||
const settings = render(<Settings themes={themes} search={search} />);
|
const settings = render(<Settings themes={themes} search={search} />);
|
||||||
|
|
||||||
fireEvent.change(settings.getByTestId("select"), { target: { value: 5 } });
|
fireEvent.change(settings.getByTestId("select-light"), {
|
||||||
|
target: { value: 5 },
|
||||||
|
});
|
||||||
|
|
||||||
fireEvent.click(settings.getByTestId("button-submit"));
|
fireEvent.click(settings.getByTestId("button-submit"));
|
||||||
expect(window.location.reload).toHaveBeenCalledTimes(0);
|
expect(window.location.reload).toHaveBeenCalledTimes(0);
|
||||||
|
|
|
@ -28,13 +28,25 @@ const setup = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("theme.tsx", () => {
|
describe("theme.tsx", () => {
|
||||||
it("setTheme test", () => {
|
it("setTheme light test", () => {
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
setTheme(props);
|
setTheme("light", props);
|
||||||
expect(window.localStorage.setItem).toHaveBeenCalledTimes(1);
|
expect(window.localStorage.setItem).toHaveBeenCalledTimes(2);
|
||||||
expect(window.localStorage.setItem).toHaveBeenCalledWith(
|
expect(window.localStorage.setItem).toHaveBeenCalledWith(
|
||||||
"theme",
|
"light-theme",
|
||||||
|
JSON.stringify(props),
|
||||||
|
);
|
||||||
|
expect(window.location.reload).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("setTheme dark test", () => {
|
||||||
|
setup();
|
||||||
|
|
||||||
|
setTheme("dark", props);
|
||||||
|
expect(window.localStorage.setItem).toHaveBeenCalledTimes(2);
|
||||||
|
expect(window.localStorage.setItem).toHaveBeenCalledWith(
|
||||||
|
"dark-theme",
|
||||||
JSON.stringify(props),
|
JSON.stringify(props),
|
||||||
);
|
);
|
||||||
expect(window.location.reload).toHaveBeenCalledTimes(1);
|
expect(window.location.reload).toHaveBeenCalledTimes(1);
|
||||||
|
|
Loading…
Reference in a new issue