Skip to content

Commit 1b70c16

Browse files
authored
Update react 18 (#187)
* Update to React 18 - update CloudScape to get support for React 18 - update @testing-library to get support for React 18 - remove @testing-library/react-hooks as it does not support React 18 * Adopt built-in renderHook from @testing-library/react * Fix failing test due to new semantics of waitFor * Fix failing build due transpilation issues * Fix internal import not being there anymore * Fix failing test due to change in renderHook result interface
1 parent 0b5c9f0 commit 1b70c16

File tree

11 files changed

+290
-293
lines changed

11 files changed

+290
-293
lines changed

frontend/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const nextConfig = {
4343

4444
const withTM = require("next-transpile-modules")([
4545
"@cloudscape-design/components",
46+
"@cloudscape-design/component-toolkit",
4647
"@cloudscape-design/design-tokens"
4748
]);
4849

frontend/package-lock.json

Lines changed: 266 additions & 252 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
"private": true,
55
"homepage": "/",
66
"dependencies": {
7-
"@cloudscape-design/components": "^3.0.118",
8-
"@cloudscape-design/design-tokens": "^3.0.9",
9-
"@cloudscape-design/global-styles": "^1.0.2",
7+
"@cloudscape-design/components": "^3.0.248",
8+
"@cloudscape-design/design-tokens": "^3.0.11",
9+
"@cloudscape-design/global-styles": "^1.0.8",
1010
"@reduxjs/toolkit": "^1.6.1",
1111
"axios": "^0.21.4",
1212
"i18next": "^21.8.13",
1313
"js-yaml": "^4.1.0",
1414
"lodash": "^4.17.21",
1515
"next": "^12.2.0",
1616
"next-transpile-modules": "^9.0.0",
17-
"react": "^17.0.2",
18-
"react-dom": "^17.0.2",
17+
"react": "^18.2.0",
18+
"react-dom": "^18.2.0",
1919
"react-i18next": "^11.18.0",
2020
"react-query": "^3.39.1",
2121
"react-redux": "^7.2.5",
@@ -47,9 +47,8 @@
4747
},
4848
"devDependencies": {
4949
"@cloudscape-design/jest-preset": "^2.0.4",
50-
"@testing-library/react": "^12.1.5",
51-
"@testing-library/react-hooks": "^8.0.1",
52-
"@testing-library/user-event": "^14.3.0",
50+
"@testing-library/react": "^14.0.0",
51+
"@testing-library/user-event": "^14.4.3",
5352
"@types/jest": "^28.1.4",
5453
"@types/lodash": "^4.14.182",
5554
"@types/node": "^18.0.0",

frontend/src/components/__tests__/useClusterPoll.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {renderHook} from '@testing-library/react-hooks'
1+
import {renderHook} from '@testing-library/react'
22
import {useClusterPoll} from '../useClusterPoll'
33

44
jest.mock('../../model', () => ({

frontend/src/components/__tests__/useLoadingState.test.tsx

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {renderHook} from '@testing-library/react-hooks'
1+
import {renderHook, waitFor} from '@testing-library/react'
22
import {useLoadingState} from '../useLoadingState'
33
import {Box} from '@cloudscape-design/components'
44
import React from 'react'
@@ -44,9 +44,9 @@ jest.mock('../../model', () => {
4444
})
4545

4646
function expectDataToBeRequested() {
47-
expect(mockGetAppConfig).toHaveBeenCalledTimes(1)
48-
expect(mockGetIdentity).toHaveBeenCalledTimes(1)
49-
expect(mockGetVersion).toHaveBeenCalledTimes(1)
47+
waitFor(() => expect(mockGetAppConfig).toHaveBeenCalledTimes(1))
48+
waitFor(() => expect(mockGetIdentity).toHaveBeenCalledTimes(1))
49+
waitFor(() => expect(mockGetVersion).toHaveBeenCalledTimes(1))
5050
}
5151

5252
function expectDataNotToBeRequested() {
@@ -114,12 +114,7 @@ describe('given a hook to load all the data necessary for the app to boot', () =
114114
})
115115

116116
it('should request the data', async () => {
117-
const {waitForNextUpdate} = renderHook(
118-
() => useLoadingState(<Box></Box>),
119-
{wrapper},
120-
)
121-
122-
await waitForNextUpdate()
117+
renderHook(() => useLoadingState(<Box></Box>), {wrapper})
123118

124119
expectDataToBeRequested()
125120
})
@@ -139,12 +134,7 @@ describe('given a hook to load all the data necessary for the app to boot', () =
139134
})
140135

141136
it('should request the data', async () => {
142-
const {waitForNextUpdate} = renderHook(
143-
() => useLoadingState(<Box></Box>),
144-
{wrapper},
145-
)
146-
147-
await waitForNextUpdate()
137+
renderHook(() => useLoadingState(<Box></Box>), {wrapper})
148138

149139
expectDataToBeRequested()
150140
})
@@ -166,12 +156,7 @@ describe('given a hook to load all the data necessary for the app to boot', () =
166156
})
167157

168158
it('should request the data', async () => {
169-
const {waitForNextUpdate} = renderHook(
170-
() => useLoadingState(<Box></Box>),
171-
{wrapper},
172-
)
173-
174-
await waitForNextUpdate()
159+
renderHook(() => useLoadingState(<Box></Box>), {wrapper})
175160

176161
expectDataToBeRequested()
177162
})
@@ -259,10 +244,9 @@ describe('given a hook to load all the data necessary for the app to boot', () =
259244
done()
260245
})
261246

262-
const {waitForNextUpdate} = renderHook(() => useLoadingState(<></>), {
247+
renderHook(() => useLoadingState(<></>), {
263248
wrapper,
264249
})
265-
waitForNextUpdate()
266250
})
267251
})
268252
})

