Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sillsdev/TheCombine
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 32cfcfa4a19e5b292e880bc4512b5b0d28ea873d
Choose a base ref
..
head repository: sillsdev/TheCombine
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e21032cee0fc207418152182854c285352574434
Choose a head ref
Showing with 57 additions and 19 deletions.
  1. +57 −19 src/goals/MergeDuplicates/Redux/tests/MergeDupsReducer.test.tsx
76 changes: 57 additions & 19 deletions src/goals/MergeDuplicates/Redux/tests/MergeDupsReducer.test.tsx
Original file line number Diff line number Diff line change
@@ -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();
});
});