Skip to content

Commit

Permalink
fix: manual updates for react/vite migration
Browse files Browse the repository at this point in the history
  • Loading branch information
kabaros committed Oct 24, 2024
1 parent caa059e commit 2ceed67
Show file tree
Hide file tree
Showing 28 changed files with 1,917 additions and 1,570 deletions.
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,27 @@
"devDependencies": {
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@badeball/cypress-cucumber-preprocessor": "^16.0.0",
"@cfaester/enzyme-adapter-react-18": "^0.8.0",
"@cypress/webpack-preprocessor": "^5.17.0",
"@dhis2/cli-app-scripts": "^12.0.0-alpha.19",
"@dhis2/cli-style": "^10.7.4",
"@dhis2/cypress-commands": "^10.0.1",
"@dhis2/cypress-plugins": "^10.0.1",
"@dhis2/d2-i18n": "1.1.3",
"@reportportal/agent-js-cypress": "^5.1.3",
"@reportportal/agent-js-jest": "^5.0.6",
"@testing-library/jest-dom": "^6.6.2",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"cypress": "^12.8.1",
"enzyme": "3.11.0",
"eslint-plugin-cypress": "2.12.1",
"fake-indexeddb": "4.0.1",
"identity-obj-proxy": "^3.0.0",
"jest-extended": "^4.0.2",
"start-server-and-test": "1.15.4"
},
"dependencies": {
"@dhis2/app-runtime": "^3.10.2",
"@dhis2/multi-calendar-dates": "^1.3.1",
"@dhis2/multi-calendar-dates": "^1.3.2",
"@dhis2/ui": "^9.11.8",
"@dhis2/ui-forms": "7.16.3",
"@tanstack/react-query": "4.24.10",
Expand Down Expand Up @@ -81,8 +82,6 @@
"node": ">=14.0.0"
},
"resolutions": {
"@dhis2/multi-calendar-dates": "^1.3.2",
"@dhis2/app-runtime": "^3.10.2",
"@dhis2/d2-i18n": "1.1.3"
"@dhis2/app-runtime": "^3.10.2"
}
}
6 changes: 1 addition & 5 deletions src/app/app-wrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const enableRQDevtools = process.env.REACT_APP_ENABLE_RQ_DEVTOOLS === 'true'
export function OuterComponents({
children,
// This way we can use a different router in tests when needed
router: Router,
router: Router = HashRouter,
queryClient: customQueryClient,
}) {
const queryClient = useQueryClient()
Expand Down Expand Up @@ -60,10 +60,6 @@ export function OuterComponents({
)
}

OuterComponents.defaultProps = {
router: HashRouter,
}

OuterComponents.propTypes = {
children: PropTypes.any.isRequired,
queryClient: PropTypes.instanceOf(QueryClient).isRequired,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
fireEvent,
screen,
waitForElementToBeRemoved,
} from '@testing-library/react'
import userEvent from '@testing-library/user-event'

Check warning on line 5 in src/bottom-bar/validation-results-sidebar/validation-results-sidebar.test.jsx

View workflow job for this annotation

GitHub Actions / lint / lint

Using exported name 'userEvent' as identifier for default export
import React from 'react'
import { MemoryRouter } from 'react-router-dom'
import { render } from '../../test-utils/render.jsx'
Expand Down Expand Up @@ -218,11 +218,10 @@ describe('ValidationResultsSidebar', () => {
getByText('There was a problem running validation')
).toBeDefined()

fireEvent.click(getByText('Run validation again'))
await userEvent.click(getByText('Run validation again'))

await findByText('Running validation...')
await findByText('2 medium priority alerts')
expect(queryByText('There was a problem running validation')).toBeNull()
expect(getByText('2 medium priority alerts')).toBeDefined()
})
it('should show empty data', async () => {
const overrideOptions = {
Expand Down
11 changes: 6 additions & 5 deletions src/context-selection/menu-select/menu-select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import PropTypes from 'prop-types'
import React from 'react'
import css from './menu-select.module.css'

export default function MenuSelect({ values, selected, dataTest, onChange }) {
export default function MenuSelect({
values,
selected,
dataTest = 'menu-select',
onChange,
}) {
return (
<div className={css.menuSelect} data-test={dataTest}>
<Menu>
Expand All @@ -21,10 +26,6 @@ export default function MenuSelect({ values, selected, dataTest, onChange }) {
)
}

MenuSelect.defaultProps = {
dataTest: 'menu-select',
}

MenuSelect.propTypes = {
values: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@ import { useExpanded } from './use-expanded/index.js'
import { useForceReload } from './use-force-reload.js'
import { useRootOrgData } from './use-root-org-data/index.js'

// OrganisationUnitTree.defaultProps = {

// }
const OrganisationUnitTree = ({
onChange,
roots,

autoExpandLoadingError,
dataTest,
dataTest = 'dhis2-uiwidgets-orgunittree',
filter = [],
highlighted = [],
initiallyExpanded = [],
selected = [],
renderNodeLabel = defaultRenderNodeLabel,

disableSelection,
forceReload,
highlighted,
isUserDataViewFallback,
initiallyExpanded,
filter,
renderNodeLabel,
selected,
singleSelection,
suppressAlphabeticalSorting,
offlineLevels,
Expand Down Expand Up @@ -266,13 +270,4 @@ OrganisationUnitTree.propTypes = {
//idsThatShouldBeReloaded: propTypes.arrayOf(orgUnitIdPropType),
}

OrganisationUnitTree.defaultProps = {
dataTest: 'dhis2-uiwidgets-orgunittree',
filter: [],
highlighted: [],
initiallyExpanded: [],
selected: [],
renderNodeLabel: defaultRenderNodeLabel,
}

export { OrganisationUnitTree }
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { CustomDataProvider } from '@dhis2/app-runtime'
import { shallow } from 'enzyme'
// import { shallow } from 'enzyme'
import React from 'react'
import { OrganisationUnitTree } from './organisation-unit-tree.jsx'

describe('OrganisationUnitTree', () => {
// There is no official Enzyme React 18 (or 17) adapter and the advice is to move to RTL
// more context here: https://dev.to/wojtekmaj/enzyme-is-dead-now-what-ekl
// ToDO: migrate this test to RTL and get rid of enzyme
describe.skip('OrganisationUnitTree', () => {
const origError = console.error.bind(console)
const errorMock = jest.fn()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import i18n from '@dhis2/d2-i18n'
import PropTypes from 'prop-types'
import React from 'react'

export const RootError = ({ dataTest, error }) => (
export const RootError = ({
dataTest = 'dhis2-uiwidgets-orgunittree-error',
error,
}) => (
<div data-test={dataTest}>
{i18n.t('Error: {{ ERRORMESSAGE }}', {
ERRORMESSAGE: error,
Expand All @@ -11,10 +14,6 @@ export const RootError = ({ dataTest, error }) => (
</div>
)

RootError.defaultProps = {
dataTest: 'dhis2-uiwidgets-orgunittree-error',
}

RootError.propTypes = {
error: PropTypes.string.isRequired,
dataTest: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { CircularLoader } from '@dhis2-ui/loader'
import PropTypes from 'prop-types'
import React from 'react'

export const RootLoading = ({ dataTest }) => (
export const RootLoading = ({
dataTest = 'dhis2-uiwidgets-orgunittree-loading',
}) => (
<div data-test={dataTest}>
<CircularLoader small />

Expand All @@ -15,10 +17,6 @@ export const RootLoading = ({ dataTest }) => (
</div>
)

RootLoading.defaultProps = {
dataTest: 'dhis2-uiwidgets-orgunittree-loading',
}

RootLoading.propTypes = {
dataTest: PropTypes.string,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CustomDataProvider } from '@dhis2/app-runtime'
import { renderHook } from '@testing-library/react'
import { renderHook, waitFor } from '@testing-library/react'
import React from 'react'
import { useRootOrgData } from './use-root-org-data.js'

Expand Down Expand Up @@ -66,12 +66,11 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
})

it('should provide the org unit data', async () => {
const { result, waitForNextUpdate } = renderHook(
() => useRootOrgData(['A0000000000']),
{ wrapper }
)
const { result } = renderHook(() => useRootOrgData(['A0000000000']), {
wrapper,
})

await waitForNextUpdate()
await waitFor(() => {})

expect(result.current).toEqual(
expect.objectContaining({
Expand Down Expand Up @@ -102,12 +101,11 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
</CustomDataProvider>
)

const { result, waitForNextUpdate } = renderHook(
() => useRootOrgData(['A0000000000']),
{ wrapper: errorWrapper }
)
const { result } = renderHook(() => useRootOrgData(['A0000000000']), {
wrapper: errorWrapper,
})

await waitForNextUpdate()
await waitFor(() => {})

expect(result.current).toEqual(
expect.objectContaining({
Expand All @@ -120,12 +118,9 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
})

it('should send the "isUserDataViewFallback" parameter with value "undefined"', async () => {
const { waitForNextUpdate } = renderHook(
() => useRootOrgData(['A0000000000']),
{ wrapper }
)
renderHook(() => useRootOrgData(['A0000000000']), { wrapper })

await waitForNextUpdate()
await waitFor(() => {})

expect(dataProviderData.organisationUnits).toHaveBeenCalledWith(
'read',
Expand All @@ -140,12 +135,9 @@ describe('OrganisationUnitTree - useRootOrgData', () => {

it('should send the "isUserDataViewFallback" parameter with value "true"', async () => {
const options = { isUserDataViewFallback: true }
const { waitForNextUpdate } = renderHook(
() => useRootOrgData(['A0000000000'], options),
{ wrapper }
)
renderHook(() => useRootOrgData(['A0000000000'], options), { wrapper })

await waitForNextUpdate()
await waitFor(() => {})

expect(dataProviderData.organisationUnits).toHaveBeenCalledWith(
'read',
Expand Down Expand Up @@ -176,12 +168,11 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
</CustomDataProvider>
)

const { result, waitForNextUpdate } = renderHook(
() => useRootOrgData(['A0000000000']),
{ wrapper: wrapperWithoutDisplayName }
)
const { result } = renderHook(() => useRootOrgData(['A0000000000']), {
wrapper: wrapperWithoutDisplayName,
})

await waitForNextUpdate()
await waitFor(() => {})

expect(result.current).toEqual(
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,11 @@ describe('<CategoryComboTableBody />', () => {
}
)

const disabledInputs = result.getAllByRole((role, element) => {
return role === 'textbox' && element.disabled
})
// const disabledInputs = result.getAllByRole('textbox', {
// disabled: true,
// })
const disabledInputs =
result.container.getElementsByClassName('disabled')

expect(disabledInputs.length).toBe(8)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('FollowUpButton', () => {
})

describe('when clicking Mark for followup', () => {
it(`should set the value of followUp to true`, () => {
it(`should set the value of followUp to true`, async () => {
const mutate = jest.fn()

useSetDataValueMutation.mockImplementation(() => ({
Expand All @@ -95,7 +95,7 @@ describe('FollowUpButton', () => {
/>
)

userEvent.click(getByText('Mark for follow-up'))
await userEvent.click(getByText('Mark for follow-up'))
expect(mutate).toHaveBeenCalledWith({
followUp: true,
})
Expand All @@ -113,7 +113,7 @@ describe('FollowUpButton', () => {
})

describe('when clicking Mark for followup', () => {
it(`should set the value of followUp to true`, () => {
it(`should set the value of followUp to true`, async () => {
const mutate = jest.fn()

useSetDataValueMutation.mockImplementation(() => ({
Expand All @@ -126,7 +126,7 @@ describe('FollowUpButton', () => {
/>
)

userEvent.click(getByText('Unmark for follow-up'))
await userEvent.click(getByText('Unmark for follow-up'))

expect(mutate).toHaveBeenCalledWith({
followUp: false,
Expand Down
Loading

0 comments on commit 2ceed67

Please sign in to comment.