Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix determination of which words have been merged #2902

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading