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 bab3882 commit 036adc1
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 152 deletions.
143 changes: 78 additions & 65 deletions src/pages/addItem.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,21 @@ describe('<AddItem/>', () => {
const createRequest = async (screen, { requestName, orgUnit }) => {
const requestNameInput = await screen.findByLabelText('Request name')
fireEvent.input(requestNameInput, { target: { value: requestName } })
fireEvent.input(screen.getByTestId('fake-data-selector'), {
target: { value: 'a data element' },
})
fireEvent.input(screen.getByTestId('fake-period-selector'), {
target: { value: 'a period' },
})
fireEvent.input(screen.getByTestId('fake-orgunit-selector'), {
target: { value: orgUnit },
})
await userEvent.type(
screen.getByTestId('fake-data-selector'),
'a data element'
)
await userEvent.type(
screen.getByTestId('fake-period-selector'),
'a period'
)
await userEvent.type(
screen.getByTestId('fake-orgunit-selector'),
orgUnit
)

const footer = screen.getByTestId('edit-request-footer')
within(footer).getByText('Save request').click()
await userEvent.click(within(footer).getByText('Save request'))
}

it('should display a warning if the user does not have permissions to add an exchange', async () => {
Expand Down Expand Up @@ -278,17 +282,19 @@ describe('<AddItem/>', () => {
screen.getByTestId('exchange-types')
).getAllByRole('radio')
expect(typeRadio[1].getAttribute('value')).toEqual('INTERNAL')
typeRadio[1].click()
await userEvent.click(typeRadio[1])

screen.getByText('Add request').click()
await userEvent.click(screen.getByText('Add request'))
await createRequest(screen, { requestName, orgUnit })

const requestRow = await screen.findByTestId('dhis2-uicore-tablerow')
expect(requestRow).toHaveTextContent(requestName)

within(screen.getByTestId('edit-item-footer'))
.getByText('Save exchange')
.click()
await userEvent.click(
within(screen.getByTestId('edit-item-footer')).getByText(
'Save exchange'
)
)

const exchangeNameInputWarning = within(
screen.getByTestId('exchange-name-input')
Expand Down Expand Up @@ -446,34 +452,36 @@ describe('<AddItem/>', () => {
screen.getByTestId('exchange-types')
).getAllByRole('radio')
expect(typeRadio[0].getAttribute('value')).toEqual('EXTERNAL')
typeRadio[0].click()
await userEvent.click(typeRadio[0])

const exchangeURLInput = within(
await screen.findByTestId('exchange-url')
).getByLabelText('Target URL')
fireEvent.input(exchangeURLInput, { target: { value: exchangeURL } })
await userEvent.type(exchangeURLInput, exchangeURL)

const authRadio = within(
screen.getByTestId('exchange-auth-method')
).getAllByRole('radio')
expect(authRadio[1].getAttribute('value')).toEqual('PAT')
authRadio[1].click()
await userEvent.click(authRadio[1])

const tokenInput = within(
screen.getByTestId('exchange-auth-pat')
).getByLabelText('Access token')
fireEvent.input(tokenInput, { target: { value: exchangePAT } })
await userEvent.type(tokenInput, exchangePAT)

screen.getByText('Add request').click()
await userEvent.click(screen.getByText('Add request'))
await createRequest(screen, { requestName, orgUnit })

const requestRow = await screen.findByTestId('dhis2-uicore-tablerow')
expect(requestRow).toHaveTextContent(requestName)
expect(requestRow).toHaveTextContent(orgUnit)

within(screen.getByTestId('edit-item-footer'))
.getByText('Save exchange')
.click()
await userEvent.click(
within(screen.getByTestId('edit-item-footer')).getByText(
'Save exchange'
)
)

const exchangeNameInputWarning = within(
screen.getByTestId('exchange-name-input')
Expand Down Expand Up @@ -506,35 +514,37 @@ describe('<AddItem/>', () => {
const nameInput = within(
screen.getByTestId('exchange-name-input')
).getByLabelText('Exchange name')
fireEvent.input(nameInput, { target: { value: exchangeName } })
await userEvent.type(nameInput, exchangeName)

const typeRadio = within(
screen.getByTestId('exchange-types')
).getAllByRole('radio')
expect(typeRadio[0].getAttribute('value')).toEqual('EXTERNAL')
typeRadio[0].click()
await userEvent.click(typeRadio[0])

const exchangeURLInput = within(
await screen.findByTestId('exchange-url')
).getByLabelText('Target URL')
fireEvent.input(exchangeURLInput, { target: { value: exchangeURL } })
await userEvent.type(exchangeURLInput, exchangeURL)

const authRadio = within(
screen.getByTestId('exchange-auth-method')
).getAllByRole('radio')
expect(authRadio[1].getAttribute('value')).toEqual('PAT')
authRadio[1].click()
await userEvent.click(authRadio[1])

screen.getByText('Add request').click()
await userEvent.click(screen.getByText('Add request'))
await createRequest(screen, { requestName, orgUnit })

const requestRow = await screen.findByTestId('dhis2-uicore-tablerow')
expect(requestRow).toHaveTextContent(requestName)
expect(requestRow).toHaveTextContent(orgUnit)

within(screen.getByTestId('edit-item-footer'))
.getByText('Save exchange')
.click()
await userEvent.click(
within(screen.getByTestId('edit-item-footer')).getByText(
'Save exchange'
)
)

const exchangeAutheInputWarning = within(
screen.getByTestId('exchange-auth-pat')
Expand Down Expand Up @@ -567,34 +577,37 @@ describe('<AddItem/>', () => {
const nameInput = within(
screen.getByTestId('exchange-name-input')
).getByLabelText('Exchange name')
fireEvent.input(nameInput, { target: { value: exchangeName } })

await userEvent.type(nameInput, exchangeName)

const typeRadio = within(
screen.getByTestId('exchange-types')
).getAllByRole('radio')
expect(typeRadio[0].getAttribute('value')).toEqual('EXTERNAL')
typeRadio[0].click()
await userEvent.click(typeRadio[0])

const exchangeURLInput = within(
await screen.findByTestId('exchange-url')
).getByLabelText('Target URL')
fireEvent.input(exchangeURLInput, { target: { value: exchangeURL } })
await userEvent.type(exchangeURLInput, exchangeURL)

const authRadio = within(
screen.getByTestId('exchange-auth-method')
).getAllByRole('radio')
expect(authRadio[0].getAttribute('value')).toEqual('BASIC')
authRadio[0].click()
await userEvent.click(authRadio[0])

screen.getByText('Add request').click()
await userEvent.click(screen.getByText('Add request'))
await createRequest(screen, { requestName, orgUnit })

const requestRow = await screen.findByTestId('dhis2-uicore-tablerow')
expect(requestRow).toHaveTextContent(requestName)

within(screen.getByTestId('edit-item-footer'))
.getByText('Save exchange')
.click()
await userEvent.click(
within(screen.getByTestId('edit-item-footer')).getByText(
'Save exchange'
)
)

const exchangeAuthInputWarnings = within(
screen.getByTestId('exchange-auth-basic')
Expand Down Expand Up @@ -839,19 +852,23 @@ describe('<AddItem/>', () => {
await screen.findByTestId('add-exchange-title')
).toHaveTextContent('Add exchange')

screen.getByText('Add request').click()
await userEvent.click(screen.getByText('Add request'))

await userEvent.type(
screen.getByTestId('fake-data-selector'),
'a data element'
)
await userEvent.type(
screen.getByTestId('fake-period-selector'),
'a period'
)
await userEvent.type(
screen.getByTestId('fake-orgunit-selector'),
orgUnit
)

fireEvent.input(screen.getByTestId('fake-data-selector'), {
target: { value: 'a data element' },
})
fireEvent.input(screen.getByTestId('fake-period-selector'), {
target: { value: 'a period' },
})
fireEvent.input(screen.getByTestId('fake-orgunit-selector'), {
target: { value: orgUnit },
})
const footer = screen.getByTestId('edit-request-footer')
within(footer).getByText('Save request').click()
await userEvent.click(within(footer).getByText('Save request'))

const requestNameInputWarning = within(
screen.getByTestId('request-name')
Expand Down Expand Up @@ -892,10 +909,10 @@ describe('<AddItem/>', () => {
await screen.findByTestId('add-exchange-title')
).toHaveTextContent('Add exchange')

screen.getByText('Add request').click()
await userEvent.click(screen.getByText('Add request'))

const footer = screen.getByTestId('edit-request-footer')
within(footer).getByText('Cancel').click()
await userEvent.click(within(footer).getByText('Cancel'))

await waitFor(() => {
const warningModal = screen.queryByTestId('request-discard-modal')
Expand All @@ -912,12 +929,12 @@ describe('<AddItem/>', () => {
await screen.findByTestId('add-exchange-title')
).toHaveTextContent('Add exchange')

screen.getByText('Add request').click()
await userEvent.click(screen.getByText('Add request'))
const requestNameInput = await screen.findByLabelText('Request name')
fireEvent.input(requestNameInput, { target: { value: 'a request' } })
await userEvent.type(requestNameInput, 'a request')

const footer = screen.getByTestId('edit-request-footer')
within(footer).getByText('Cancel').click()
await userEvent.click(within(footer).getByText('Cancel'))

const warningModal = await screen.findByTestId('request-discard-modal')
expect(warningModal).toBeVisible()
Expand Down Expand Up @@ -1016,23 +1033,19 @@ describe('<AddItem/>', () => {
screen.getByTestId('exchange-types')
).getAllByRole('radio')
expect(typeRadio[1].getAttribute('value')).toEqual('INTERNAL')
typeRadio[1].click()
await userEvent.click(typeRadio[1])

screen.getByText('Add request').click()
await userEvent.click(screen.getByText('Add request'))
await createRequest(screen, { requestName, orgUnit })

const requestRow = await screen.findByTestId('dhis2-uicore-tablerow')
expect(requestRow).toHaveTextContent(requestName)
expect(requestRow).toHaveTextContent(orgUnit)

within(screen.getByTestId('edit-item-footer'))
.getByText('Save exchange')
.click()

await waitFor(() =>
expect(
screen.getByTestId('saving-exchange-loader')
).toBeInTheDocument()
await userEvent.click(
within(screen.getByTestId('edit-item-footer')).getByText(
'Save exchange'
)
)

const expectedPayload = {
Expand Down
20 changes: 12 additions & 8 deletions src/pages/data.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@testing-library/jest-dom'
import { Provider, CustomDataProvider } from '@dhis2/app-runtime'
import { act, configure, render, waitFor, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'

Check warning on line 4 in src/pages/data.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, Route } from 'react-router-dom'
import { QueryParamProvider } from 'use-query-params'
Expand Down Expand Up @@ -223,21 +224,24 @@ describe('<DataPage/>', () => {
aggregateDataExchanges: exchanges,
})

screen.getByTestId('dhis2-ui-selectorbaritem').click()
await userEvent.click(screen.getByTestId('dhis2-ui-selectorbaritem'))

const menuItems = await screen.findAllByTestId('dhis2-uicore-menuitem')
within(menuItems[0]).queryByText(anExchange.displayName).click()

await userEvent.click(
within(menuItems[0]).queryByText(anExchange.displayName)
)

expect(screen.getByTestId('data-exchange-selector')).toHaveTextContent(
anExchange.displayName
)

const loader = screen.getByTestId('dhis2-uicore-circularloader')
expect(loader).toBeInTheDocument()

const headerBar = screen.getByTestId('dhis2-ui-selectorbar')
within(headerBar)
.queryByRole('button', { name: 'Clear selections' })
.click()
await userEvent.click(
within(headerBar).queryByRole('button', {
name: 'Clear selections',
})
)
expect(screen.getByTestId('data-exchange-selector')).toHaveTextContent(
'Choose a data exchange'
)
Expand Down
Loading

0 comments on commit 036adc1

Please sign in to comment.