Skip to content

Commit

Permalink
✅ Add E2E addMapClickEventWithMarker
Browse files Browse the repository at this point in the history
- #61
  • Loading branch information
JaeSeoKim committed Jan 18, 2024
1 parent 7472ff9 commit f246a42
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 31 deletions.
47 changes: 47 additions & 0 deletions dev/src/pages/samples/addMapClickEventWithMarker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Map, MapMarker } from "react-kakao-maps-sdk"
import useKakaoLoader from "./useKakaoLoader"
import { useState } from "react"

const center = {
// 지도의 중심좌표
lat: 33.450701,
lng: 126.570667,
}

export default function AddMapClickEventWithMarker() {
useKakaoLoader()
const [position, setPosition] = useState<{
lat: number
lng: number
}>()

return (
<>
<Map // 지도를 표시할 Container
id="map"
center={center}
style={{
width: "100%",
height: "350px",
}}
level={3} // 지도의 확대 레벨
onClick={(_, mouseEvent) => {
const latlng = mouseEvent.latLng
setPosition({
lat: latlng.getLat(),
lng: latlng.getLng(),
})
}}
>
<MapMarker position={position ?? center} />
</Map>
<p>
<em>지도를 클릭해주세요!</em>
</p>
<div id="clickLatlng">
{position &&
`클릭한 위치의 위도는 ${position.lat} 이고, 경도는 ${position.lng} 입니다`}
</div>
</>
)
}
5 changes: 5 additions & 0 deletions dev/src/pages/samples/sampleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ChangeOverlay2 from "./changeOverlay2"
import SetBounds from "./setBounds"
import MapRelayout from "./mapRelayout"
import AddMapClickEvent from "./addMapClickEvent"
import AddMapClickEventWithMarker from "./addMapClickEventWithMarker"

export const samples: RouteObject[] = [
{
Expand Down Expand Up @@ -81,4 +82,8 @@ export const samples: RouteObject[] = [
path: "addMapClickEvent",
element: <AddMapClickEvent />,
},
{
path: "addMapClickEventWithMarker",
element: <AddMapClickEventWithMarker />,
},
]
34 changes: 3 additions & 31 deletions docs/docs/sample/map/addMapClickEventWithMarker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,6 @@ sidebar_position: 16

> original docs : https://apis.map.kakao.com/web/sample/addMapClickEventWithMarker/
```jsx live
function(){
const Main = () => {
const [position, setPosition] = useState()
return (
<>
<Map // 지도를 표시할 Container
center={{
// 지도의 중심좌표
lat: 33.450701,
lng: 126.570667,
}}
style={{
width: "100%",
height: "450px",
}}
level={3} // 지도의 확대 레벨
onClick={(_t, mouseEvent) => setPosition({
lat: mouseEvent.latLng.getLat(),
lng: mouseEvent.latLng.getLng(),
})}
>
{position && <MapMarker position={position} />}
</Map>
{position && <p>{'클릭한 위치의 위도는 ' + position.lat + ' 이고, 경도는 ' + position.lng + ' 입니다'}</p>}
</>
)
}
return (<Main/>)
}
```
import codesource from "!!raw-loader!~samples/addMapClickEventWithMarker.tsx"

<LiveEditor>{codesource}</LiveEditor>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { test, expect } from "@playwright/test"

const getUrl = (id: string, isUpdateSanpShots: boolean = false) =>
isUpdateSanpShots
? `http://127.0.0.1:5252/samples/${id}.html`
: `/samples/${id}`

test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
const url = getUrl(
"addMapClickEventWithMarker",
testInfo.config.updateSnapshots === "all",
)
await page.goto(url, { waitUntil: "networkidle" })
await page.waitForLoadState("networkidle")
await expect(page).toHaveScreenshot({
maxDiffPixels: 120, // map의 center값을 넘겼지만, `map.getCenter()` 시 넘어오는 값이 정확하게 일치하지 않아서 fail 나는 부분을 무시
})

const mapBoundingBox = await page.locator("#map").boundingBox()
await page.mouse.click(mapBoundingBox!.x, mapBoundingBox!.y)
await expect(page.locator("#clickLatlng")).toHaveText(
"클릭한 위치의 위도는 33.452254813152855 이고, 경도는 126.5638559967347 입니다",
)
await expect(page).toHaveScreenshot()

await page.mouse.click(
mapBoundingBox!.x + mapBoundingBox!.width / 2,
mapBoundingBox!.y + mapBoundingBox!.height / 2,
)
await expect(page.locator("#clickLatlng")).toHaveText(
"클릭한 위치의 위도는 33.450700761312206 이고, 경도는 126.57066121198349 입니다",
)
await expect(page).toHaveScreenshot()
})

0 comments on commit f246a42

Please sign in to comment.