@@ -23,6 +23,7 @@ import { assertTextVisibility } from '@ovh-ux/manager-core-test-utils';
2323import { waitFor } from '@testing-library/dom' ;
2424import { act , render , screen } from '@testing-library/react' ;
2525import { SECRET_ACTIVATE_OKMS_TEST_IDS } from '@secret-manager/pages/createSecret/ActivateRegion.contants' ;
26+ import { locationsMock } from '@secret-manager/mocks/locations/locations.mock' ;
2627import { labels , initTestI18n } from '@/utils/tests/init.i18n' ;
2728import { OkmsManagement } from './OkmsManagement.component' ;
2829import { catalogMock } from '@/mocks/catalog/catalog.mock' ;
@@ -35,15 +36,26 @@ import {
3536import { useOkmsList } from '@/data/hooks/useOkms' ;
3637import { OKMS } from '@/types/okms.type' ;
3738import { getOrderCatalogOKMS } from '@/data/api/orderCatalogOKMS' ;
39+ import * as locationApi from '@/common/data/api/location' ;
3840import { ErrorResponse } from '@/types/api.type' ;
3941import { OrderOkmsModalProvider } from '@/common/pages/OrderOkmsModal/OrderOkmsModalContext' ;
42+ import { REGION_PICKER_TEST_IDS } from '@/common/components/regionPicker/regionPicker.constants' ;
43+ import { createErrorResponseMock } from '@/utils/tests/testUtils' ;
44+ import { useNotificationAddErrorOnce } from '@/hooks/useNotificationAddErrorOnce' ;
4045
4146let i18nValue : i18n ;
4247
48+ const mockedGetOrderCatalogOKMS = vi . mocked ( getOrderCatalogOKMS ) ;
4349vi . mock ( '@/data/api/orderCatalogOKMS' , ( ) => ( {
4450 getOrderCatalogOKMS : vi . fn ( ) ,
4551} ) ) ;
4652
53+ vi . spyOn ( locationApi , 'getLocations' ) . mockResolvedValue ( locationsMock ) ;
54+
55+ vi . mock ( '@/hooks/useNotificationAddErrorOnce' , ( ) => ( {
56+ useNotificationAddErrorOnce : vi . fn ( ) ,
57+ } ) ) ;
58+
4759vi . mock ( 'react-router-dom' , async ( importOriginal ) => {
4860 const module : typeof import ( 'react-router-dom' ) = await importOriginal ( ) ;
4961 return {
@@ -213,37 +225,32 @@ const selectRegion = async (user: UserEvent, region: string) => {
213225describe ( 'OKMS management test suite' , ( ) => {
214226 it ( 'should display a spinner when loading' , async ( ) => {
215227 // GIVEN
216- vi . mocked ( getOrderCatalogOKMS ) . mockResolvedValueOnce ( catalogMock ) ;
228+ mockedGetOrderCatalogOKMS . mockResolvedValueOnce ( catalogMock ) ;
217229 // WHEN
218230 await renderOkmsManagement ( ) ;
219231
220232 // THEN
221- const regionsSpinner = screen . getByTestId ( 'regionsSpinner' ) ;
233+ const regionsSpinner = screen . getByTestId ( REGION_PICKER_TEST_IDS . SPINNER ) ;
222234 expect ( regionsSpinner ) . toBeVisible ( ) ;
223235 } ) ;
224236
225237 it ( 'should display a notification message when error on catalog api' , async ( ) => {
226238 // GIVEN
227- const mockError : ErrorResponse = {
228- response : { data : { message : 'errorCatalog' } , status : 500 } ,
229- } ;
230- vi . mocked ( getOrderCatalogOKMS ) . mockRejectedValue ( mockError ) ;
239+ const mockError = createErrorResponseMock ( 'errorCatalog' ) ;
240+ mockedGetOrderCatalogOKMS . mockRejectedValue ( mockError ) ;
231241
232242 // WHEN
233243 await renderOkmsManagement ( ) ;
234244
235245 // THEN
236- await assertTextVisibility (
237- labels . common . error . error_message . replace (
238- '{{message}}' ,
239- mockError . response . data . message ,
240- ) ,
241- ) ;
246+ await waitFor ( ( ) => {
247+ expect ( useNotificationAddErrorOnce ) . toHaveBeenCalledWith ( mockError ) ;
248+ } ) ;
242249 } ) ;
243250
244251 it ( 'should display the available region list' , async ( ) => {
245252 // GIVEN
246- vi . mocked ( getOrderCatalogOKMS ) . mockResolvedValueOnce ( catalogMock ) ;
253+ mockedGetOrderCatalogOKMS . mockResolvedValueOnce ( catalogMock ) ;
247254 // WHEN
248255 await renderOkmsManagement ( ) ;
249256 await assertTextVisibility (
@@ -262,7 +269,7 @@ describe('OKMS management test suite', () => {
262269 it ( 'should display a CTA' , async ( ) => {
263270 const user = userEvent . setup ( ) ;
264271 // GIVEN
265- vi . mocked ( getOrderCatalogOKMS ) . mockResolvedValueOnce ( catalogMock ) ;
272+ mockedGetOrderCatalogOKMS . mockResolvedValueOnce ( catalogMock ) ;
266273
267274 await renderOkmsManagement ( ) ;
268275 await assertTextVisibility (
@@ -284,7 +291,7 @@ describe('OKMS management test suite', () => {
284291 it ( 'should display a loading state when an order is processing' , async ( ) => {
285292 const user = userEvent . setup ( ) ;
286293 // GIVEN
287- vi . mocked ( getOrderCatalogOKMS ) . mockResolvedValueOnce ( catalogMock ) ;
294+ mockedGetOrderCatalogOKMS . mockResolvedValueOnce ( catalogMock ) ;
288295
289296 await renderOkmsManagement ( 'rbx' ) ;
290297 await assertTextVisibility (
@@ -305,7 +312,7 @@ describe('OKMS management test suite', () => {
305312 it ( 'should not display anything when there is exactly one okms' , async ( ) => {
306313 const user = userEvent . setup ( ) ;
307314 // GIVEN
308- vi . mocked ( getOrderCatalogOKMS ) . mockResolvedValueOnce ( catalogMock ) ;
315+ mockedGetOrderCatalogOKMS . mockResolvedValueOnce ( catalogMock ) ;
309316
310317 await renderOkmsManagement ( ) ;
311318 await assertTextVisibility (
@@ -329,7 +336,7 @@ describe('OKMS management test suite', () => {
329336 const user = userEvent . setup ( ) ;
330337
331338 // GIVEN
332- vi . mocked ( getOrderCatalogOKMS ) . mockResolvedValueOnce ( catalogMock ) ;
339+ mockedGetOrderCatalogOKMS . mockResolvedValueOnce ( catalogMock ) ;
333340
334341 await renderOkmsManagement ( ) ;
335342 await assertTextVisibility (
@@ -360,7 +367,7 @@ describe('OKMS management test suite', () => {
360367
361368 describe ( 'When there is a okmsId search param' , ( ) => {
362369 beforeEach ( ( ) => {
363- vi . mocked ( getOrderCatalogOKMS ) . mockResolvedValueOnce ( catalogMock ) ;
370+ mockedGetOrderCatalogOKMS . mockResolvedValueOnce ( catalogMock ) ;
364371 } ) ;
365372 it ( 'should pre-select the right region and okms' , async ( ) => {
366373 // GIVEN
0 commit comments