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

[ReviewEntriesActions] Fix flag not saving; Add tests for note and flag #2668

Merged
merged 3 commits into from
Oct 9, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export function updateFrontierWord(
getSenseFromEditSense(s, editWord.senses)
);
editWord.note = newNote(editSource.noteText, editWord.note?.language);
editWord.flag = { ...editSource.flag };

// Update the word in the backend, and retrieve the id.
editSource.id = (await backend.updateWord(editWord)).id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ReviewEntriesWord,
} from "goals/ReviewEntries/ReviewEntriesComponent/ReviewEntriesTypes";
import { newSemanticDomain } from "types/semanticDomain";
import { newGloss, newSense, newWord } from "types/word";
import { newFlag, newGloss, newNote, newSense, newWord } from "types/word";
import { Bcp47Code } from "types/writingSystem";

const mockGetWord = jest.fn();
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("ReviewEntriesActions", () => {
expect(mockUpdateWord.mock.calls[0][0]).toEqual(newFrontierWord);
}

describe("Adds data", () => {
describe("Changes data", () => {
it("Changes the vernacular.", async () => {
const newRevWord = mockReviewEntriesWord("foo2");
const newFrontierWord = mockFrontierWord("foo2");
Expand All @@ -109,6 +109,44 @@ describe("ReviewEntriesActions", () => {
checkResultantData(newFrontierWord);
});

it("Changes the note.", async () => {
const oldNoteText = "old-note";
const oldRevWord = mockReviewEntriesWord();
oldRevWord.noteText = oldNoteText;
const oldFrontierWord = mockFrontierWord();
oldFrontierWord.note = newNote(oldNoteText, Bcp47Code.Pt);

const newNoteText = "new-note";
const newRevWord = mockReviewEntriesWord();
newRevWord.noteText = newNoteText;
const newFrontierWord = mockFrontierWord();
newFrontierWord.note = newNote(newNoteText, Bcp47Code.Pt);

mockGetWordResolve(oldFrontierWord);
await makeDispatch(newRevWord, oldRevWord);
checkResultantData(newFrontierWord);
});

it("Changes the flag.", async () => {
const oldFlagText = "old-flag";
const oldRevWord = mockReviewEntriesWord();
oldRevWord.flag = newFlag(oldFlagText);
const oldFrontierWord = mockFrontierWord();
oldFrontierWord.flag = newFlag(oldFlagText);

const newFlagText = "new-flag";
const newRevWord = mockReviewEntriesWord();
newRevWord.flag = newFlag(newFlagText);
const newFrontierWord = mockFrontierWord();
newFrontierWord.flag = newFlag(newFlagText);

mockGetWordResolve(oldFrontierWord);
await makeDispatch(newRevWord, oldRevWord);
checkResultantData(newFrontierWord);
});
});

describe("Adds data", () => {
it("Adds a gloss to an extant sense.", async () => {
const newRevWord = mockReviewEntriesWord();
newRevWord.senses[0].glosses.push(gloss1);
Expand Down Expand Up @@ -141,6 +179,17 @@ describe("ReviewEntriesActions", () => {
await makeDispatch(newRevWord, mockReviewEntriesWord());
checkResultantData(newFrontierWord);
});

it("Adds a flag.", async () => {
const newFlagText = "new-flag";
const newRevWord = mockReviewEntriesWord();
newRevWord.flag = newFlag(newFlagText);
const newFrontierWord = mockFrontierWord();
newFrontierWord.flag = newFlag(newFlagText);

await makeDispatch(newRevWord, mockReviewEntriesWord());
checkResultantData(newFrontierWord);
});
});

describe("Removes data", () => {
Expand All @@ -153,6 +202,7 @@ describe("ReviewEntriesActions", () => {
});
const newRevWord = mockReviewEntriesWord();
newRevWord.senses.push(oldSense);

const oldFrontierWord = mockFrontierWord();
const oldFrontierSense = sense1();
oldFrontierWord.senses.push({
Expand All @@ -176,6 +226,7 @@ describe("ReviewEntriesActions", () => {
});
const newRevWord = mockReviewEntriesWord();
newRevWord.senses.push(oldSense);

const oldFrontierWord = mockFrontierWord();
const oldFrontierSense = sense1();
oldFrontierWord.senses.push({
Expand All @@ -200,6 +251,18 @@ describe("ReviewEntriesActions", () => {
await makeDispatch(mockReviewEntriesWord(), oldRevWord);
checkResultantData(mockFrontierWord());
});

it("Removes the flag.", async () => {
const oldFlagText = "old-flag";
const oldRevWord = mockReviewEntriesWord();
oldRevWord.flag = newFlag(oldFlagText);
const oldFrontierWord = mockFrontierWord();
oldRevWord.flag = newFlag(oldFlagText);

mockGetWordResolve(oldFrontierWord);
await makeDispatch(mockReviewEntriesWord(), oldRevWord);
checkResultantData(mockFrontierWord());
});
});

describe("Circumvents bad data", () => {
Expand Down