generated from openmrs/openmrs-esm-template-app
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
O3-2501:Write unit tests to test the components
- Loading branch information
Showing
11 changed files
with
1,138 additions
and
145 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
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,76 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import "@testing-library/jest-dom"; | ||
import SvgEditor from './custom-annotate.component'; | ||
import { isElementInDocument } from '../test-utils'; | ||
|
||
describe('SvgEditor Component', () => { | ||
it('renders the SvgEditor component', () => { | ||
const { container } = render(<SvgEditor />); | ||
const canvasContainer = container.querySelector('.canvas-container'); | ||
expect(isElementInDocument(canvasContainer)).toBe(true); | ||
}); | ||
|
||
it('can add a shape to the canvas', () => { | ||
const { getByText } = render(<SvgEditor />); | ||
const addShapeButton = getByText('Add Shape'); | ||
fireEvent.click(addShapeButton); | ||
}); | ||
|
||
it('can select drawing mode', () => { | ||
const { getByText } = render(<SvgEditor />); | ||
const freehandButton = getByText('Freehand'); | ||
fireEvent.click(freehandButton); | ||
}); | ||
|
||
it('can add text to the canvas', () => { | ||
const { getByText } = render(<SvgEditor />); | ||
const addTextButton = getByText('Add Text'); | ||
fireEvent.click(addTextButton); | ||
}); | ||
|
||
it('can change the color of an object on the canvas', () => { | ||
const { getByText, container } = render(<SvgEditor />); | ||
const addShapeButton = getByText('Add Shape'); | ||
fireEvent.click(addShapeButton); | ||
|
||
const colorPicker = container.querySelector('input[type="color"]'); | ||
fireEvent.change(colorPicker, { target: { value: '#ff0000' } }); | ||
|
||
}); | ||
|
||
it('can undo and redo actions', () => { | ||
const { getByText } = render(<SvgEditor />); | ||
const addShapeButton = getByText('Add Shape'); | ||
fireEvent.click(addShapeButton); | ||
|
||
const undoButton = getByText('Undo'); | ||
const redoButton = getByText('Redo'); | ||
|
||
// Perform actions that can be undone and redone | ||
fireEvent.click(undoButton); | ||
// You can add assertions to check if the action is undone. | ||
|
||
fireEvent.click(redoButton); | ||
// You can add assertions to check if the action is redone. | ||
}); | ||
|
||
it('can upload an image', () => { | ||
const { getByLabelText } = render(<SvgEditor />); | ||
const fileInput = getByLabelText('Upload Image'); | ||
|
||
// You can simulate uploading an image using fireEvent.change | ||
// and then add assertions to check if the image is loaded and displayed. | ||
}); | ||
|
||
it('can save an annotated image', () => { | ||
const { getByText } = render(<SvgEditor />); | ||
const addShapeButton = getByText('Add Shape'); | ||
fireEvent.click(addShapeButton); | ||
|
||
const saveButton = getByText('Save'); | ||
|
||
// Perform actions to create an annotated image | ||
// Then, click the "Save" button and add assertions to check if the image is saved. | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
@use '@carbon/styles/scss/spacing'; | ||
@use '@carbon/styles/scss/type'; | ||
@import 'carbon-components/css/carbon-components.css'; | ||
@import '~@openmrs/esm-styleguide/src/vars'; | ||
|
||
.text { | ||
font-size: 0.9rem; | ||
padding: 0.5rem; | ||
} | ||
.container { | ||
padding: 1.5rem; | ||
background: $ui-01; | ||
} | ||
|
||
div.bx--tab-content { | ||
padding: 0 !important; | ||
} |
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,24 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { isElementInDocument } from './test-utils'; | ||
import DrawPage from './draw-page.component'; | ||
|
||
jest.mock('./components/custom-annotate.component', () => { | ||
return () => <div data-testid="mock-svg-editor" />; | ||
}); | ||
|
||
describe('DrawPage Component', () => { | ||
it('renders the DrawPage component', () => { | ||
const { container } = render(<DrawPage />); | ||
const editorContainer = container.querySelector('.editor-container'); | ||
|
||
expect(isElementInDocument(editorContainer as HTMLElement)).toBe(true); | ||
}); | ||
|
||
it('renders the SvgEditor component within the DrawPage', () => { | ||
const { getByTestId } = render(<DrawPage />); | ||
const svgEditor = getByTestId('mock-svg-editor'); | ||
|
||
expect(isElementInDocument(svgEditor as HTMLElement)).toBe(true); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
export function isElementInDocument(element: Element): boolean { | ||
return document.body.contains(element); | ||
} |
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 @@ | ||
import "@testing-library/jest-dom"; |
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.