Load the finished Rule itself on Edit, and ask before replacing a draft in progress.
This commit is contained in:
1 parent
942c7cc9de
commit
d576ed81d9
4 files changed
+171
-7
No files matched your search
@@ -0,0 +1,78 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
createFlowStateForEditingPublishedRule,
|
||||
createFlowStateMatchesPublishedRule,
|
||||
publishedRuleEditWouldReplaceDraft,
|
||||
} from "../../lib/create/beginEditingPublishedRule";
|
||||
import type { StoredLastPublishedRule } from "../../lib/create/lastPublishedRule";
|
||||
import type { CreateFlowState } from "../../app/(app)/create/types";
|
||||
|
||||
const published: StoredLastPublishedRule = {
|
||||
id: "rule-qa",
|
||||
title: "QA Tenants Union",
|
||||
summary: "How we share the building.",
|
||||
document: {
|
||||
coreValues: [
|
||||
{
|
||||
chipId: "accountability",
|
||||
label: "Accountability",
|
||||
meaning: "We say what we will do.",
|
||||
signals: "",
|
||||
},
|
||||
],
|
||||
methodSelections: {
|
||||
communication: [
|
||||
{
|
||||
id: "signal",
|
||||
label: "Signal",
|
||||
sections: {
|
||||
corePrinciple: "We write it down.",
|
||||
logisticsAdmin: "A shared thread.",
|
||||
codeOfConduct: "No pile-ons.",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
describe("publishedRuleEditWouldReplaceDraft", () => {
|
||||
it("is false when there is no draft", () => {
|
||||
expect(publishedRuleEditWouldReplaceDraft({}, published)).toBe(false);
|
||||
});
|
||||
|
||||
it("is false when the draft is already this finished Rule", () => {
|
||||
const state = createFlowStateForEditingPublishedRule(published);
|
||||
expect(publishedRuleEditWouldReplaceDraft(state, published)).toBe(false);
|
||||
expect(createFlowStateMatchesPublishedRule(state, published)).toBe(true);
|
||||
});
|
||||
|
||||
it("is true when the draft is a different community", () => {
|
||||
const state: CreateFlowState = {
|
||||
title: "The CommunityRule Project",
|
||||
selectedCoreValueIds: ["solidarity"],
|
||||
selectedCommunicationMethodIds: ["loomio"],
|
||||
};
|
||||
expect(publishedRuleEditWouldReplaceDraft(state, published)).toBe(true);
|
||||
});
|
||||
|
||||
it("is true when the draft is already marked as an edit of another Rule", () => {
|
||||
const state: CreateFlowState = {
|
||||
...createFlowStateForEditingPublishedRule(published),
|
||||
editingPublishedRuleId: "some-other-rule",
|
||||
};
|
||||
expect(publishedRuleEditWouldReplaceDraft(state, published)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("createFlowStateForEditingPublishedRule", () => {
|
||||
it("loads the finished Rule's own name and cards, not leftover draft fields", () => {
|
||||
const state = createFlowStateForEditingPublishedRule(published);
|
||||
expect(state.title).toBe("QA Tenants Union");
|
||||
expect(state.editingPublishedRuleId).toBe("rule-qa");
|
||||
expect(state.selectedCommunicationMethodIds).toEqual(["signal"]);
|
||||
expect(state.selectedOrganizationTypeIds).toBeUndefined();
|
||||
expect(state.communityAvatarUrl).toBeUndefined();
|
||||
expect(state.sections).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user