Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/components/AzureMapPopup/useCreateAzureMapPopup.test.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<AzureMapsContext.Provider
value={{
...mapContextProps,
mapRef
mapRef: mapRef as unknown as MapType,
}}
>
{children}
Expand Down
7 changes: 6 additions & 1 deletion src/components/AzureMapPopup/useCreateAzureMapPopup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -14,6 +15,10 @@ export const useCreatePopup = ({
)
const { mapRef } = useContext<IAzureMapsContextProps>(AzureMapsContext)

useCheckRef<MapType, MapType>(mapRef, mapRef, mref => {
mref.events.addOnce('ready', () => mref.popups.add(popupRef))
})

useEffect(() => {
popupRef.setOptions({
...options,
Expand Down