Skip to content

Commit

Permalink
[MergeDups] Fix determining which words have been merged (#2902)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored and jmgrady committed Mar 6, 2024
1 parent 6586611 commit f4b0edd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/goals/MergeDuplicates/Redux/MergeDupsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ export function mergeAll() {
}

// Blacklist the set of words with updated ids.
const mergedIds = mergeWordsArray.map((mw) => mw.parent.id);
const mergedIds = new Set(
mergeWordsArray.flatMap((mw) => mw.children.map((c) => c.srcWordId))
);
const unmergedIds = Object.keys(mergeTree.data.words).filter(
(id) => !mergedIds.includes(id)
(id) => !mergedIds.has(id)
);
const blacklistIds = [...unmergedIds, ...parentIds];
if (blacklistIds.length > 1) {
Expand Down
28 changes: 28 additions & 0 deletions src/goals/MergeDuplicates/Redux/tests/MergeDupsActions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,34 @@ describe("MergeDupActions", () => {
// No blacklist entry added for only 1 resulting word.
expect(mockBlacklistAdd).not.toHaveBeenCalled();
});
// Move all senses from B to A
it("moves all senses to other word", async () => {
const WA = newMergeTreeWord(vernA, {
ID1: [S1, S3],
ID2: [S2],
ID3: [S4],
});
const tree: MergeTree = { ...defaultTree, words: { WA } };
const store = setupStore({
...preloadedState,
mergeDuplicateGoal: { ...defaultMergeState, data, tree },
});
await store.dispatch(mergeAll());

expect(mockMergeWords).toHaveBeenCalledTimes(1);
const parentA = wordAnyGuids(
vernA,
[senses["S1"], senses["S2"], senses["S4"]],
idA
);
const childA = { srcWordId: idA, getAudio: true };
const childB = { srcWordId: idB, getAudio: true };
const mockMerge = newMergeWords(parentA, [childA, childB]);
expect(mockMergeWords).toHaveBeenCalledWith([mockMerge]);

// No blacklist entry added for only 1 resulting word.
expect(mockBlacklistAdd).not.toHaveBeenCalled();
});

// Performs a merge when a word is flagged
it("adds a flag to a word", async () => {
Expand Down

0 comments on commit f4b0edd

Please sign in to comment.