From be2bf9c4f704d311e427dfd67e453426160b13e9 Mon Sep 17 00:00:00 2001 From: sb-cecilialiu Date: Fri, 27 Dec 2024 08:02:56 -0600 Subject: [PATCH 1/3] MAT-7676 Base64Binary component --- .../types/Base64BinaryComponent.test.tsx | 60 ++++++++++++++++++ .../element/types/Base64BinaryComponent.tsx | 61 +++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/types/Base64BinaryComponent.test.tsx create mode 100644 src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/types/Base64BinaryComponent.tsx diff --git a/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/types/Base64BinaryComponent.test.tsx b/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/types/Base64BinaryComponent.test.tsx new file mode 100644 index 00000000..d21addd0 --- /dev/null +++ b/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/types/Base64BinaryComponent.test.tsx @@ -0,0 +1,60 @@ +import * as React from "react"; +import { render, screen } from "@testing-library/react"; +import Base64BinaryComponent from "./Base64BinaryComponent"; +import userEvent from "@testing-library/user-event"; + +describe("Base64BinaryComponent", () => { + it("Should render Base64BinaryComponent", async () => { + const handleChange = jest.fn(); + + render( + + ); + + expect(screen.getByText("Base64BinaryComponent")).toBeInTheDocument(); + expect( + screen.getByTestId("field-input-Base64BinaryComponent") + ).toBeInTheDocument(); + }); + + it("Should validate input", async () => { + const handleChange = jest.fn(); + + render( + + ); + + const base64BinaryInput = screen.getByTestId( + "field-input-Base64BinaryComponent" + ) as HTMLInputElement; + + // valid base64BinaryInput + userEvent.type(base64BinaryInput, "abcd"); + expect(base64BinaryInput.value).toBe("abcd"); + expect( + screen.getByTestId("field-input-helper-text-Base64BinaryComponent") + ).toBeEmptyDOMElement(); + + // invalid base64BinaryInput + userEvent.clear(base64BinaryInput); + userEvent.type(base64BinaryInput, "invalid base64BinaryInput."); + expect(base64BinaryInput).toHaveValue("invalid base64BinaryInput."); + expect( + screen.getByTestId("field-input-helper-text-Base64BinaryComponent") + ).toHaveTextContent("Please enter a valid Base64Binary"); + }); +}); diff --git a/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/types/Base64BinaryComponent.tsx b/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/types/Base64BinaryComponent.tsx new file mode 100644 index 00000000..e862f2db --- /dev/null +++ b/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/types/Base64BinaryComponent.tsx @@ -0,0 +1,61 @@ +import React, { useState } from "react"; +import { FormHelperText } from "@mui/material"; +import { TypeComponentProps } from "./TypeComponentProps"; +import { TextField } from "@madie/madie-design-system/dist/react"; +import _ from "lodash"; + +const isBase64 = (str) => { + try { + const decoded = atob(str); + return decoded && new RegExp(/(\s*([0-9a-zA-Z\+\=]){4}\s*)+/).test(str); + } catch (err) { + return false; + } +}; + +const Base64BinaryComponent = ({ + canEdit, + fieldRequired, + label = "Base64Binary", + value, + onChange, + structureDefinition, +}: TypeComponentProps) => { + const [isValid, setValid] = useState(value ? isBase64(value) : true); + + const handleChange = (base64BinaryString) => { + setValid(true); + if (isBase64(base64BinaryString)) { + onChange(base64BinaryString); + } else if (!_.isEmpty(base64BinaryString)) { + setValid(false); + } + }; + return ( + handleChange(e.target.value)} + helperText={ + + {isValid ? "" : "Please enter a valid Base64Binary"} + + } + /> + ); +}; + +export default Base64BinaryComponent; From a15c45b953de26aa78ec1cc858d6cd63d205ca2f Mon Sep 17 00:00:00 2001 From: adongare Date: Fri, 27 Dec 2024 09:13:51 -0500 Subject: [PATCH 2/3] MAT-7675 Test Case Builder Component - Canonical --- .../api/useFhirDefinitionsService.ts | 1 + .../builder/element/TypeEditor.test.tsx | 19 +++++++++++++++++++ .../builder/element/TypeEditor.tsx | 1 + 3 files changed, 21 insertions(+) diff --git a/src/components/editMeasure/testCases/api/useFhirDefinitionsService.ts b/src/components/editMeasure/testCases/api/useFhirDefinitionsService.ts index b4486281..5e97e155 100644 --- a/src/components/editMeasure/testCases/api/useFhirDefinitionsService.ts +++ b/src/components/editMeasure/testCases/api/useFhirDefinitionsService.ts @@ -25,6 +25,7 @@ export class FhirDefinitionsServiceApi { case "uri": case "url": case "uuid": + case "canonical": case "string": case "http://hl7.org/fhirpath/System.String": case "code": diff --git a/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/TypeEditor.test.tsx b/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/TypeEditor.test.tsx index 27e3e26c..89e5cae2 100644 --- a/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/TypeEditor.test.tsx +++ b/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/TypeEditor.test.tsx @@ -172,6 +172,25 @@ describe("TypeEditor Component", () => { expect(screen.getByTestId("url-input-field-URL")).toBeInTheDocument(); }); + test("Should render canonical uri type attribute", () => { + const handleChange = jest.fn(); + const canonicalUri = "https://example.com/blog"; + render( + + ); + expect(screen.getByTestId("url-input-field-instantiatesUri")).toHaveValue( + canonicalUri + ); + }); + test("Should render Instant component by instant", () => { const handleChange = jest.fn(); render( diff --git a/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/TypeEditor.tsx b/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/TypeEditor.tsx index 20e76e0c..6934c2a4 100644 --- a/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/TypeEditor.tsx +++ b/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/TypeEditor.tsx @@ -106,6 +106,7 @@ const TypeEditor = ({ /> ); case "url": + case "canonical": return ( Date: Fri, 27 Dec 2024 09:18:28 -0500 Subject: [PATCH 3/3] MAT-7675 update testcase --- .../ElementsTab/builder/element/TypeEditor.test.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/TypeEditor.test.tsx b/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/TypeEditor.test.tsx index 89e5cae2..adc38c49 100644 --- a/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/TypeEditor.test.tsx +++ b/src/components/editMeasure/testCases/components/editTestCase/qiCore/LeftPanel/ElementsTab/builder/element/TypeEditor.test.tsx @@ -172,7 +172,7 @@ describe("TypeEditor Component", () => { expect(screen.getByTestId("url-input-field-URL")).toBeInTheDocument(); }); - test("Should render canonical uri type attribute", () => { + test("Should render canonical url type attribute", () => { const handleChange = jest.fn(); const canonicalUri = "https://example.com/blog"; render( @@ -183,12 +183,12 @@ describe("TypeEditor Component", () => { onChange={handleChange} structureDefinition={null} canEdit={true} - label="instantiatesUri" + label="instantiatesCanonical" /> ); - expect(screen.getByTestId("url-input-field-instantiatesUri")).toHaveValue( - canonicalUri - ); + expect( + screen.getByTestId("url-input-field-instantiatesCanonical") + ).toHaveValue(canonicalUri); }); test("Should render Instant component by instant", () => {