-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add ui tests with rtl, jest and msw
- Loading branch information
Showing
18 changed files
with
5,552 additions
and
1,493 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 |
---|---|---|
|
@@ -18,6 +18,20 @@ jobs: | |
- run: yarn install --frozen-lockfile | ||
- id: lint | ||
run: yarn lint | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
cache: 'yarn' | ||
- run: yarn install --frozen-lockfile | ||
- run: yarn test:client --coverage | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
lint-pr-title: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
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 |
---|---|---|
|
@@ -17,4 +17,5 @@ build/ | |
cypress.env.json | ||
|
||
# ignore tools download cache | ||
tools/apps | ||
tools/apps | ||
coverage/ |
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,7 @@ | ||
import '@testing-library/jest-dom' | ||
import { configure } from '@testing-library/dom' | ||
const util = require('util') | ||
const { TextEncoder, TextDecoder } = util | ||
Object.assign(global, { TextDecoder, TextEncoder }) | ||
|
||
configure({ testIdAttribute: 'data-test' }) |
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,19 @@ | ||
/** @type {import('jest').Config} */ | ||
const config = { | ||
verbose: true, | ||
testEnvironment: 'jest-fixed-jsdom', | ||
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'], | ||
|
||
moduleNameMapper: { | ||
'@dhis2/app-runtime': '<rootDir>/app-runtime-mock.js', | ||
'react-markdown': '<rootDir>/test/mocks/react-markdown-mock.js', | ||
'@react-hook': '<rootDir>/app-runtime-mock.js', | ||
'\\.(jpg|jpeg|png|gif|webp|svg)$': 'identity-obj-proxy', | ||
'\\.(css|scss)$': 'identity-obj-proxy', | ||
'^src(.*)$': '<rootDir>/src$1', | ||
'^config(.*)$': '<rootDir>/config$1', | ||
'^mocks(.*)$': '<rootDir>/test/mocks$1', | ||
}, | ||
} | ||
|
||
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
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,58 @@ | ||
import { render } from '@testing-library/react' | ||
import AppView from './AppView.js' | ||
import '../../../test/mocks/setup.js' | ||
|
||
describe('AppView', () => { | ||
it('should render app details', async () => { | ||
const appId = '08c48425-abd3-410e-8802-8f9ada971c03' | ||
|
||
const { findByText, getByTestId } = render( | ||
<AppView | ||
match={{ | ||
params: { appId }, | ||
}} | ||
/> | ||
) | ||
|
||
await findByText('ADEx Flow') | ||
|
||
// check organisation link | ||
const organisationLink = getByTestId('organisation-link') | ||
expect(organisationLink).toHaveTextContent( | ||
'DHIS2 Global Implementation Team' | ||
) | ||
expect(organisationLink).toHaveAttribute( | ||
'href', | ||
'/organisation/dhis2-global-implementation-team/view' | ||
) | ||
|
||
expect(getByTestId('app-type')).toHaveTextContent('Application') | ||
|
||
// Check the buttons | ||
const downloadButton = getByTestId('button-download-latest-version') | ||
expect(downloadButton).toHaveTextContent('Download latest version') | ||
expect(downloadButton.getAttribute('href')).toMatch( | ||
'api/v1/apps/download/dhis2-global-implementation-team/adex-flow_0.1.5.zip' | ||
) | ||
|
||
// latest version description | ||
expect(getByTestId('latest-version-description')).toHaveTextContent( | ||
`Stable release v0.1.5.Compatible with DHIS2 2.39 and above.` | ||
) | ||
|
||
// app description | ||
expect(getByTestId('app-description')).toHaveTextContent( | ||
'The Global Fund ADEX Flow app provides a series of workflows to assist country teams with the management of Global Fund Related ADEX metadata.The app provides a series of pre-defined workflows:' | ||
) | ||
|
||
const sourceCodeLink = getByTestId('link-source-code') | ||
expect(sourceCodeLink.getAttribute('href')).toEqual( | ||
'https://github.com/dhis2/gf-adex-flow-app' | ||
) | ||
expect(sourceCodeLink).toHaveTextContent('Source code') | ||
|
||
expect(getByTestId('tabbar-appview')).toHaveTextContent( | ||
'About' + 'Previous releases' + 'Change log' | ||
) | ||
}) | ||
}) |
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,28 @@ | ||
import { render } from '@testing-library/react' | ||
import '../../../test/mocks/setup.js' | ||
import { Router, Route } from 'react-router-dom' | ||
import { QueryParamProvider } from 'use-query-params' | ||
import { history } from '../../utils/history' | ||
import Apps from './Apps.js' | ||
|
||
describe('Apps list (Homepage)', () => { | ||
it('should render all app cards', async () => { | ||
const { findByText, getAllByTestId } = render( | ||
<Router history={history}> | ||
<QueryParamProvider | ||
ReactRouterRoute={Route} | ||
stringifyOptions={{ skipEmptyString: true }} | ||
> | ||
<Apps /> | ||
</QueryParamProvider> | ||
</Router> | ||
) | ||
|
||
await findByText('Analytics Info') | ||
expect(getAllByTestId('appcard').length).toEqual(24) | ||
expect(getAllByTestId('appcard-name').length).toEqual(24) | ||
expect(getAllByTestId('appcard-organisation').length).toEqual(24) | ||
|
||
expect(getAllByTestId('appcard-description').length).toEqual(24) | ||
}) | ||
}) |
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.