Skip to content
Myr

chore: regression tests for fixed issue #916 (#1215)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Dean Kerr · committed by GitHub · parent b67db83 · Browse files · 1 file+63 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+63 added−0 removed

  • tests:+63 added−0 removed

1 file+63 added−0 removed

modified:__tests__/patch.js+63 added
196 unmodified lines
197 expect(replaceValueAfter).toStrictEqual(replaceValueBefore)198 })199})200201describe("#916 nested patches with moved child draft", () => {202 const makeBaseState = () => ({203 id: 0,204 type: "root",205 children: [{id: 2, type: "node", value: "A"}]206 })207208 const makeRootWithGroup = groupName => ({209 id: 0,210 type: "root",211 children: [212 {213 id: 3,214 children: [{id: 2, type: "node", value: "A"}],215 groupName216 }217 ]218 })219220 function runNestedPatchScenario() {221 let nestedPatches = []222 const [nextState] = produceWithPatches(makeBaseState(), draft => {223 const node = draft.children[0]224 draft.children.splice(0, 1) // remove node from root225226 const group = {id: 3, children: [node], groupName: ""} // new group227 draft.children.splice(0, 0, group) // add group to root228229 const [, patches] = produceWithPatches(draft, inner => {230 const value = inner.children[0].children[0].value231 inner.children[0].groupName = value + " Group"232 })233234 nestedPatches = patches235 applyPatches(draft, patches)236 })237238 return {nextState, patches: nestedPatches}239 }240241 it("#916 nested patches with moved child draft", () => {242 const {nextState, patches} = runNestedPatchScenario()243244 expect(patches).toEqual(245 expect.arrayContaining([246 {247 op: "replace",248 path: ["children", 0, "groupName"],249 value: "A Group"250 }251 ])252 )253 expect(nextState).toEqual(makeRootWithGroup("A Group"))254 })255256 it("#916 patches apply on non-draft base", () => {257 const {patches} = runNestedPatchScenario()258 expect(applyPatches(makeRootWithGroup(""), patches)).toEqual(259 makeRootWithGroup("A Group")260 )261 })262})263264// New macro-style test265runPatchTests(266 "simple assignment - 1",267 {x: 3},
1331 unmodified lines