Skip to content

Commit

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

export default function AddMapClickEvent() {
useKakaoLoader()
const [result, setResult] = useState("")

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

export const samples: RouteObject[] = [
{
Expand Down Expand Up @@ -76,4 +77,8 @@ export const samples: RouteObject[] = [
path: "mapRelayout",
element: <MapRelayout />,
},
{
path: "addMapClickEvent",
element: <AddMapClickEvent />,
},
]
33 changes: 3 additions & 30 deletions docs/docs/sample/map/addMapClickEvent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,6 @@ sidebar_position: 15

> original docs : https://apis.map.kakao.com/web/sample/addMapClickEvent/
```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(),
})}
>
</Map>
{position && <p>{'클릭한 위치의 위도는 ' + position.lat + ' 이고, 경도는 ' + position.lng + ' 입니다'}</p>}
</>
)
}
return (<Main/>)
}
```
import codesource from "!!raw-loader!~samples/addMapClickEvent.tsx"

<LiveEditor>{codesource}</LiveEditor>
30 changes: 30 additions & 0 deletions packages/react-kakao-maps-sdk/__test__/addMapClickEvent.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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(
"addMapClickEvent",
testInfo.config.updateSnapshots === "all",
)
await page.goto(url, { waitUntil: "networkidle" })
await page.waitForLoadState("networkidle")
await expect(page).toHaveScreenshot()

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

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

0 comments on commit 7472ff9

Please sign in to comment.