diff --git a/src/components/DataEntry/DataEntryTable/NewEntry/VernDialog.tsx b/src/components/DataEntry/DataEntryTable/NewEntry/VernDialog.tsx index 03fc935f64..c64fd130c6 100644 --- a/src/components/DataEntry/DataEntryTable/NewEntry/VernDialog.tsx +++ b/src/components/DataEntry/DataEntryTable/NewEntry/VernDialog.tsx @@ -5,7 +5,7 @@ import { MenuList, Typography, } from "@mui/material"; -import { type ReactElement } from "react"; +import { Fragment, type ReactElement } from "react"; import { useTranslation } from "react-i18next"; import { GramCatGroup, type Word } from "api/models"; @@ -24,6 +24,10 @@ interface vernDialogProps { } export default function VernDialog(props: vernDialogProps): ReactElement { + if (!props.vernacularWords.length) { + return ; + } + return ( void; analysisLang?: string; @@ -96,7 +102,7 @@ export function VernList(props: VernListProps): ReactElement { menuItems.push( props.closeDialog("")}> {t("addWords.newEntryFor")} - {props.vernacularWords[0].vernacular} + {props.vernacular} ); diff --git a/src/components/DataEntry/DataEntryTable/NewEntry/tests/VernDialog.test.tsx b/src/components/DataEntry/DataEntryTable/NewEntry/tests/VernDialog.test.tsx index 0c3aca046c..318b497cc1 100644 --- a/src/components/DataEntry/DataEntryTable/NewEntry/tests/VernDialog.test.tsx +++ b/src/components/DataEntry/DataEntryTable/NewEntry/tests/VernDialog.test.tsx @@ -5,7 +5,9 @@ import configureMockStore from "redux-mock-store"; import { Word } from "api/models"; import StyledMenuItem from "components/DataEntry/DataEntryTable/NewEntry/StyledMenuItem"; -import { VernList } from "components/DataEntry/DataEntryTable/NewEntry/VernDialog"; +import VernDialog, { + VernList, +} from "components/DataEntry/DataEntryTable/NewEntry/VernDialog"; import theme from "types/theme"; import { testWordList } from "types/word"; import { defaultWritingSystem } from "types/writingSystem"; @@ -23,7 +25,21 @@ const mockState = { }; const mockStore = configureMockStore()(mockState); -describe("VernList ", () => { +describe("VernDialog", () => { + it("handles empty list", () => { + createVernDialogInstance([], true); + const vernList = testRenderer.root.findAllByType(VernList); + expect(vernList).toHaveLength(0); + }); +}); + +describe("VernList", () => { + it("handles empty list", () => { + createVernListInstance([], jest.fn()); + const menuItems = testRenderer.root.findAllByType(StyledMenuItem); + expect(menuItems).toHaveLength(1); + }); + it("closes dialog when selecting a menu item", () => { const closeDialogMockCallback = jest.fn(); const words = testWordList(); @@ -42,6 +58,28 @@ describe("VernList ", () => { }); }); +function createVernDialogInstance( + _vernacularWords: Word[], + open: boolean +): void { + renderer.act(() => { + testRenderer = renderer.create( + + + + + + + + ); + }); +} + function createVernListInstance( _vernacularWords: Word[], _mockCallback: jest.Mock @@ -52,6 +90,7 @@ function createVernListInstance(