Skip to content

Commit

Permalink
Reduce code smell
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec committed Jul 22, 2024
1 parent 7b13aa8 commit f44256c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/components/DataEntry/DataEntryTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ export function updateEntryGloss(
const newSense: Sense = { ...sense };
let glossIndex = sense.glosses.findIndex((g) => g.language === analysisLang);
if (glossIndex === -1) {
// It there's no gloss in the current analysis language, then it's the first gloss
// that was shown in the RecentEntry that's now being updated.
glossIndex = 0;
}
newSense.glosses = sense.glosses.map((g, i) =>
Expand Down
14 changes: 7 additions & 7 deletions src/components/DataEntry/DataEntryTable/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ describe("DataEntryTable", () => {
describe("updateEntryGloss", () => {
it("throws error when entry doesn't have sense with specified guid", () => {
const entry: WordAccess = { word: newWord(), senseGuid: "gibberish" };
expect(() => updateEntryGloss(entry, "def", "semDomId", "")).toThrow();
expect(() => updateEntryGloss(entry, "def", "semDomId", "en")).toThrow();
});

it("directly updates a sense with no other semantic domains", () => {
Expand All @@ -260,9 +260,9 @@ describe("DataEntryTable", () => {
const expectedWord: Word = { ...entry.word };
expectedWord.senses[senseIndex] = { ...sense, glosses: [expectedGloss] };

expect(updateEntryGloss(entry, def, mockSemDom.id, "")).toEqual(
expectedWord
);
expect(
updateEntryGloss(entry, def, mockSemDom.id, sense.glosses[0].language)
).toEqual(expectedWord);
});

it("updates gloss of specified language", () => {
Expand Down Expand Up @@ -301,9 +301,9 @@ describe("DataEntryTable", () => {
newSense.semanticDomains = [mockSemDom];
const expectedWord: Word = { ...word, senses: [oldSense, newSense] };

expect(updateEntryGloss(entry, def, mockSemDom.id, "")).toEqual(
expectedWord
);
expect(
updateEntryGloss(entry, def, mockSemDom.id, sense.glosses[0].language)
).toEqual(expectedWord);
});
});

Expand Down

0 comments on commit f44256c

Please sign in to comment.