- <>
+
- >
+
);
}
diff --git a/src/goals/ReviewEntries/ReviewEntriesTypes.ts b/src/goals/ReviewEntries/ReviewEntriesTypes.ts
index 0b06f81886..7bcd8b190a 100644
--- a/src/goals/ReviewEntries/ReviewEntriesTypes.ts
+++ b/src/goals/ReviewEntries/ReviewEntriesTypes.ts
@@ -9,7 +9,7 @@ import {
Word,
} from "api/models";
import { Goal, GoalName, GoalType } from "types/goals";
-import { newSense, newWord } from "types/word";
+import { newNote, newSense, newWord } from "types/word";
import { cleanDefinitions, cleanGlosses } from "utilities/wordUtilities";
export enum ColumnId {
@@ -113,3 +113,35 @@ export class ReviewEntriesSense {
return sense.glosses.map((g) => g.def).join(ReviewEntriesSense.SEPARATOR);
}
}
+
+/** Reverse map of the ReviewEntriesSense constructor.
+ * Important: Not everything is preserved! */
+function senseFromReviewEntriesSense(revSense: ReviewEntriesSense): Sense {
+ return {
+ ...newSense(),
+ accessibility: revSense.protected
+ ? Status.Protected
+ : revSense.deleted
+ ? Status.Deleted
+ : Status.Active,
+ definitions: revSense.definitions.map((d) => ({ ...d })),
+ glosses: revSense.glosses.map((g) => ({ ...g })),
+ grammaticalInfo: revSense.partOfSpeech,
+ guid: revSense.guid,
+ semanticDomains: revSense.domains.map((dom) => ({ ...dom })),
+ };
+}
+
+/** Reverse map of the ReviewEntriesWord constructor.
+ * Important: Not everything is preserved! */
+export function wordFromReviewEntriesWord(revWord: ReviewEntriesWord): Word {
+ return {
+ ...newWord(revWord.vernacular),
+ accessibility: revWord.protected ? Status.Protected : Status.Active,
+ audio: [...revWord.audio],
+ id: revWord.id,
+ flag: { ...revWord.flag },
+ note: newNote(revWord.noteText),
+ senses: revWord.senses.map(senseFromReviewEntriesSense),
+ };
+}
diff --git a/src/goals/ReviewEntries/tests/ReviewEntriesReducer.test.tsx b/src/goals/ReviewEntries/tests/ReviewEntriesReducer.test.tsx
deleted file mode 100644
index b9873b3331..0000000000
--- a/src/goals/ReviewEntries/tests/ReviewEntriesReducer.test.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-import { reviewEntriesReducer } from "goals/ReviewEntries/Redux/ReviewEntriesReducer";
-import {
- defaultState,
- ReviewEntriesActionTypes,
-} from "goals/ReviewEntries/Redux/ReviewEntriesReduxTypes";
-import {
- ReviewEntriesSense,
- ReviewEntriesWord,
-} from "goals/ReviewEntries/ReviewEntriesTypes";
-import mockWords from "goals/ReviewEntries/tests/WordsMock";
-import { newSemanticDomain } from "types/semanticDomain";
-import { Bcp47Code } from "types/writingSystem";
-
-const mockState = {
- ...defaultState,
- words: mockWords(),
-};
-const reviewEntriesWord: ReviewEntriesWord = {
- ...new ReviewEntriesWord(),
- id: mockState.words[0].id,
- vernacular: "toadTOAD",
- senses: [
- {
- ...new ReviewEntriesSense(),
- guid: "1",
- glosses: [{ def: "bupBUP", language: Bcp47Code.En }],
- domains: [
- newSemanticDomain("number", "domain"),
- newSemanticDomain("number2", "domain2"),
- ],
- },
- ],
-};
-const result: ReviewEntriesWord = {
- ...new ReviewEntriesWord(),
- id: "a new mock id",
- vernacular: "toadTOAD",
- senses: [
- {
- ...new ReviewEntriesSense(),
- guid: "1",
- glosses: [{ def: "bupBUP", language: Bcp47Code.En }],
- domains: [
- newSemanticDomain("number", "domain"),
- newSemanticDomain("number2", "domain2"),
- ],
- },
- ],
-};
-
-describe("ReviewEntriesReducer", () => {
- it("Returns default state when passed undefined state", () => {
- expect(reviewEntriesReducer(undefined, { type: undefined } as any)).toEqual(
- defaultState
- );
- });
-
- it("Adds a set of words to a list when passed an UpdateAllWords action", () => {
- expect(
- reviewEntriesReducer(defaultState, {
- type: ReviewEntriesActionTypes.UpdateAllWords,
- words: mockWords(),
- })
- ).toEqual(mockState);
- });
-
- it("Updates a specified word when passed an UpdateWord action", () => {
- expect(
- reviewEntriesReducer(mockState, {
- type: ReviewEntriesActionTypes.UpdateWord,
- oldId: mockWords()[0].id,
- updatedWord: { ...reviewEntriesWord, id: result.id },
- })
- ).toEqual({ ...mockState, words: [result, mockWords()[1]] });
- });
-});
diff --git a/src/goals/ReviewEntries/tests/WordsMock.ts b/src/goals/ReviewEntries/tests/WordsMock.ts
index 01a2bfbca9..45d65b8ecc 100644
--- a/src/goals/ReviewEntries/tests/WordsMock.ts
+++ b/src/goals/ReviewEntries/tests/WordsMock.ts
@@ -1,17 +1,10 @@
-import { GramCatGroup, Sense, Word } from "api/models";
+import { GramCatGroup } from "api/models";
import {
ReviewEntriesSense,
ReviewEntriesWord,
} from "goals/ReviewEntries/ReviewEntriesTypes";
import { newSemanticDomain } from "types/semanticDomain";
-import {
- newDefinition,
- newFlag,
- newGloss,
- newNote,
- newSense,
- newWord,
-} from "types/word";
+import { newDefinition, newFlag, newGloss } from "types/word";
import { Bcp47Code } from "types/writingSystem";
export default function mockWords(): ReviewEntriesWord[] {
@@ -57,24 +50,3 @@ export default function mockWords(): ReviewEntriesWord[] {
},
];
}
-
-export function mockCreateWord(word: ReviewEntriesWord): Word {
- return {
- ...newWord(word.vernacular),
- id: word.id,
- senses: word.senses.map((sense) => createMockSense(sense)),
- note: newNote(word.noteText),
- flag: word.flag,
- };
-}
-
-function createMockSense(sense: ReviewEntriesSense): Sense {
- return {
- ...newSense(),
- guid: sense.guid,
- definitions: [...sense.definitions],
- glosses: [...sense.glosses],
- grammaticalInfo: sense.partOfSpeech,
- semanticDomains: [...sense.domains],
- };
-}
diff --git a/src/goals/ReviewEntries/tests/index.test.tsx b/src/goals/ReviewEntries/tests/index.test.tsx
index 7590959b91..ab346fade8 100644
--- a/src/goals/ReviewEntries/tests/index.test.tsx
+++ b/src/goals/ReviewEntries/tests/index.test.tsx
@@ -7,8 +7,11 @@ import "tests/reactI18nextMock";
import ReviewEntries from "goals/ReviewEntries";
import * as actions from "goals/ReviewEntries/Redux/ReviewEntriesActions";
-import { ReviewEntriesWord } from "goals/ReviewEntries/ReviewEntriesTypes";
-import mockWords, { mockCreateWord } from "goals/ReviewEntries/tests/WordsMock";
+import {
+ ReviewEntriesWord,
+ wordFromReviewEntriesWord,
+} from "goals/ReviewEntries/ReviewEntriesTypes";
+import mockWords from "goals/ReviewEntries/tests/WordsMock";
import { defaultWritingSystem } from "types/writingSystem";
const mockGetFrontierWords = jest.fn();
@@ -33,16 +36,16 @@ jest.mock("notistack", () => ({
...jest.requireActual("notistack"),
enqueueSnackbar: jest.fn(),
}));
-jest.mock("uuid", () => ({ v4: () => mockUuid() }));
+jest.mock("uuid", () => ({
+ v4: () => mockUuid(),
+}));
jest.mock("backend", () => ({
getFrontierWords: (...args: any[]) => mockGetFrontierWords(...args),
}));
// Mock the node module used by AudioRecorder.
jest.mock("components/Pronunciations/Recorder");
jest.mock("components/TreeView", () => "div");
-jest.mock("components/GoalTimeline/Redux/GoalActions", () => ({
- addEntryEditToGoal: () => jest.fn(),
-}));
+jest.mock("components/GoalTimeline/Redux/GoalActions", () => ({}));
jest.mock("types/hooks", () => ({
useAppDispatch: () => jest.fn(),
}));
@@ -70,7 +73,7 @@ const mockStore = configureMockStore()(state);
function setMockFunctions(): void {
jest.clearAllMocks();
mockGetFrontierWords.mockResolvedValue(
- mockReviewEntryWords.map(mockCreateWord)
+ mockReviewEntryWords.map(wordFromReviewEntriesWord)
);
mockMaterialTable.mockReturnValue(Fragment);
}