frontend/src/feature-flags/__tests__/useFeatureFlag.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
99
// limitations under the License.
1010

11-
import {renderHook} from '@testing-library/react-hooks'
11+
import {renderHook} from '@testing-library/react'
1212
import {useFeatureFlag} from '../useFeatureFlag'
1313

1414
const mockUseState = jest.fn()

frontend/src/old-pages/Clusters/FromClusterModal/__tests__/useClustersToCopyFrom.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// limitations under the License.
1111

1212
import {Store} from '@reduxjs/toolkit'
13-
import {renderHook} from '@testing-library/react-hooks'
13+
import {renderHook} from '@testing-library/react'
1414
import {mock} from 'jest-mock-extended'
1515
import {PropsWithChildren} from 'react'
1616
import {Provider} from 'react-redux'

frontend/src/old-pages/Configure/Create.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {setState, getState, useState} from '../../store'
3838
import {NavigateFunction} from 'react-router-dom'
3939
import TitleDescriptionHelpPanel from '../../components/help-panel/TitleDescriptionHelpPanel'
4040
import {useHelpPanel} from '../../components/help-panel/HelpPanel'
41-
import {StackedFlashbarProps} from '@cloudscape-design/components/flashbar/interfaces'
4241
import {errorsToFlashbarItems} from './errorsToFlashbarItems'
4342

4443
// Constants
@@ -209,7 +208,7 @@ function Create() {
209208
FlashbarProps.MessageDefinition[]
210209
>([])
211210

212-
const flashbarProps: StackedFlashbarProps = {
211+
const flashbarProps: FlashbarProps = {
213212
stackItems: true,
214213
items: flashbarItems,
215214
}

frontend/src/old-pages/Configure/__tests__/dynamicFS.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Store} from '@reduxjs/toolkit'
2-
import {renderHook} from '@testing-library/react-hooks'
2+
import {renderHook} from '@testing-library/react'
33
import {mock} from 'jest-mock-extended'
44
import {Provider} from 'react-redux'
55
import {useDynamicStorage} from '../Storage'

frontend/src/old-pages/Configure/__tests__/useWizardNavigation.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Store} from '@reduxjs/toolkit'
2-
import {renderHook} from '@testing-library/react-hooks'
2+
import {renderHook} from '@testing-library/react'
33
import {mock} from 'jest-mock-extended'
44
import {Provider} from 'react-redux'
55
import {useWizardNavigation} from '../useWizardNavigation'

frontend/src/old-pages/Logs/__tests__/LogStreamsTable.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// limitations under the License.
1111

1212
import {Store} from '@reduxjs/toolkit'
13-
import {render, RenderResult} from '@testing-library/react'
13+
import {render, RenderResult, waitFor} from '@testing-library/react'
1414
import userEvent from '@testing-library/user-event'
1515
import {mock} from 'jest-mock-extended'
1616
import {I18nextProvider, initReactI18next} from 'react-i18next'
@@ -142,7 +142,7 @@ describe('given a component to show the log streams list and a cluster name', ()
142142

143143
describe('when the user selects a log stream', () => {
144144
it('should call the selection handler with the selected log stream name', async () => {
145-
await userEvent.click(screen.getByRole('radio'))
145+
await waitFor(() => userEvent.click(screen.getByRole('radio')))
146146
expect(mockOnLogStreamSelect).toHaveBeenCalledTimes(1)
147147
expect(mockOnLogStreamSelect).toHaveBeenCalledWith(
148148
'hostname.instanceId.logIdentifier',

0 commit comments

Comments
 (0)