-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(test) Add some missing test cases and improve typing in test files (#…
…1239) This PR improves test coverage and standardizes test descriptions across Core. Key changes include: - Adding coverage for missing test cases in the Devtools, Help Menu, and Implementer Tools test suites among others. - Standardizing test case descriptions across all modules. - Improving TypeScript types in test files. - Using `jest.mocked()` instead of direct type assertions for mocks as suggested in our [mocking patterns](https://o3-docs.openmrs.org/docs/frontend-modules/unit-and-integration-testing#mocking-patterns) guide. - Adding proper type annotations for mock data and responses - Cleaning up redundant type casts and improving mock implementations - Maintaining consistent naming conventions for mock variables (mock* prefix) - Adding missing type information to test utilities and helpers
- Loading branch information
1 parent
7269bbf
commit ccb94fb
Showing
47 changed files
with
943 additions
and
385 deletions.
There are no files selected for viewing
74 changes: 70 additions & 4 deletions
74
packages/apps/esm-devtools-app/src/devtools/devtools.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,75 @@ | ||
import React from 'react'; | ||
import '@testing-library/jest-dom'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { type AppProps } from 'single-spa'; | ||
import { render, screen } from '@testing-library/react'; | ||
import Root from './devtools.component'; | ||
import { render } from '@testing-library/react'; | ||
|
||
describe(`<Root />`, () => { | ||
it(`renders without dying`, () => { | ||
render(<Root />); | ||
jest.mock('./import-map.component', () => ({ | ||
__esModule: true, | ||
default: () => <div role="dialog">Mock Import Map</div>, | ||
importMapOverridden: false, | ||
})); | ||
|
||
const defaultProps: AppProps = { | ||
name: '@openmrs/esm-devtools-app-page-0', | ||
singleSpa: {}, | ||
mountParcel: jest.fn(), | ||
}; | ||
|
||
describe('DevTools', () => { | ||
beforeEach(() => { | ||
localStorage.clear(); | ||
delete window.spaEnv; | ||
jest.resetModules(); | ||
}); | ||
|
||
describe('Root component', () => { | ||
it('should not render DevTools in production without the devtools localStorage flag', () => { | ||
window.spaEnv = 'production'; | ||
|
||
const { container } = render(<Root {...defaultProps} />); | ||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
|
||
it('should render DevTools in development environments', () => { | ||
window.spaEnv = 'development'; | ||
|
||
render(<Root {...defaultProps} />); | ||
|
||
expect(screen.getByRole('button', { name: '{···}' })).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render DevTools when the devtools localStorage flag is set', () => { | ||
localStorage.setItem('openmrs:devtools', 'true'); | ||
|
||
render(<Root {...defaultProps} />); | ||
|
||
expect(screen.getByRole('button', { name: '{···}' })).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('DevTools component', () => { | ||
const user = userEvent.setup(); | ||
|
||
beforeEach(() => { | ||
window.spaEnv = 'development'; | ||
}); | ||
|
||
it('should toggle DevToolsPopup when clicking trigger button', async () => { | ||
render(<Root {...defaultProps} />); | ||
|
||
const triggerButton = screen.getByRole('button', { name: '{···}' }); | ||
// Initially, popup should not be present | ||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); | ||
|
||
// Click to open | ||
await user.click(triggerButton); | ||
expect(screen.getByRole('dialog')).toBeInTheDocument(); | ||
|
||
// Click to close | ||
await user.click(triggerButton); | ||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
6 changes: 4 additions & 2 deletions
6
packages/apps/esm-devtools-app/src/devtools/devtools.component.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
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
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
Oops, something went wrong.