Replace useFetcher with useFetch.
This commit is contained in:
parent
d4f593c4ce
commit
942cba97da
15 changed files with 292 additions and 740 deletions
|
@ -1,46 +0,0 @@
|
|||
import { ok } from "assert";
|
||||
import useFetcher, {
|
||||
defaults,
|
||||
handleResponse,
|
||||
handleError,
|
||||
fetchProduction,
|
||||
fetchDevelopment,
|
||||
} from "../../lib/fetcher";
|
||||
|
||||
describe("fetcher.tsx", () => {
|
||||
it("Tests handleResponse", () => {});
|
||||
|
||||
it("Tests handleError", () => {
|
||||
expect(handleError("apps", Error("Test!"))).toEqual({
|
||||
...defaults.app,
|
||||
error: "Test!",
|
||||
});
|
||||
|
||||
expect(handleError("bookmark", Error("Test!"))).toEqual({
|
||||
...defaults.bookmark,
|
||||
error: "Test!",
|
||||
});
|
||||
|
||||
expect(handleError("searchProvider", Error("Test!"))).toEqual({
|
||||
...defaults.search,
|
||||
error: "Test!",
|
||||
});
|
||||
|
||||
expect(handleError("theme", Error("Test!"))).toEqual({
|
||||
...defaults.theme,
|
||||
error: "Test!",
|
||||
});
|
||||
|
||||
expect(handleError("imprint", Error("Test!"))).toEqual({
|
||||
...defaults.imprint,
|
||||
error: "Test!",
|
||||
});
|
||||
|
||||
expect(handleError("greeter", Error("Test!"))).toEqual({
|
||||
...defaults.greeter,
|
||||
error: "Test!",
|
||||
});
|
||||
|
||||
expect(handleError("", Error("Test!"))).toEqual(undefined);
|
||||
});
|
||||
});
|
|
@ -1,76 +0,0 @@
|
|||
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…
Add table
Add a link
Reference in a new issue