11import React , { createRef } from 'react' ;
2- import { mount } from 'test-utilities' ;
2+ import { mount , mountWithApp } from 'test-utilities' ;
33// eslint-disable-next-line no-restricted-imports
44import { mountWithAppProvider } from 'test-utilities/legacy' ;
55
6- import { Portal } from '../Portal' ;
6+ import { Portal , UNIQUE_CONTAINER_ID } from '../Portal' ;
77import { portal } from '../../shared' ;
88
99jest . mock ( 'react-dom' , ( ) => ( {
@@ -28,6 +28,41 @@ describe('<Portal />', () => {
2828 createPortalSpy . mockRestore ( ) ;
2929 } ) ;
3030
31+ describe ( 'container' , ( ) => {
32+ it ( 'creates a portal container with the UNIQUE_CONTAINER_ID' , ( ) => {
33+ const appendChildSpy = jest . spyOn ( document . body , 'appendChild' ) ;
34+ mountWithApp ( < Portal /> ) ;
35+ expect ( appendChildSpy ) . toHaveBeenLastCalledWith (
36+ expect . objectContaining ( {
37+ id : UNIQUE_CONTAINER_ID ,
38+ } ) ,
39+ ) ;
40+ appendChildSpy . mockReset ( ) ;
41+ } ) ;
42+
43+ it ( 'sets CSS custom properties on the portal node' , ( ) => {
44+ const setSpy = jest . spyOn ( Element . prototype , 'setAttribute' ) ;
45+ const portal = mountWithAppProvider ( < Portal /> , {
46+ features : { newDesignLanguage : true } ,
47+ theme : {
48+ colors : { surface : '#000000' } ,
49+ } ,
50+ } ) ;
51+
52+ expect ( setSpy ) . toHaveBeenLastCalledWith (
53+ 'style' ,
54+ portal . context ( ) . cssCustomProperties ,
55+ ) ;
56+ setSpy . mockRestore ( ) ;
57+ } ) ;
58+
59+ it ( 'removes CSS custom properties from the portal node' , ( ) => {
60+ const removeSpy = jest . spyOn ( Element . prototype , 'removeAttribute' ) ;
61+ mountWithAppProvider ( < Portal /> ) ;
62+ expect ( removeSpy ) . toHaveBeenCalledWith ( 'style' ) ;
63+ } ) ;
64+ } ) ;
65+
3166 describe ( 'children' , ( ) => {
3267 it ( 'get passed into the portal creation method' , ( ) => {
3368 const children = < div /> ;
@@ -104,25 +139,4 @@ describe('<Portal />', () => {
104139 mount ( < Portal /> ) ;
105140 } ) . not . toThrow ( ) ;
106141 } ) ;
107-
108- it ( 'sets CSS custom properties on the portal node' , ( ) => {
109- const setSpy = jest . spyOn ( Element . prototype , 'setAttribute' ) ;
110- const portal = mountWithAppProvider ( < Portal /> , {
111- features : { newDesignLanguage : true } ,
112- theme : {
113- colors : { surface : '#000000' } ,
114- } ,
115- } ) ;
116-
117- expect ( setSpy ) . toHaveBeenCalledWith (
118- 'style' ,
119- portal . context ( ) . cssCustomProperties ,
120- ) ;
121- } ) ;
122-
123- it ( 'removes CSS custom properties from the portal node' , ( ) => {
124- const removeSpy = jest . spyOn ( Element . prototype , 'removeAttribute' ) ;
125- mountWithAppProvider ( < Portal /> ) ;
126- expect ( removeSpy ) . toHaveBeenCalledWith ( 'style' ) ;
127- } ) ;
128142} ) ;
0 commit comments