Keep shared Rule files reachable, and say when a privacy change does not save.
This commit is contained in:
1 parent
b6795c1f18
commit
63ba21c614
9 files changed
+148
-16
No files matched your search
@@ -8,8 +8,15 @@ import {
|
||||
} from "../../utils/test-utils";
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import Share from "../../../app/components/modals/Share";
|
||||
import { patchRuleShare } from "../../../lib/create/api";
|
||||
import type { RuleShareSettings } from "../../../lib/ruleShareTypes";
|
||||
|
||||
vi.mock("../../../lib/create/api", () => ({
|
||||
patchRuleShare: vi.fn(),
|
||||
fetchRuleShare: vi.fn(),
|
||||
addRuleStakeholder: vi.fn(),
|
||||
}));
|
||||
|
||||
const previewSettings: RuleShareSettings = {
|
||||
visibility: "private",
|
||||
shareSlug: null,
|
||||
@@ -41,9 +48,18 @@ function openShare(overrides: Partial<RuleShareSettings> = {}) {
|
||||
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
const sharedSettings: RuleShareSettings = {
|
||||
...previewSettings,
|
||||
visibility: "shared_by_link",
|
||||
shareSlug: "k7f2-9qxm",
|
||||
shareUrl: "https://communityrule.info/r/k7f2-9qxm",
|
||||
shareUrlDisplay: "communityrule.info/r/k7f2-9qxm",
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
writeText.mockReset();
|
||||
writeText.mockResolvedValue(undefined);
|
||||
vi.mocked(patchRuleShare).mockReset();
|
||||
Object.defineProperty(window.navigator, "clipboard", {
|
||||
configurable: true,
|
||||
value: { writeText },
|
||||
@@ -133,6 +149,58 @@ describe("Share modal", () => {
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the link on and says so when turning the Rule private does not save", async () => {
|
||||
vi.mocked(patchRuleShare).mockResolvedValueOnce({
|
||||
ok: false,
|
||||
status: 500,
|
||||
error: "nope",
|
||||
});
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<Share
|
||||
isOpen
|
||||
onClose={vi.fn()}
|
||||
ruleId="rule-1"
|
||||
previewSettings={sharedSettings}
|
||||
/>,
|
||||
);
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: /Anyone with the link/i }),
|
||||
);
|
||||
await user.click(
|
||||
await screen.findByRole("option", { name: "Only people you invite" }),
|
||||
);
|
||||
expect(await screen.findByText("That change didn’t save")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Turn off link" }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByText("Only people you invite can open it."),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the link on and says so when turning the link off does not save", async () => {
|
||||
vi.mocked(patchRuleShare).mockResolvedValueOnce({
|
||||
ok: false,
|
||||
status: 500,
|
||||
error: "nope",
|
||||
});
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<Share
|
||||
isOpen
|
||||
onClose={vi.fn()}
|
||||
ruleId="rule-1"
|
||||
previewSettings={sharedSettings}
|
||||
/>,
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: "Turn off link" }));
|
||||
expect(await screen.findByText("That change didn’t save")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByDisplayValue("communityrule.info/r/k7f2-9qxm"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("calls onClose when Done is clicked", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onClose = vi.fn();
|
||||
|
||||
Reference in new issue
Block a user