generated from openmrs/openmrs-esm-template-app
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(tests) O3-4097 Add tests for rendering a dummy schema (#13)
- Loading branch information
1 parent
3d76a7a
commit e27909a
Showing
15 changed files
with
155 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,22 @@ | ||
/** | ||
* @returns {Promise<import('jest').Config>} | ||
*/ | ||
const path = require('path'); | ||
|
||
/** @type {import('jest').Config} */ | ||
module.exports = { | ||
collectCoverageFrom: [ | ||
'**/src/**/*.component.tsx', | ||
'!**/node_modules/**', | ||
'!**/vendor/**', | ||
'!**/src/**/*.test.*', | ||
'!**/src/declarations.d.ts', | ||
'!**/e2e/**', | ||
], | ||
clearMocks: true, | ||
transform: { | ||
'^.+\\.tsx?$': ['@swc/jest'], | ||
}, | ||
transformIgnorePatterns: ['/node_modules/(?!@openmrs)'], | ||
moduleNameMapper: { | ||
'@openmrs/esm-framework': '@openmrs/esm-framework/mock', | ||
'@openmrs/esm-utils': '@openmrs/esm-framework/mock', | ||
'\\.(s?css)$': 'identity-obj-proxy', | ||
'^lodash-es/(.*)$': 'lodash/$1', | ||
'lodash-es': 'lodash', | ||
'^dexie$': require.resolve('dexie'), | ||
'^@testing-library/jest-dom/extend-expect$': '@testing-library/jest-dom', | ||
}, | ||
moduleNameMapper: { | ||
'^@carbon/icons-react/es/(.*)$': '@carbon/icons-react/lib/$1', | ||
'^carbon-components-react/es/(.*)$': 'carbon-components-react/lib/$1', | ||
'@openmrs/esm-framework': '@openmrs/esm-framework/mock', | ||
'\\.(s?css)$': 'identity-obj-proxy', | ||
'^lodash-es/(.*)$': 'lodash/$1', | ||
'lodash-es': 'lodash', | ||
'^dexie$': '<rootDir>/node_modules/dexie', | ||
'^react-i18next$': '<rootDir>/__mocks__/react-i18next.js', | ||
'ace-builds': '<rootDir>/node_modules/ace-builds', | ||
}, | ||
setupFilesAfterEnv: ['<rootDir>/src/setup-tests.ts'], | ||
testPathIgnorePatterns: [path.resolve(__dirname, 'e2e')], | ||
testEnvironment: 'jsdom', | ||
testEnvironmentOptions: { | ||
url: 'http://localhost/', | ||
}, | ||
testPathIgnorePatterns: ['<rootDir>/e2e'], | ||
}; |
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
2 changes: 1 addition & 1 deletion
2
src/components/interactive-builder/add-columns-modal.component.test.tsx
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
2 changes: 1 addition & 1 deletion
2
src/components/interactive-builder/add-package-modal.component.test.tsx
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
2 changes: 1 addition & 1 deletion
2
src/components/interactive-builder/add-submenu-modal.component.test.tsx
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
2 changes: 1 addition & 1 deletion
2
src/components/interactive-builder/configure-dashboard-modal.component.test.tsx
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
2 changes: 1 addition & 1 deletion
2
src/components/interactive-builder/delete-config-detail-modal.component.test.tsx
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
2 changes: 1 addition & 1 deletion
2
src/components/interactive-builder/interactive-builder.component.test.tsx
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,54 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { ContentPackagesEditorContent } from './view-editor.component'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
jest.mock('react-i18next', () => ({ | ||
useTranslation: () => ({ | ||
t: (key) => key, | ||
}), | ||
})); | ||
|
||
beforeEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
||
describe('ContentPackagesEditorContent', () => { | ||
it('renders correctly and allows inputting dummy schema', async () => { | ||
render( | ||
<MemoryRouter initialEntries={['/clinical-views-builder/new']}> | ||
<ContentPackagesEditorContent t={(key) => key} /> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(screen.getByText('schemaEditor')).toBeInTheDocument(); | ||
const importSchemaButtons = screen.queryAllByText(/importSchema/i); | ||
expect(importSchemaButtons.length).toBeGreaterThan(0); | ||
expect(screen.getByText(/inputDummySchema/i)).toBeInTheDocument(); | ||
|
||
await userEvent.click(screen.getByText(/inputDummySchema/i)); | ||
|
||
expect(screen.getByText(/interactiveBuilderInfo/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Package One/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/clinicalViewMenus/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/First Menu/i)).toBeInTheDocument(); | ||
await userEvent.click(screen.getByRole('button', { name: /First Menu/i })); | ||
expect(screen.getByText(/menuSlot\s*:\s*first-menu-slot/i)).toBeInTheDocument(); | ||
const firstHelperText = screen.getAllByText(/helperTextForAddDasboards/i)[0]; | ||
expect(firstHelperText).toBeInTheDocument(); | ||
|
||
const firstConfigureButton = screen.getAllByRole('button', { name: /configureDashboard/i })[0]; | ||
expect(firstConfigureButton).toBeInTheDocument(); | ||
expect(screen.getByText(/Second Menu/i)).toBeInTheDocument(); | ||
|
||
await userEvent.click(screen.getByRole('button', { name: /Second Menu/i })); | ||
expect(screen.getByText(/menuSlot\s*:\s*second-menu-slot/i)).toBeInTheDocument(); | ||
const secondHelperText = screen.getAllByText(/helperTextForAddDasboards/i)[1]; | ||
expect(secondHelperText).toBeInTheDocument(); | ||
|
||
const secondConfigureButton = screen.getAllByRole('button', { name: /configureDashboard/i })[1]; | ||
expect(secondConfigureButton).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: /addClinicalViewSubMenu/i })).toBeInTheDocument(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1 +1,9 @@ | ||
import '@testing-library/jest-dom'; | ||
|
||
window.URL.createObjectURL = jest.fn(); | ||
window.openmrsBase = '/openmrs'; | ||
window.spaBase = '/spa'; | ||
window.getOpenmrsSpaBase = () => '/openmrs/spa/'; | ||
|
||
// https://github.com/jsdom/jsdom/issues/1695 | ||
window.HTMLElement.prototype.scrollIntoView = function () {}; |
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,30 @@ | ||
import React from 'react'; | ||
import { SWRConfig } from 'swr'; | ||
import { type RenderOptions, render, screen, waitForElementToBeRemoved } from '@testing-library/react'; | ||
|
||
// This component wraps whatever component is passed to it with an SWRConfig context which provides a global configuration for all SWR hooks. | ||
const swrWrapper = ({ children }: { children: React.ReactNode }) => { | ||
return ( | ||
<SWRConfig | ||
value={{ | ||
// Sets the `dedupingInterval` to 0 - we don't need to dedupe requests in our test environment. | ||
dedupingInterval: 0, | ||
// Returns a new Map object, effectively wrapping our application with an empty cache provider. This is useful for resetting the SWR cache between test cases. | ||
provider: () => new Map(), | ||
}} | ||
> | ||
{children} | ||
</SWRConfig> | ||
); | ||
}; | ||
|
||
// Render the provided component within the wrapper we created above | ||
export const renderWithSwr = (ui: React.ReactElement, options?: RenderOptions) => | ||
render(ui, { wrapper: swrWrapper, ...options }); | ||
|
||
// Helper function that waits for a loading state to disappear from the screen | ||
export function waitForLoadingToFinish() { | ||
return waitForElementToBeRemoved(() => [...screen.queryAllByRole('progressbar')], { | ||
timeout: 4000, | ||
}); | ||
} |
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 +1,10 @@ | ||
module.exports = require('openmrs/default-webpack-config'); | ||
const config = (module.exports = require('openmrs/default-webpack-config')); | ||
config.scriptRuleConfig.exclude = /(node_modules(?![/\\]@(?:openmrs|ohri)))/; | ||
config.overrides.resolve = { | ||
extensions: ['.tsx', '.ts', '.jsx', '.js', '.scss', '.json'], | ||
alias: { | ||
'@openmrs/esm-framework': '@openmrs/esm-framework/src/internal', | ||
'@openmrs/esm-form-engine-lib': '@openmrs/esm-form-engine-lib/src/index', | ||
}, | ||
}; | ||
module.exports = config; |
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