Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' into MAT-7854
Browse files Browse the repository at this point in the history
  • Loading branch information
adongare authored Oct 28, 2024
2 parents af8660d + 68e4bd2 commit 039bc7f
Show file tree
Hide file tree
Showing 5 changed files with 449 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ jest.mock("@madie/madie-util", () => ({
}),
}));

const adverseEventStructureDefinition = {
id: "AdverseEvent.actuality",
path: "AdverseEvent.actuality",
};
const codingDef = {
path: "Coding",
definition: { resourceType: "StructureDefinition", id: "Coding" },
Expand Down Expand Up @@ -63,6 +59,75 @@ useFhirDefinitionsServiceApiMock.mockImplementation(
);

describe("TypeEditor Component", () => {
test("Should render String component", () => {
const handleChange = jest.fn();
render(
<TypeEditor
type={`http://hl7.org/fhirpath/System.String`}
required={false}
value={`test string`}
onChange={handleChange}
structureDefinition={null}
/>
);
const inputField = screen.getByTestId("string-field-input-VALUE");
expect(inputField).toBeInTheDocument();
expect(inputField.value).toBe("test string");
});

test("Should render String component", () => {
const handleChange = jest.fn();
render(
<TypeEditor
type={`http://hl7.org/fhirpath/System.String`}
required={false}
value={`test string`}
onChange={handleChange}
structureDefinition={null}
/>
);
const inputField = screen.getByTestId("string-field-input-VALUE");
expect(inputField).toBeInTheDocument();
expect(inputField.value).toBe("test string");
});

test("Should render Period component", () => {
const handleChange = jest.fn();
render(
<TypeEditor
type={`Period`}
required={false}
value={null}
onChange={handleChange}
structureDefinition={null}
/>
);

expect(screen.getByText("start")).toBeInTheDocument();
expect(screen.getByText("End")).toBeInTheDocument();
});

test("Should render DateTime component", () => {
const handleChange = jest.fn();
render(
<TypeEditor
type={`http://hl7.org/fhirpath/System.DateTime`}
required={false}
value={`2024-09-26T08:33:33.000-05:00`}
onChange={handleChange}
structureDefinition={null}
/>
);
const inputDate = screen.getByTestId("date-field-input");
expect(inputDate).toBeInTheDocument();

const inputTime = screen.getByPlaceholderText("hh:mm:ss aa");
expect(inputTime).toBeInTheDocument();

const inputZone = screen.getByTestId("timezone-input-field-");
expect(inputZone).toBeInTheDocument();
});

test("Should render Boolean component", () => {
const handleChange = jest.fn();
render(
Expand Down Expand Up @@ -92,6 +157,7 @@ describe("TypeEditor Component", () => {
);
expect(screen.getByTestId("uri-input-field-URI")).toBeInTheDocument();
});

test("Should render Instant component by instant", () => {
const handleChange = jest.fn();
render(
Expand All @@ -118,4 +184,67 @@ describe("TypeEditor Component", () => {
);
expect(screen.getByTestId("instant-input")).toBeInTheDocument();
});

test("Should render Date component", () => {
const handleChange = jest.fn();
render(
<TypeEditor
type={`date`}
required={false}
value={`2024-09-26`}
onChange={handleChange}
structureDefinition={null}
/>
);

const inputField = screen.getByTestId("date-field--input");
expect(inputField).toBeInTheDocument();
expect(inputField.value).toBe("09/26/2024");
});

test("Should render PositiveInt component", () => {
const handleChange = jest.fn();
render(
<TypeEditor
type={`positiveInt`}
required={false}
value={`1234`}
onChange={handleChange}
structureDefinition={null}
/>
);
const inputField = screen.getByTestId("integer-field-input-");
expect(inputField).toBeInTheDocument();
expect(inputField.value).toBe("1234");
});

test("Should render unsignedInt component", () => {
const handleChange = jest.fn();
render(
<TypeEditor
type={`unsignedInt`}
required={false}
value={`1234`}
onChange={handleChange}
structureDefinition={null}
/>
);
const inputField = screen.getByTestId("integer-field-input-Integer Field");
expect(inputField).toBeInTheDocument();
expect(inputField.value).toBe("1234");
});

test("Should display unsupported", () => {
const handleChange = jest.fn();
render(
<TypeEditor
type={`test`}
required={false}
value={`test`}
onChange={handleChange}
structureDefinition={null}
/>
);
expect(screen.getByText(`Unsupported Type [test]`)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import DateTimeComponent from "./types/DateTimeComponent";
import BooleanComponent from "./types/BooleanComponent";
import UriComponent from "./types/UriComponent";
import DateComponent from "./types/DateComponent";
import IntegerComponent, { IntegerType } from "./types/IntegerComponent";
import CodesComponent from "./types/CodesComponent";
import { Instant } from "@madie/madie-design-system/dist/react";

Expand Down Expand Up @@ -113,6 +114,30 @@ const TypeEditor = ({
value={value}
/>
);
case "positiveInt":
return (
<IntegerComponent
canEdit={true}
structureDefinition={structureDefinition}
fieldRequired={required}
label={``}
onChange={onChange}
value={value}
integerType={IntegerType.POSITIVE_INT}
/>
);
case "unsignedInt":
return (
<IntegerComponent
canEdit={true}
structureDefinition={structureDefinition}
fieldRequired={required}
label={`Integer Field`}
onChange={onChange}
value={value}
integerType={IntegerType.UNSIGNED}
/>
);
case "code":
return (
<CodesComponent
Expand Down
Loading

0 comments on commit 039bc7f

Please sign in to comment.