Update tests
This commit is contained in:
parent
0ce5d3aea6
commit
1385bf7dcc
3 changed files with 77 additions and 68 deletions
|
@ -27,13 +27,12 @@ const props: IImprintProps = {
|
||||||
|
|
||||||
describe("imprint.tsx", () => {
|
describe("imprint.tsx", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
delete global.window.location;
|
// @ts-ignore
|
||||||
global.window = Object.create(window);
|
delete window.location;
|
||||||
global.window.location = {
|
|
||||||
port: "123",
|
window.location = {
|
||||||
protocol: "http:",
|
...location,
|
||||||
hostname: "localhost",
|
reload: jest.fn(),
|
||||||
href: "test",
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,29 +2,32 @@ import { fireEvent, render } from "@testing-library/react";
|
||||||
import SearchBar, {
|
import SearchBar, {
|
||||||
handleQueryWithProvider,
|
handleQueryWithProvider,
|
||||||
ISearchProviderProps,
|
ISearchProviderProps,
|
||||||
ISearchBarProps,
|
ISearchProps,
|
||||||
} from "../../components/searchBar";
|
} from "../../components/searchBar";
|
||||||
|
|
||||||
const providers: Array<ISearchProviderProps> = [
|
const props: ISearchProps = {
|
||||||
{
|
defaultProvider: "https://test.com?q=",
|
||||||
name: "Allmusic",
|
providers: [
|
||||||
url: "https://www.allmusic.com/search/all/",
|
{
|
||||||
prefix: "/a",
|
name: "Allmusic",
|
||||||
},
|
url: "https://www.allmusic.com/search/all/",
|
||||||
{
|
prefix: "/a",
|
||||||
name: "Discogs",
|
},
|
||||||
url: "https://www.discogs.com/search/?q=",
|
{
|
||||||
prefix: "/di",
|
name: "Discogs",
|
||||||
},
|
url: "https://www.discogs.com/search/?q=",
|
||||||
{
|
prefix: "/di",
|
||||||
name: "Duck Duck Go",
|
},
|
||||||
url: "https://duckduckgo.com/?q=",
|
{
|
||||||
prefix: "/d",
|
name: "Duck Duck Go",
|
||||||
},
|
url: "https://duckduckgo.com/?q=",
|
||||||
];
|
prefix: "/d",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
const setup = () => {
|
const setup = () => {
|
||||||
const searchBar = render(<SearchBar providers={providers} />);
|
const searchBar = render(<SearchBar search={props} />);
|
||||||
const input = searchBar.getByTestId("search-input");
|
const input = searchBar.getByTestId("search-input");
|
||||||
const clearButton = searchBar.getByTestId("search-clear");
|
const clearButton = searchBar.getByTestId("search-clear");
|
||||||
const submitButton = searchBar.getByTestId("search-submit");
|
const submitButton = searchBar.getByTestId("search-submit");
|
||||||
|
@ -37,37 +40,44 @@ const setup = () => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const location: Location = window.location;
|
||||||
|
|
||||||
describe("searchBar.tsx", () => {
|
describe("searchBar.tsx", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
delete global.window.location;
|
// @ts-ignore
|
||||||
global.window = Object.create(window);
|
delete window.location;
|
||||||
global.window.location = {
|
|
||||||
port: "123",
|
window.location = {
|
||||||
protocol: "http:",
|
...location,
|
||||||
hostname: "localhost",
|
reload: jest.fn(),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Tests SearchBar rendering", () => {
|
it("Tests SearchBar rendering", () => {
|
||||||
const { asFragment } = render(<SearchBar providers={providers} />);
|
const { asFragment } = render(<SearchBar search={props} />);
|
||||||
expect(asFragment).toMatchSnapshot();
|
expect(asFragment).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Tests handleQueryWithProvider", () => {
|
it("Tests handleQueryWithProvider", () => {
|
||||||
providers.forEach((provider: ISearchProviderProps) => {
|
props.providers?.forEach((provider: ISearchProviderProps) => {
|
||||||
handleQueryWithProvider(providers, provider.prefix + " test");
|
handleQueryWithProvider(props, provider.prefix + " test");
|
||||||
expect(window.location.href).toEqual(provider.url + "test");
|
expect(window.location.href).toEqual(provider.url + "test");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Tests handleQueryWithProvider default", () => {
|
it("Tests handleQueryWithProvider default", () => {
|
||||||
handleQueryWithProvider(providers, "test");
|
handleQueryWithProvider(props, "test");
|
||||||
expect(window.location.href).toEqual("https://google.com/search?q=test");
|
expect(window.location.href).toEqual(props.defaultProvider + "test");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Tests handleQueryWithProvider without providers", () => {
|
it("Tests handleQueryWithProvider without providers", () => {
|
||||||
handleQueryWithProvider(undefined, "test");
|
const test: ISearchProps = {
|
||||||
expect(window.location.href).toEqual("https://google.com/search?q=test");
|
defaultProvider: "https://test.com?q=",
|
||||||
|
providers: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
handleQueryWithProvider(test, "test");
|
||||||
|
expect(window.location.href).toEqual(test.defaultProvider + "test");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Tests SearchBar component with default search", () => {
|
it("Tests SearchBar component with default search", () => {
|
||||||
|
@ -75,7 +85,7 @@ describe("searchBar.tsx", () => {
|
||||||
fireEvent.change(input, { target: { value: "test" } });
|
fireEvent.change(input, { target: { value: "test" } });
|
||||||
fireEvent.click(submitButton);
|
fireEvent.click(submitButton);
|
||||||
|
|
||||||
expect(window.location.href).toEqual("https://google.com/search?q=test");
|
expect(window.location.href).toEqual(props.defaultProvider + "test");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Tests SearchBar component with other search", () => {
|
it("Tests SearchBar component with other search", () => {
|
||||||
|
@ -96,6 +106,6 @@ describe("searchBar.tsx", () => {
|
||||||
fireEvent.click(clearButton);
|
fireEvent.click(clearButton);
|
||||||
fireEvent.click(submitButton);
|
fireEvent.click(submitButton);
|
||||||
|
|
||||||
expect(window.location.href).toEqual("https://google.com/search?q=");
|
expect(window.location.href).toEqual(props.defaultProvider);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,7 +9,7 @@ import Settings, {
|
||||||
SectionHeadline,
|
SectionHeadline,
|
||||||
SelectorStyle,
|
SelectorStyle,
|
||||||
} from "../../components/settings";
|
} from "../../components/settings";
|
||||||
import { ISearchProviderProps } from "../../components/searchBar";
|
import { ISearchProps } from "../../components/searchBar";
|
||||||
import { IThemeProps } from "../../lib/theme";
|
import { IThemeProps } from "../../lib/theme";
|
||||||
|
|
||||||
const themes: Array<IThemeProps> = [
|
const themes: Array<IThemeProps> = [
|
||||||
|
@ -29,40 +29,43 @@ const themes: Array<IThemeProps> = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const providers: Array<ISearchProviderProps> = [
|
const search: ISearchProps = {
|
||||||
{
|
defaultProvider: "https://test.com?q=",
|
||||||
name: "Allmusic",
|
providers: [
|
||||||
url: "https://www.allmusic.com/search/all/",
|
{
|
||||||
prefix: "/a",
|
name: "Allmusic",
|
||||||
},
|
url: "https://www.allmusic.com/search/all/",
|
||||||
{
|
prefix: "/a",
|
||||||
name: "Discogs",
|
},
|
||||||
url: "https://www.discogs.com/search/?q=",
|
{
|
||||||
prefix: "/di",
|
name: "Discogs",
|
||||||
},
|
url: "https://www.discogs.com/search/?q=",
|
||||||
{
|
prefix: "/di",
|
||||||
name: "Duck Duck Go",
|
},
|
||||||
url: "https://duckduckgo.com/?q=",
|
{
|
||||||
prefix: "/d",
|
name: "Duck Duck Go",
|
||||||
},
|
url: "https://duckduckgo.com/?q=",
|
||||||
];
|
prefix: "/d",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
const propsList = [
|
const propsList = [
|
||||||
{
|
{
|
||||||
themes: themes,
|
themes: themes,
|
||||||
providers: providers,
|
search: search,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
themes: themes,
|
themes: themes,
|
||||||
providers: undefined,
|
search: undefined,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
themes: undefined,
|
themes: undefined,
|
||||||
providers: providers,
|
search: search,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
themes: undefined,
|
themes: undefined,
|
||||||
providers: undefined,
|
search: undefined,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -115,7 +118,7 @@ describe("settings.tsx", () => {
|
||||||
it("Tests settings rendering", () => {
|
it("Tests settings rendering", () => {
|
||||||
propsList.forEach((props) => {
|
propsList.forEach((props) => {
|
||||||
const settings = render(
|
const settings = render(
|
||||||
<Settings themes={props.themes} providers={props.providers} />,
|
<Settings themes={props.themes} search={props.search} />,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(settings.asFragment).toMatchSnapshot();
|
expect(settings.asFragment).toMatchSnapshot();
|
||||||
|
@ -125,10 +128,7 @@ describe("settings.tsx", () => {
|
||||||
// TODO: Finish this test
|
// TODO: Finish this test
|
||||||
it("Tests theme setting", () => {
|
it("Tests theme setting", () => {
|
||||||
const settings = render(
|
const settings = render(
|
||||||
<Settings
|
<Settings themes={propsList[0].themes} search={propsList[0].search} />,
|
||||||
themes={propsList[0].themes}
|
|
||||||
providers={propsList[0].providers}
|
|
||||||
/>,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const toggleButton = settings.getByTestId("toggle-button");
|
const toggleButton = settings.getByTestId("toggle-button");
|
||||||
|
|
Loading…
Reference in a new issue