diff --git a/src/components/AzureMapPopup/useCreateAzureMapPopup.test.tsx b/src/components/AzureMapPopup/useCreateAzureMapPopup.test.tsx index 214aca5..b055190 100644 --- a/src/components/AzureMapPopup/useCreateAzureMapPopup.test.tsx +++ b/src/components/AzureMapPopup/useCreateAzureMapPopup.test.tsx @@ -1,25 +1,31 @@ import { ReactNode } from 'react' import { renderHook } from '@testing-library/react' -import { Map } from 'azure-maps-control' import React from 'react' import { AzureMapsContext } from '../../contexts/AzureMapContext' import { useCreatePopup } from './useCreateAzureMapPopup' +import { MapType } from '../../types' const mapContextProps = { - mapRef: null, isMapReady: false, setMapReady: jest.fn(), removeMapRef: jest.fn(), setMapRef: jest.fn() } -const mapRef = new Map('fake', {}) +const mapRef = { + events: { + addOnce: jest.fn() + }, + popups: { + add: jest.fn() + } +} const wrapWithAzureMapContext = ({ children }: { children?: ReactNode | null }) => { return ( {children} diff --git a/src/components/AzureMapPopup/useCreateAzureMapPopup.ts b/src/components/AzureMapPopup/useCreateAzureMapPopup.ts index a76c98e..f96635a 100644 --- a/src/components/AzureMapPopup/useCreateAzureMapPopup.ts +++ b/src/components/AzureMapPopup/useCreateAzureMapPopup.ts @@ -2,8 +2,9 @@ import { useState, useEffect, useContext } from 'react' import { renderToStaticMarkup } from 'react-dom/server' import atlas from 'azure-maps-control' -import { IAzureMapPopup, IAzureMapsContextProps } from '../../types' +import { IAzureMapPopup, IAzureMapsContextProps, MapType } from '../../types' import { AzureMapsContext } from '../../contexts/AzureMapContext' +import { useCheckRef } from '../../hooks/useCheckRef' export const useCreatePopup = ({ options, popupContent, @@ -14,6 +15,10 @@ export const useCreatePopup = ({ ) const { mapRef } = useContext(AzureMapsContext) + useCheckRef(mapRef, mapRef, mref => { + mref.events.addOnce('ready', () => mref.popups.add(popupRef)) + }) + useEffect(() => { popupRef.setOptions({ ...options,