1- import { render , screen } from '@testing-library/react' ;
1+ import { render , screen , renderHook } from '@testing-library/react' ;
22import * as React from 'react' ;
33import { ISVStepperContext , useISVStepper } from '../ISVStepperContext' ;
44import { Veeam } from '../../modules/veeam' ;
@@ -16,35 +16,31 @@ jest.mock('../ISVSteps', () => {
1616 } ;
1717} ) ;
1818
19- // Mock dependencies
2019jest . mock ( 'react-router' , ( ) => ( {
20+ ...jest . requireActual ( 'react-router' ) ,
2121 useSearchParams : jest . fn ( ) ,
2222} ) ) ;
2323
24- // Import React hooks correctly
2524const { useContext } = React ;
2625
27- // Test the useISVStepper hook
2826describe ( 'useISVStepper' , ( ) => {
2927 it ( 'should throw an error when used outside of the Provider' , ( ) => {
30- const TestComponent = ( ) => {
31- useISVStepper ( ) ;
32- return null ;
33- } ;
28+ const originalError = console . error ;
29+ console . error = jest . fn ( ) ;
3430
35- expect ( ( ) => render ( < TestComponent /> ) ) . toThrow (
36- 'useISVStepper must be used within ISVStepperProvider' ,
37- ) ;
31+ expect ( ( ) => {
32+ renderHook ( ( ) => useISVStepper ( ) ) ;
33+ } ) . toThrow ( 'useISVStepper must be used within ISVStepperProvider' ) ;
34+
35+ console . error = originalError ;
3836 } ) ;
3937} ) ;
4038
41- // Test the ISVSteps component
4239describe ( 'ISVSteps' , ( ) => {
4340 beforeEach ( ( ) => {
4441 jest . clearAllMocks ( ) ;
4542 } ) ;
4643
47- // Component to access context for testing
4844 const ContextReader = ( ) => {
4945 const context = useContext ( ISVStepperContext ) ;
5046 if ( ! context ) return null ;
@@ -58,7 +54,6 @@ describe('ISVSteps', () => {
5854 ) ;
5955 } ;
6056
61- // Set up mock implementation in each test
6257 const setupMockISVSteps = ( platformId : string | null ) => {
6358 const { ISVSteps } = require ( '../ISVSteps' ) ;
6459
@@ -89,15 +84,13 @@ describe('ISVSteps', () => {
8984 ) ;
9085 } ) ;
9186
92- // Configure useSearchParams mock
9387 const { useSearchParams } = require ( 'react-router' ) ;
9488 useSearchParams . mockReturnValue ( [
9589 new URLSearchParams ( platformId ? `?platform=${ platformId } ` : '' ) ,
9690 jest . fn ( ) ,
9791 ] ) ;
9892 } ;
9993
100- // Helper to render component with theme and context reader
10194 const renderWithThemeAndContextReader = ( ) => {
10295 const { ISVSteps } = require ( '../ISVSteps' ) ;
10396
@@ -116,7 +109,6 @@ describe('ISVSteps', () => {
116109 setupMockISVSteps ( platformId ) ;
117110 renderWithThemeAndContextReader ( ) ;
118111
119- // Check platform ID in context
120112 expect ( screen . getByTestId ( 'platform-id' ) ) . toHaveTextContent (
121113 platformId || 'no-platform' ,
122114 ) ;
@@ -127,11 +119,9 @@ describe('ISVSteps', () => {
127119 setupMockISVSteps ( 'veeam-vbr' ) ;
128120 renderWithThemeAndContextReader ( ) ;
129121
130- // Check UI components
131122 expect ( screen . getByTestId ( 'isv-steps' ) ) . toBeInTheDocument ( ) ;
132123 expect ( screen . getByTestId ( 'stepper' ) ) . toBeInTheDocument ( ) ;
133124
134- // Check step labels
135125 expect ( screen . getByTestId ( 'step-0' ) ) . toHaveTextContent ( 'Configure' ) ;
136126 expect ( screen . getByTestId ( 'step-1' ) ) . toHaveTextContent ( 'Apply Actions' ) ;
137127 expect ( screen . getByTestId ( 'step-2' ) ) . toHaveTextContent ( 'Summary' ) ;
0 commit comments