Skip to content

Commit 27f823b

Browse files
committed
test(client): add test for reference-conflict-errors in ScheduleModal
1 parent 1414bfc commit 27f823b

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

__mocks__/styleMock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
jest.mock("react-day-picker/lib/style.css");
2+
jest.mock("react-router-dom", () => ({ Link: () => "Link" }));
3+
4+
import React from "react";
5+
import { render, fireEvent, waitForElement } from "@testing-library/react";
6+
import ScheduleModal from "../Schedule";
7+
import ModelPathsContext from "../../ModelPathsContext";
8+
9+
const conflictingRef = {
10+
id: 117,
11+
model: "index",
12+
type: "content",
13+
title: "Startseite",
14+
kind: "Startseite"
15+
};
16+
17+
it("should display ConflictDialog on schedule error", async () => {
18+
const onSchedule = jest.fn(async () =>
19+
Promise.reject({
20+
body: {
21+
conflictingRefs: [conflictingRef]
22+
}
23+
})
24+
);
25+
const { findByText } = render(
26+
<ModelPathsContext.Provider
27+
value={{
28+
modelPaths: { [conflictingRef.model]: "/test" },
29+
baseUrls: {} as any
30+
}}
31+
>
32+
<ScheduleModal
33+
schedule={{ visibleFrom: null, visibleUntil: null }}
34+
onClose={jest.fn()}
35+
onSchedule={onSchedule}
36+
/>
37+
</ModelPathsContext.Provider>
38+
);
39+
40+
const visibleUntilSlider = await waitForElement(() =>
41+
findByText(/Visible Until/i).then(e => e.closest("div"))
42+
);
43+
44+
fireEvent.click(visibleUntilSlider as Element);
45+
46+
const scheduleButton = await waitForElement(() =>
47+
findByText(/schedule/i, { selector: "span" }).then(e => e.closest("button"))
48+
);
49+
50+
fireEvent.click(scheduleButton as Element);
51+
52+
expect(onSchedule).toBeCalledTimes(1);
53+
expect(
54+
await waitForElement(() => findByText(/content in use/i))
55+
).toBeInTheDocument();
56+
});

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@
148148
],
149149
"watchPathIgnorePatterns": [
150150
"node_modules"
151-
]
151+
],
152+
"moduleNameMapper": {
153+
"\\.(css)$": "<rootDir>/__mocks__/styleMock.js"
154+
}
152155
}
153156
}

0 commit comments

Comments
 (0)