Update tests
This commit is contained in:
parent
942cba97da
commit
6d059ce3b8
6 changed files with 114 additions and 22 deletions
|
@ -1,3 +1,5 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`Greeter snapshot test 1`] = `[Function]`;
|
exports[`Greeter snapshot test with properties 1`] = `[Function]`;
|
||||||
|
|
||||||
|
exports[`Greeter snapshot test without properties 1`] = `[Function]`;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`searchBar.tsx Tests SearchBar rendering 1`] = `[Function]`;
|
exports[`searchBar.tsx Tests SearchBar rendering with properties 1`] = `[Function]`;
|
||||||
|
|
||||||
|
exports[`searchBar.tsx Tests searchBar rendering without properties 1`] = `[Function]`;
|
||||||
|
|
|
@ -98,7 +98,12 @@ it("getExtension test", () => {
|
||||||
expect(getExtension(31)).toEqual("st");
|
expect(getExtension(31)).toEqual("st");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Greeter snapshot test", () => {
|
it("Greeter snapshot test with properties", () => {
|
||||||
const { asFragment } = render(<Greeter data={props} />);
|
const { asFragment } = render(<Greeter greeter={{ greeter: props }} />);
|
||||||
|
expect(asFragment).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Greeter snapshot test without properties", () => {
|
||||||
|
const { asFragment } = render(<Greeter />);
|
||||||
expect(asFragment).toMatchSnapshot();
|
expect(asFragment).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
|
@ -54,11 +54,16 @@ describe("searchBar.tsx", () => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Tests SearchBar rendering", () => {
|
it("Tests SearchBar rendering with properties", () => {
|
||||||
const { asFragment } = render(<SearchBar search={props} />);
|
const { asFragment } = render(<SearchBar search={props} />);
|
||||||
expect(asFragment).toMatchSnapshot();
|
expect(asFragment).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Tests searchBar rendering without properties", () => {
|
||||||
|
const { asFragment } = render(<SearchBar />);
|
||||||
|
expect(asFragment).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
it("Tests handleQueryWithProvider", () => {
|
it("Tests handleQueryWithProvider", () => {
|
||||||
props.providers?.forEach((provider: ISearchProviderProps) => {
|
props.providers?.forEach((provider: ISearchProviderProps) => {
|
||||||
handleQueryWithProvider(props, provider.prefix + " test");
|
handleQueryWithProvider(props, provider.prefix + " test");
|
||||||
|
|
|
@ -9,9 +9,10 @@ import Settings, {
|
||||||
SectionHeadline,
|
SectionHeadline,
|
||||||
} from "../../components/settings";
|
} from "../../components/settings";
|
||||||
import { ISearchProps } from "../../components/searchBar";
|
import { ISearchProps } from "../../components/searchBar";
|
||||||
import { IThemeProps } from "../../lib/useTheme";
|
import { IThemeDataProps } from "../../lib/useTheme";
|
||||||
|
|
||||||
const themes: Array<IThemeProps> = [
|
const themes: IThemeDataProps = {
|
||||||
|
themes: [
|
||||||
{
|
{
|
||||||
label: "Classic",
|
label: "Classic",
|
||||||
value: 0,
|
value: 0,
|
||||||
|
@ -26,7 +27,8 @@ const themes: Array<IThemeProps> = [
|
||||||
accentColor: "#1e272e",
|
accentColor: "#1e272e",
|
||||||
backgroundColor: "#ffffff",
|
backgroundColor: "#ffffff",
|
||||||
},
|
},
|
||||||
];
|
],
|
||||||
|
};
|
||||||
|
|
||||||
const search: ISearchProps = {
|
const search: ISearchProps = {
|
||||||
defaultProvider: "https://test.com?q=",
|
defaultProvider: "https://test.com?q=",
|
||||||
|
|
76
src/test/lib/useTheme.spec.tsx
Normal file
76
src/test/lib/useTheme.spec.tsx
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
import { getTheme, IThemeProps, setScheme, setTheme } from "../../lib/useTheme";
|
||||||
|
|
||||||
|
const props: IThemeProps = {
|
||||||
|
label: "Classic",
|
||||||
|
value: 0,
|
||||||
|
mainColor: "#000000",
|
||||||
|
accentColor: "#1e272e",
|
||||||
|
backgroundColor: "#ffffff",
|
||||||
|
};
|
||||||
|
|
||||||
|
const location: Location = window.location;
|
||||||
|
const setup = () => {
|
||||||
|
Object.defineProperty(window, "localStorage", {
|
||||||
|
value: {
|
||||||
|
getItem: jest.fn(() => JSON.stringify(props)),
|
||||||
|
setItem: jest.fn(() => null),
|
||||||
|
},
|
||||||
|
writable: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
delete window.location;
|
||||||
|
|
||||||
|
window.location = {
|
||||||
|
...location,
|
||||||
|
reload: jest.fn(),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("theme.tsx", () => {
|
||||||
|
it("Tests setScheme", () => {
|
||||||
|
setup();
|
||||||
|
|
||||||
|
let value = "dark";
|
||||||
|
|
||||||
|
setScheme(value);
|
||||||
|
expect(window.localStorage.setItem).toHaveBeenCalledTimes(1);
|
||||||
|
expect(window.localStorage.setItem).toHaveBeenCalledWith("theme", value);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("setTheme light test", () => {
|
||||||
|
setup();
|
||||||
|
|
||||||
|
setTheme("light", props);
|
||||||
|
expect(window.localStorage.setItem).toHaveBeenCalledTimes(2);
|
||||||
|
expect(window.localStorage.setItem).toHaveBeenCalledWith(
|
||||||
|
"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),
|
||||||
|
);
|
||||||
|
expect(window.location.reload).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Tests getTheme", () => {
|
||||||
|
setup();
|
||||||
|
|
||||||
|
let themeTest = getTheme();
|
||||||
|
expect(themeTest).toEqual(props);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Tests getTheme with empty parameters", () => {
|
||||||
|
localStorage.setItem("theme", "");
|
||||||
|
expect(getTheme()).toEqual({});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue