diff --git a/src/goals/MergeDuplicates/Redux/tests/MergeDupsReducer.test.tsx b/src/goals/MergeDuplicates/Redux/tests/MergeDupsReducer.test.tsx index d4e62a6d01..d0059017cc 100644 --- a/src/goals/MergeDuplicates/Redux/tests/MergeDupsReducer.test.tsx +++ b/src/goals/MergeDuplicates/Redux/tests/MergeDupsReducer.test.tsx @@ -1,5 +1,6 @@ import { type Action, type PayloadAction } from "@reduxjs/toolkit"; +import { Status } from "api/models"; import { type MergeTreeReference, type MergeTreeWord, @@ -17,6 +18,7 @@ import { moveSense, orderSense, setData, + toggleOverrideProtection, } from "goals/MergeDuplicates/Redux/MergeDupsActions"; import mergeDupStepReducer from "goals/MergeDuplicates/Redux/MergeDupsReducer"; import { @@ -572,25 +574,61 @@ describe("MergeDupsReducer", () => { ); }); - test("setWordData", () => { - const wordList = testWordList(); - const treeState = mergeDupStepReducer(undefined, setData(wordList)); - // check if data has all words present - for (const word of wordList) { - const srcWordId = word.id; - expect(Object.keys(treeState.data.words)).toContain(srcWordId); - // check each sense of word - for (const [order, sense] of word.senses.entries()) { - const treeSense = convertSenseToMergeTreeSense(sense, srcWordId, order); - const senses = treeState.data.senses; - expect(Object.values(senses).map((s) => JSON.stringify(s))).toContain( - JSON.stringify(treeSense) - ); - // check that this sense is somewhere in the tree - expect( - getRefByGuid(treeSense.sense.guid, treeState.tree.words) - ).toBeDefined(); + describe("setWordData", () => { + test("with no protected words/senses", () => { + const wordList = testWordList(); + const treeState = mergeDupStepReducer(undefined, setData(wordList)); + // check if data has all words present + for (const word of wordList) { + const srcWordId = word.id; + expect(Object.keys(treeState.data.words)).toContain(srcWordId); + // check each sense of word + for (const [order, sense] of word.senses.entries()) { + const treeSense = convertSenseToMergeTreeSense( + sense, + srcWordId, + order + ); + const senses = treeState.data.senses; + expect(Object.values(senses).map((s) => JSON.stringify(s))).toContain( + JSON.stringify(treeSense) + ); + // check that this sense is somewhere in the tree + expect( + getRefByGuid(treeSense.sense.guid, treeState.tree.words) + ).toBeDefined(); + } } - } + // check that overrideProtection is reset + expect(treeState.overrideProtection).toEqual(false); + // check that hasProtected is false + expect(treeState.hasProtected).toBeFalsy(); + }); + + test("with protected word", () => { + const wordList = testWordList(); + wordList[1].accessibility = Status.Protected; + const treeState = mergeDupStepReducer(undefined, setData(wordList)); + // check that hasProtected is true + expect(treeState.hasProtected).toBeTruthy(); + }); + + test("with protected sense", () => { + const wordList = testWordList(); + wordList.find((w) => w.senses.length)!.senses[0].accessibility = + Status.Protected; + const treeState = mergeDupStepReducer(undefined, setData(wordList)); + // check that hasProtected is true + expect(treeState.hasProtected).toBeTruthy(); + }); + }); + + test("toggleOverrideProtection", () => { + let state = defaultState; + expect(state.overrideProtection).toBeFalsy(); + state = mergeDupStepReducer(state, toggleOverrideProtection()); + expect(state.overrideProtection).toBeTruthy(); + state = mergeDupStepReducer(state, toggleOverrideProtection()); + expect(state.overrideProtection).toBeFalsy(); }); });