55 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
66 */
77
8- import { createRoot } from 'react-dom/client' ;
9- import { act } from 'react-dom/test-utils' ;
8+ import { render } from '@testing-library/react' ;
109import { IntlProvider } from 'react-intl' ;
1110
1211import { red } from '@mui/material/colors' ;
1312import { createTheme , ThemeProvider } from '@mui/material' ;
14- import { afterEach , beforeEach , expect , it } from '@jest/globals' ;
13+ import { expect , it } from '@jest/globals' ;
1514import TopBar , { LANG_ENGLISH } from './TopBar' ;
1615import { CommonMetadata , top_bar_en } from '../..' ;
1716
1817import PowsyblLogo from '../images/powsybl_logo.svg?react' ;
1918
20- let container : Element ;
21-
22- beforeEach ( ( ) => {
23- // setup a DOM element as a render target
24- container = document . createElement ( 'div' ) ;
25- document . body . appendChild ( container ) ;
26- } ) ;
27-
28- afterEach ( ( ) => {
29- // cleanup on exiting
30- container ?. remove ( ) ;
31- } ) ;
32-
3319const apps : CommonMetadata [ ] = [
3420 {
3521 name : 'App1' ,
@@ -54,50 +40,44 @@ const theme = createTheme({
5440} ) ;
5541
5642it ( 'renders' , ( ) => {
57- const root = createRoot ( container ) ;
58- act ( ( ) => {
59- root . render (
60- < ThemeProvider theme = { theme } >
61- < IntlProvider locale = "en" messages = { top_bar_en } >
62- < TopBar
63- appName = "Demo"
64- appColor = "#808080"
65- appLogo = { < PowsyblLogo /> }
66- onParametersClick = { ( ) => { } }
67- onLogoutClick = { ( ) => { } }
68- onLogoClick = { ( ) => { } }
69- user = { {
70- profile : {
71- name : 'John Doe' ,
72- iss : 'issuer' ,
73- sub : 'sub' ,
74- aud : 'aud' ,
75- exp : 213443 ,
76- iat : 3214324 ,
77- } ,
78- id_token : 'id_token' ,
79- access_token : 'access_token' ,
80- token_type : 'code' ,
81- scope : 'scope' ,
82- expires_at : 123343 ,
83- scopes : [ 'code' , 'token' ] ,
84- expired : false ,
85- state : null ,
86- toStorageString : ( ) => 'stored' ,
87- expires_in : 1232 ,
88- } }
89- appsAndUrls = { apps }
90- language = { LANG_ENGLISH }
91- onLanguageClick = { ( ) => { } }
92- >
93- < p > testchild</ p >
94- </ TopBar >
95- </ IntlProvider >
96- </ ThemeProvider >
97- ) ;
98- } ) ;
43+ const { container } = render (
44+ < ThemeProvider theme = { theme } >
45+ < IntlProvider locale = "en" messages = { top_bar_en } >
46+ < TopBar
47+ appName = "Demo"
48+ appColor = "#808080"
49+ appLogo = { < PowsyblLogo /> }
50+ onParametersClick = { ( ) => { } }
51+ onLogoutClick = { ( ) => { } }
52+ onLogoClick = { ( ) => { } }
53+ user = { {
54+ profile : {
55+ name : 'John Doe' ,
56+ iss : 'issuer' ,
57+ sub : 'sub' ,
58+ aud : 'aud' ,
59+ exp : 213443 ,
60+ iat : 3214324 ,
61+ } ,
62+ id_token : 'id_token' ,
63+ access_token : 'access_token' ,
64+ token_type : 'code' ,
65+ scope : 'scope' ,
66+ expires_at : 123343 ,
67+ scopes : [ 'code' , 'token' ] ,
68+ expired : false ,
69+ state : null ,
70+ toStorageString : ( ) => 'stored' ,
71+ expires_in : 1232 ,
72+ } }
73+ appsAndUrls = { apps }
74+ language = { LANG_ENGLISH }
75+ onLanguageClick = { ( ) => { } }
76+ >
77+ < p > testchild</ p >
78+ </ TopBar >
79+ </ IntlProvider >
80+ </ ThemeProvider >
81+ ) ;
9982 expect ( container . textContent ) . toContain ( 'GridDemotestchildJD' ) ;
100- act ( ( ) => {
101- root . unmount ( ) ;
102- } ) ;
10383} ) ;
0 commit comments