Skip to content

Commit

Permalink
Fix uncalled/impotent test functions (#2945)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Feb 23, 2024
1 parent 179bb36 commit 4979ed8
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 40 deletions.
10 changes: 4 additions & 6 deletions src/components/AppBar/tests/NavigationButtons.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const mockStore = configureMockStore()({

let testRenderer: renderer.ReactTestRenderer;
let entryButton: ReactTestInstance;
let cleanButton: ReactTestInstance;
let cleanButton: ReactTestInstance | null;

const renderNavButtons = async (
path: Path,
Expand Down Expand Up @@ -57,9 +57,7 @@ const renderNavButtonsWithPermission = async (
const cleanupButtons = testRenderer.root.findAllByProps({
id: dataCleanupButtonId,
});
if (cleanupButtons.length) {
cleanButton = cleanupButtons[0];
}
cleanButton = cleanupButtons.length ? cleanupButtons[0] : null;
};

beforeEach(() => {
Expand All @@ -74,9 +72,9 @@ describe("NavigationButtons", () => {
perm === Permission.CharacterInventory ||
perm === Permission.MergeAndReviewEntries
) {
expect(cleanButton).toBeTruthy;
expect(cleanButton).toBeTruthy();
} else {
expect(cleanButton).toBeUndefined;
expect(cleanButton).toBeNull();
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/AppBar/tests/SpeakerMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("SpeakerMenuList", () => {
it("has one disabled menu item if no speakers", async () => {
await renderMenuList();
const menuItem = testRenderer.root.findByType(MenuItem);
expect(menuItem).toBeDisabled;
expect(menuItem.props.disabled).toBeTruthy();
});

it("has divider and one more menu item than speakers", async () => {
Expand Down
6 changes: 2 additions & 4 deletions src/components/DataEntry/DataEntryTable/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ describe("DataEntryTable", () => {
it("creates word when new entry has vernacular", async () => {
expect(mockCreateWord).not.toHaveBeenCalled();
testHandle = testRenderer.root.findByType(NewEntry);
expect(testHandle).not.toBeNull;
// Set newVern but not newGloss.
await act(async () => testHandle.props.setNewVern("hasVern"));
testHandle = testRenderer.root.findByProps({ id: exitButtonId });
Expand All @@ -161,7 +160,6 @@ describe("DataEntryTable", () => {

it("doesn't create word when new entry has no vernacular", async () => {
testHandle = testRenderer.root.findByType(NewEntry);
expect(testHandle).not.toBeNull;
// Set newGloss but not newVern.
await act(async () => testHandle.props.setNewGloss("hasGloss"));
testHandle = testRenderer.root.findByProps({ id: exitButtonId });
Expand Down Expand Up @@ -231,8 +229,8 @@ describe("DataEntryTable", () => {

describe("makeSemDomCurrent", () => {
it("adds timestamp and the current user", () => {
expect(mockSemDom.created).toBeUndefined;
expect(mockSemDom.userId).toBeUndefined;
expect(mockSemDom.created).toBeUndefined();
expect(mockSemDom.userId).toBeUndefined();

const currentDom = makeSemDomCurrent(mockSemDom);
expect(currentDom.created).not.toBeUndefined();
Expand Down
4 changes: 2 additions & 2 deletions src/components/DataEntry/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ describe("DataEntry", () => {
it("displays TreeView when state says the tree is open", async () => {
await renderDataEntry({ currentDomain: mockDomain, open: true });
const dialog = testHandle.root.findByProps({ id: treeViewDialogId });
expect(dialog.props.open).toBeTruthy;
expect(dialog.props.open).toBeTruthy();
});

it("doesn't displays TreeView when state says the tree is closed", async () => {
await renderDataEntry({ currentDomain: mockDomain, open: false });
const dialog = testHandle.root.findByProps({ id: treeViewDialogId });
expect(dialog.props.open).toBeFalsy;
expect(dialog.props.open).toBeFalsy();
});

it("dispatches to open the tree", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/PasswordReset/tests/ResetPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@ describe("PasswordReset", () => {
expect(screen.queryAllByTestId(id)).toHaveLength(0);
}
// The textId will show up as text because t() is mocked to return its input.
expect(screen.queryAllByText("passwordReset.invalidURL")).toBeTruthy;
expect(screen.queryAllByText("passwordReset.invalidURL")).toBeTruthy();
});
});
4 changes: 2 additions & 2 deletions src/components/ProjectSettings/tests/ProjectImport.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ const renderImport = async (): Promise<void> => {
describe("ProjectImport", () => {
it("upload button disabled when no file selected", async () => {
await renderImport();
expect(uploadButton.props.disabled).toBeTruthy;
expect(uploadButton.props.disabled).toBeTruthy();
});

it("upload button enabled when file selected", async () => {
await renderImport();
const selectButton = testRenderer.root.findByType(FileInputButton);
const mockFile = { name: "name-of-a.file" } as File;
await renderer.act(async () => selectButton.props.updateFile(mockFile));
expect(uploadButton.props.disabled).toBeFalsy;
expect(uploadButton.props.disabled).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ describe("ProjectSpeakersList", () => {
expect(testRenderer.root.findAllByType(SpeakerListItem)).toHaveLength(
mockSpeakers.length
);
expect(testRenderer.root.findByType(AddSpeakerListItem)).toBeTruthy;
expect(testRenderer.root.findByType(AddSpeakerListItem)).toBeTruthy();
});
});
1 change: 0 additions & 1 deletion src/components/ProjectUsers/tests/SortOptions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe("SortOptions", () => {
const mockReverse = jest.fn();
renderSortOptions({ onReverseClick: mockReverse });
const button = testRenderer.root.findByProps({ id: reverseButtonId });
expect(button).not.toBeNull();
button.props.onClick();
expect(mockReverse).toHaveBeenCalledTimes(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ describe("SpeakerConsentListItemIcon", () => {
...mockSpeaker,
consent: ConsentType.None,
});
expect(screen.queryByTestId(ListItemIconId.AddConsent)).not.toBeNull;
expect(screen.queryByTestId(ListItemIconId.PlayAudio)).toBeNull;
expect(screen.queryByTestId(ListItemIconId.ShowImage)).toBeNull;
expect(screen.queryByTestId(ListItemIconId.AddConsent)).not.toBeNull();
expect(screen.queryByTestId(ListItemIconId.PlayAudio)).toBeNull();
expect(screen.queryByTestId(ListItemIconId.ShowImage)).toBeNull();
});

it("opens menu when clicked", async () => {
Expand All @@ -77,14 +77,14 @@ describe("SpeakerConsentListItemIcon", () => {
...mockSpeaker,
consent: ConsentType.None,
});
expect(screen.queryByRole("menu")).toBeNull;
expect(screen.queryByTestId(ListItemIconId.RecordAudio)).toBeNull;
expect(screen.queryByTestId(ListItemIconId.UploadAudio)).toBeNull;
expect(screen.queryByRole("menu")).toBeNull();
expect(screen.queryByTestId(ListItemIconId.RecordAudio)).toBeNull();
expect(screen.queryByTestId(ListItemIconId.UploadAudio)).toBeNull();

await agent.click(screen.getByRole("button"));
expect(screen.queryByRole("menu")).not.toBeNull;
expect(screen.queryByTestId(ListItemIconId.RecordAudio)).not.toBeNull;
expect(screen.queryByTestId(ListItemIconId.UploadAudio)).not.toBeNull;
expect(screen.queryByRole("menu")).not.toBeNull();
expect(screen.queryByTestId(ListItemIconId.RecordAudio)).not.toBeNull();
expect(screen.queryByTestId(ListItemIconId.UploadAudio)).not.toBeNull();
});
});

Expand All @@ -94,9 +94,9 @@ describe("SpeakerConsentListItemIcon", () => {
...mockSpeaker,
consent: ConsentType.Audio,
});
expect(screen.queryByTestId(ListItemIconId.AddConsent)).toBeNull;
expect(screen.queryByTestId(ListItemIconId.PlayAudio)).not.toBeNull;
expect(screen.queryByTestId(ListItemIconId.ShowImage)).toBeNull;
expect(screen.queryByTestId(ListItemIconId.AddConsent)).toBeNull();
expect(screen.queryByTestId(ListItemIconId.PlayAudio)).not.toBeNull();
expect(screen.queryByTestId(ListItemIconId.ShowImage)).toBeNull();
});
});

Expand All @@ -106,9 +106,9 @@ describe("SpeakerConsentListItemIcon", () => {
...mockSpeaker,
consent: ConsentType.Image,
});
expect(screen.queryByTestId(ListItemIconId.AddConsent)).toBeNull;
expect(screen.queryByTestId(ListItemIconId.PlayAudio)).toBeNull;
expect(screen.queryByTestId(ListItemIconId.ShowImage)).not.toBeNull;
expect(screen.queryByTestId(ListItemIconId.AddConsent)).toBeNull();
expect(screen.queryByTestId(ListItemIconId.PlayAudio)).toBeNull();
expect(screen.queryByTestId(ListItemIconId.ShowImage)).not.toBeNull();
});

it("opens dialog when clicked", async () => {
Expand All @@ -117,10 +117,10 @@ describe("SpeakerConsentListItemIcon", () => {
...mockSpeaker,
consent: ConsentType.Image,
});
expect(screen.queryAllByRole("dialog")).toBeNull;
expect(screen.queryByRole("dialog")).toBeNull();

await agent.click(screen.getByRole("button"));
expect(screen.queryAllByRole("dialog")).not.toBeNull;
expect(screen.queryByRole("dialog")).not.toBeNull();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe("ReviewEntriesActions", () => {

// Verify the replacement word in state has the audio removed
const words = store.getState().reviewEntriesState.words;
expect(words.find((w) => w.id === wordId)).toBeNull;
expect(words.find((w) => w.id === wordId)).toBeUndefined();
const wordInState = words.find((w) => w.id === newId);
expect(wordInState?.audio).toHaveLength(0);
});
Expand Down Expand Up @@ -247,7 +247,7 @@ describe("ReviewEntriesActions", () => {

// Verify the replacement word in state has the updated speaker id
const words = store.getState().reviewEntriesState.words;
expect(words.find((w) => w.id === wordId)).toBeNull;
expect(words.find((w) => w.id === wordId)).toBeUndefined();
const audioInState = words.find((w) => w.id === newId)?.audio;
expect(audioInState).toHaveLength(1);
expect(audioInState![0].speakerId).toEqual(speakerId);
Expand Down Expand Up @@ -276,7 +276,7 @@ describe("ReviewEntriesActions", () => {

// Verify the replacement word in state has the audio added
const words = store.getState().reviewEntriesState.words;
expect(words.find((w) => w.id === wordId)).toBeNull;
expect(words.find((w) => w.id === wordId)).toBeUndefined();
const audioInState = words.find((w) => w.id === newId)?.audio;
expect(audioInState).toHaveLength(1);
expect(audioInState![0].fileName).toEqual(pro.fileName);
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/tests/dictionaryLoader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ describe("DictionaryLoader", () => {

it("loads nothing for empty or non-existent key", async () => {
const loader = new DictionaryLoader(bcp47);
expect(await loader.loadDictPart("")).toBeUndefined;
expect(await loader.loadDictPart("not-a-key")).toBeUndefined;
expect(await loader.loadDictPart("")).toBeUndefined();
expect(await loader.loadDictPart("not-a-key")).toBeUndefined();
});

it("doesn't load the same part more than once", async () => {
Expand Down

0 comments on commit 4979ed8

Please sign in to comment.