Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec committed Feb 15, 2024
1 parent 11db41e commit 8062beb
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/components/ProjectSettings/ProjectImport.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Grid, Typography } from "@mui/material";
import { ReactElement, useState } from "react";
import { type ReactElement, useState } from "react";
import { Trans, useTranslation } from "react-i18next";

import { getProject, uploadLift } from "backend";
import { FileInputButton, LoadingDoneButton } from "components/Buttons";
import { ProjectSettingProps } from "components/ProjectSettings/ProjectSettingsTypes";
import { type ProjectSettingProps } from "components/ProjectSettings/ProjectSettingsTypes";

enum UploadState {
Awaiting,
Expand Down
6 changes: 3 additions & 3 deletions src/components/ProjectSettings/ProjectLanguages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import {
Typography,
} from "@mui/material";
import { LanguagePicker, languagePickerStrings_en } from "mui-language-picker";
import { Fragment, ReactElement, useEffect, useState } from "react";
import { Fragment, type ReactElement, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { toast } from "react-toastify";

import { WritingSystem } from "api/models";
import { type WritingSystem } from "api/models";
import { getFrontierWords } from "backend";
import { IconButtonWithTooltip } from "components/Buttons";
import { ProjectSettingProps } from "components/ProjectSettings/ProjectSettingsTypes";
import { type ProjectSettingProps } from "components/ProjectSettings/ProjectSettingsTypes";
import theme from "types/theme";
import { newWritingSystem, semDomWritingSystems } from "types/writingSystem";
import { getAnalysisLangsFromWords } from "utilities/wordUtilities";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, IconButton } from "@mui/material";
import { type ReactTestRenderer, act, create } from "react-test-renderer";
import renderer from "react-test-renderer";

import "tests/reactI18nextMock";

Expand All @@ -9,7 +9,7 @@ import { newProject } from "types/project";

const mockSetProject = jest.fn();

let projectMaster: ReactTestRenderer;
let projectMaster: renderer.ReactTestRenderer;

function mockProject(sched?: string[]): Project {
return { ...newProject(), workshopSchedule: sched ?? [] };
Expand All @@ -20,8 +20,8 @@ const renderProjSched = async (
readOnly = false
): Promise<void> => {
mockSetProject.mockResolvedValue(undefined);
await act(async () => {
projectMaster = create(
await renderer.act(async () => {
projectMaster = renderer.create(
<ProjectSchedule
project={project}
readOnly={readOnly}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Select } from "@mui/material";
import { type ReactTestRenderer, act, create } from "react-test-renderer";
import renderer from "react-test-renderer";

import "tests/reactI18nextMock";

Expand All @@ -11,11 +11,11 @@ const mockSetProject = jest.fn();

const mockProject = randomProject();

let testRenderer: ReactTestRenderer;
let testRenderer: renderer.ReactTestRenderer;

const renderAutocomplete = async (): Promise<void> => {
await act(async () => {
testRenderer = create(
await renderer.act(async () => {
testRenderer = renderer.create(
<ProjectAutocomplete project={mockProject} setProject={mockSetProject} />
);
});
Expand All @@ -25,12 +25,12 @@ describe("ProjectAutocomplete", () => {
it("updates project autocomplete", async () => {
await renderAutocomplete();
const selectChange = testRenderer.root.findByType(Select).props.onChange;
await act(async () => selectChange({ target: { value: "Off" } }));
await renderer.act(async () => selectChange({ target: { value: "Off" } }));
expect(mockSetProject).toHaveBeenCalledWith({
...mockProject,
autocompleteSetting: AutocompleteSetting.Off,
});
await act(async () => selectChange({ target: { value: "On" } }));
await renderer.act(async () => selectChange({ target: { value: "On" } }));
expect(mockSetProject).toHaveBeenCalledWith({
...mockProject,
autocompleteSetting: AutocompleteSetting.On,
Expand Down
16 changes: 8 additions & 8 deletions src/components/ProjectSettings/tests/ProjectName.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, TextField } from "@mui/material";
import { type ReactTestRenderer, act, create } from "react-test-renderer";
import renderer from "react-test-renderer";

import "tests/reactI18nextMock";

Expand All @@ -16,11 +16,11 @@ const mockSetProject = jest.fn();

const mockProject = randomProject();

let testRenderer: ReactTestRenderer;
let testRenderer: renderer.ReactTestRenderer;

const renderName = async (): Promise<void> => {
await act(async () => {
testRenderer = create(
await renderer.act(async () => {
testRenderer = renderer.create(
<ProjectName project={mockProject} setProject={mockSetProject} />
);
});
Expand All @@ -33,23 +33,23 @@ describe("ProjectName", () => {
const saveButton = testRenderer.root.findByType(Button);
const name = "new-project-name";
mockSetProject.mockResolvedValueOnce({});
await act(async () =>
await renderer.act(async () =>
textField.props.onChange({ target: { value: name } })
);
await act(async () => saveButton.props.onClick());
await renderer.act(async () => saveButton.props.onClick());
expect(mockSetProject).toHaveBeenCalledWith({ ...mockProject, name });
});

it("toasts on error", async () => {
await renderName();
const textField = testRenderer.root.findByType(TextField);
const saveButton = testRenderer.root.findByType(Button);
await act(async () =>
await renderer.act(async () =>
textField.props.onChange({ target: { value: "new-name" } })
);
mockSetProject.mockRejectedValueOnce({});
expect(mockToastError).not.toHaveBeenCalled();
await act(async () => saveButton.props.onClick());
await renderer.act(async () => saveButton.props.onClick());
expect(mockToastError).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Select } from "@mui/material";
import { type ReactTestRenderer, act, create } from "react-test-renderer";
import { ReactTestRenderer, act, create } from "react-test-renderer";

import ProjectSelect from "components/ProjectSettings/ProjectSelect";
import { newProject, randomProject } from "types/project";
Expand Down
21 changes: 10 additions & 11 deletions src/goals/MergeDuplicates/MergeDupsStep/SenseCardContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
GramCatGroup,
type ProtectReason,
ReasonType,
type SemanticDomain,
type Sense,
Status,
} from "api/models";
Expand All @@ -23,10 +24,10 @@ interface SenseCardContentProps {
toggleFunction?: () => void;
}

// Only show first sense's glosses/definitions; in merging, others deleted as duplicates.
// Show first part of speech, if any.
// Show semantic domains from all senses.
// In merging, user can select a different one by reordering in the sidebar.
/** Only show first sense's glosses, definitions, and part of speech.
* In merging, others deleted as duplicates;
* user can select a different first sense by reordering in the sidebar.
* Show semantic domains from all senses. */
export default function SenseCardContent(
props: SenseCardContentProps
): ReactElement {
Expand All @@ -35,18 +36,16 @@ export default function SenseCardContent(
);
const { t } = useTranslation();

const getName = (id: string): string | undefined => {
if (semDomNames) {
return semDomNames[id];
}
/** Get the domain name in the project's sem dom language;
* if not available, fall back to the given domain's name. */
const getName = (dom: SemanticDomain): string | undefined => {
return semDomNames ? semDomNames[dom.id] ?? dom.name : dom.name;
};

const semDoms = [
...new Set(
props.senses.flatMap((s) =>
s.semanticDomains.map(
(dom) => `${dom.id}: ${getName(dom.id) ?? dom.name}`
)
s.semanticDomains.map((dom) => `${dom.id}: ${getName(dom)}`)
)
),
];
Expand Down

0 comments on commit 8062beb

Please sign in to comment.