-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Local micro-frontend setup for alergies UI (#644)
* Introduce a generic react micro-frontend for next gen ui and add sample code * Simplify micro-frontend build by pulling polyfill into shared.min.js * Fix test failures on adding new micro-frontend * Add jest setup for mico-frontends * Add a linter to the micro-frontend code * Update the pipelines to support the new tools for micro-frontends
- Loading branch information
1 parent
402f1b0
commit a5043c6
Showing
22 changed files
with
2,028 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module.exports = { | ||
root: true, | ||
ignorePatterns: [ | ||
"node_modules/*", | ||
"*.config.js", | ||
".*", | ||
"**/__mocks__/*", | ||
"src/setupTests.js", | ||
], | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
extends: ["eslint:recommended", "plugin:react/recommended", "prettier"], | ||
parserOptions: { | ||
ecmaVersion: "latest", | ||
sourceType: "module", | ||
}, | ||
plugins: ["react"], | ||
rules: {}, | ||
settings: { | ||
react: { | ||
version: "detect", | ||
}, | ||
}, | ||
globals: { | ||
angular: "readonly", | ||
}, | ||
overrides: [ | ||
{ | ||
files: ["*.spec.js", "*.spec.jsx"], | ||
plugins: ["jest"], | ||
extends: ["plugin:jest/recommended"], | ||
rules: {}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
testEnvironment: "jsdom", | ||
moduleNameMapper: { | ||
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": | ||
"<rootDir>/src/__mocks__/fileMock.js", | ||
"\\.(css|scss|sass)$": "<rootDir>/src/__mocks__/styleMock.js", | ||
}, | ||
setupFilesAfterEnv: ["<rootDir>/src/setupTests.js"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = "test-file-stub"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { react2angular } from "react2angular"; | ||
import { PatientAlergiesControl } from "./patientAlergies/PatientAlergiesControl"; | ||
|
||
const moduleName = "bahmni.mfe.nextUi"; | ||
angular.module(moduleName, []); | ||
|
||
angular | ||
.module(moduleName) | ||
.component("mfeNextUiPatientAlergiesControl", react2angular(PatientAlergiesControl)); |
26 changes: 26 additions & 0 deletions
26
micro-frontends/src/next-ui/patientAlergies/PatientAlergiesControl.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Button } from 'carbon-components-react'; | ||
|
||
/** NOTE: for reasons known only to react2angular, | ||
* any function nested inside one of the prop objects will be undefined at first and then later load up | ||
* so you need to use the conditional operator like props.hostApi?.callback even though it is a mandatory prop | ||
*/ | ||
|
||
export function PatientAlergiesControl(props) { | ||
return ( | ||
<div> | ||
<span>Displaying alergy control from {props.hostData.name}</span> | ||
<Button onClick={props.hostApi?.callback}>Click for callback</Button> | ||
</div> | ||
); | ||
} | ||
|
||
PatientAlergiesControl.propTypes = { | ||
hostData: PropTypes.shape({ | ||
name: PropTypes.string.isRequired, | ||
}), | ||
hostApi: PropTypes.shape({ | ||
callback: PropTypes.func.isRequired, | ||
}), | ||
}; |
18 changes: 18 additions & 0 deletions
18
micro-frontends/src/next-ui/patientAlergies/PatientAlergiesControl.spec.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import { PatientAlergiesControl } from "./PatientAlergiesControl"; | ||
|
||
it("works as a dummy test", () => { | ||
const hostData = { name: "__test_name__" }; | ||
const hostApi = { callback: jest.fn() }; | ||
render(<PatientAlergiesControl hostData={hostData} hostApi={hostApi}/>); | ||
|
||
expect(screen.getByText('Displaying alergy control from __test_name__')).toBeTruthy(); | ||
|
||
const button = screen.getByRole('button', { name: 'Click for callback' }); | ||
expect(button).toBeTruthy(); | ||
fireEvent.click(button); | ||
|
||
expect(hostApi.callback).toHaveBeenCalled(); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// mock the fetch global using jest | ||
require("jest-fetch-mock").enableMocks(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// polyfill the angular.module.component function for angular v1.4 | ||
import 'angular-component'; | ||
|
||
// import the carbon-ui's stylesheet | ||
import "bahmni-carbon-ui/styles.css"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.