1
1
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
- import React , { useRef } from 'react' ;
3
+ import React from 'react' ;
4
4
import { render , screen } from '@testing-library/react' ;
5
5
6
+ import { clearVisualRefreshState } from '@cloudscape-design/component-toolkit/internal/testing' ;
7
+
6
8
import VisualContext from '../../../../../lib/components/internal/components/visual-context' ;
7
- import { usePortalModeClasses } from '../../../../../lib/components/internal/hooks/use-portal-mode-classes' ;
8
- import { useVisualRefresh } from '../../../../../lib/components/internal/hooks/use-visual-mode' ;
9
+ import { RenderTest } from './helpers' ;
9
10
10
- jest . mock ( '../../../../../lib/components/internal/hooks/use-visual-mode' , ( ) => {
11
- const original = jest . requireActual ( '../../../../../lib/components/internal/hooks/use-visual-mode' ) ;
12
- return { ...original , useVisualRefresh : jest . fn ( ) } ;
13
- } ) ;
14
-
15
- afterEach ( ( ) => {
16
- ( useVisualRefresh as jest . Mock ) . mockReset ( ) ;
17
- } ) ;
11
+ const globalWithFlags = globalThis as any ;
18
12
19
13
describe ( 'usePortalModeClasses' , ( ) => {
20
- function RenderTest ( { refClasses } : { refClasses : string } ) {
21
- const ref = useRef ( null ) ;
22
- const classes = usePortalModeClasses ( ref ) ;
23
- return (
24
- < div >
25
- < div ref = { ref } className = { refClasses } />
26
- < div data-testid = "subject" className = { classes } />
27
- </ div >
28
- ) ;
29
- }
30
-
31
14
afterEach ( ( ) => {
32
15
jest . clearAllMocks ( ) ;
16
+ delete globalWithFlags [ Symbol . for ( 'awsui-visual-refresh-flag' ) ] ;
17
+ clearVisualRefreshState ( ) ;
33
18
} ) ;
34
19
35
20
test ( 'should not add any classes by default' , ( ) => {
@@ -49,6 +34,14 @@ describe('usePortalModeClasses', () => {
49
34
expect ( screen . getByTestId ( 'subject' ) ) . toHaveClass ( 'awsui-polaris-compact-mode awsui-compact-mode' , { exact : true } ) ;
50
35
} ) ;
51
36
37
+ test ( 'should detect visual refresh mode' , ( ) => {
38
+ globalWithFlags [ Symbol . for ( 'awsui-visual-refresh-flag' ) ] = ( ) => true ;
39
+
40
+ render ( < RenderTest refClasses = "" /> ) ;
41
+ expect ( document . body ) . toHaveClass ( 'awsui-visual-refresh' , { exact : true } ) ;
42
+ expect ( screen . getByTestId ( 'subject' ) ) . toHaveClass ( 'awsui-visual-refresh' , { exact : true } ) ;
43
+ } ) ;
44
+
52
45
test ( 'should detect contexts' , ( ) => {
53
46
render (
54
47
< VisualContext contextName = "content-header" >
0 commit comments