Skip to content

Commit 3173a66

Browse files
committed
feat: tests for the Abstract component
1 parent 4ce7f4b commit 3173a66

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { render } from "@testing-library/react";
2+
import { Localization } from "../../../../js/i18n/localization";
3+
import LocalizationProvider from "../../../../js/components/LocalizationProvider";
4+
import Abstract from "../../../../js/templates/listentry/Abstract";
5+
import React from "react";
6+
import { Provider } from "react-redux";
7+
import configureStore from "redux-mock-store";
8+
9+
const mockStore = configureStore([]);
10+
11+
describe("Abstract in the ListEntry component", () => {
12+
const setup = (isSelectedPaper: boolean, abstractText?: string) => {
13+
const LOCALIZATION_OBJECT_MOCK: Pick<Localization, "default_abstract"> = {
14+
default_abstract: "No abstract available",
15+
};
16+
17+
const STORE_DATA_MOCK = {
18+
selectedPaper: isSelectedPaper,
19+
list: { searchValue: "" },
20+
query: { parsedTerms: "" },
21+
};
22+
23+
const STORE_MOCK = mockStore(STORE_DATA_MOCK);
24+
25+
const { container } = render(
26+
<LocalizationProvider
27+
localization={LOCALIZATION_OBJECT_MOCK as Localization}
28+
>
29+
<Provider store={STORE_MOCK}>
30+
<Abstract text={abstractText as string} />
31+
</Provider>
32+
</LocalizationProvider>,
33+
);
34+
35+
return container;
36+
};
37+
38+
it("Shows abstract text if it is presented", () => {
39+
const container = setup(true, "Some cool abstract text.");
40+
41+
const paragraphWithAbstract = container.querySelector("#list_abstract");
42+
expect(paragraphWithAbstract).toBeInTheDocument();
43+
expect(paragraphWithAbstract).toHaveTextContent("Some cool abstract text.");
44+
});
45+
46+
it("Shows abstract text with additional styling if it is presented and document is not selected", () => {
47+
const container = setup(false, "Some cool abstract text.");
48+
49+
const paragraphWithAbstract = container.querySelector("#list_abstract");
50+
expect(paragraphWithAbstract).toBeInTheDocument();
51+
expect(paragraphWithAbstract).toHaveClass("short");
52+
expect(paragraphWithAbstract).toHaveTextContent("Some cool abstract text.");
53+
});
54+
55+
it("Shows template text from localization if abstract is not presented", () => {
56+
const container = setup(false, undefined);
57+
58+
const paragraphWithAbstract = container.querySelector("#list_abstract");
59+
expect(paragraphWithAbstract).toBeInTheDocument();
60+
expect(paragraphWithAbstract).toHaveTextContent("No abstract available");
61+
});
62+
});

0 commit comments

Comments
 (0)