Skip to content

Commit

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

export default function AddMapBoundsChangedEvent() {
useKakaoLoader()
const [bounds, setBounds] = useState<{
sw: string
ne: string
}>()

return (
<>
<Map // 지도를 표시할 Container
id="map"
center={{
// 지도의 중심좌표
lat: 33.450701,
lng: 126.570667,
}}
style={{
width: "100%",
height: "350px",
}}
level={3} // 지도의 확대 레벨
onBoundsChanged={(map) => {
const bounds = map.getBounds()
setBounds({
sw: bounds.getSouthWest().toString(),
ne: bounds.getNorthEast().toString(),
})
}}
/>
<p>
<em>지도 영역이 변경되면 지도 정보가 표출됩니다</em>
</p>
<p id="result">
{bounds && (
<p>
영역좌표는 남서쪽 위도, 경도는 {bounds.sw}이고 <br />
북동쪽 위도, 경도는 {bounds.ne}입니다{" "}
</p>
)}
</p>
</>
)
}
40 changes: 3 additions & 37 deletions docs/docs/sample/map/addMapBoundsChangedEvent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,6 @@ sidebar_position: 20

> original docs : https://apis.map.kakao.com/web/sample/addMapBoundsChangedEvent/
```jsx live
function(){
const Main = () => {
const [state, setState] = useState()
return (
<>
<Map // 지도를 표시할 Container
center={{
// 지도의 중심좌표
lat: 33.450701,
lng: 126.570667,
}}
style={{
width: "100%",
height: "450px",
}}
level={3} // 지도의 확대 레벨
onBoundsChanged={(map) => setState({
sw: map.getBounds().getSouthWest().toString(),
ne: map.getBounds().getNorthEast().toString(),
})}
>
</Map>
{!!state && (
<>
<p>
{'영역좌표는 남서쪽 위도, 경도는 ' + state.sw + ' 이고'}<br/>
{'북동쪽 위도, 경도는 ' + state.ne + '입니다'}
</p>
</>
)}
</>
)
}
return (<Main/>)
}
```
import codesource from "!!raw-loader!~samples/addMapBoundsChangedEvent.tsx"

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

test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
const url = getTestUrl(
"addMapBoundsChangedEvent",
testInfo.config.updateSnapshots === "all",
)
await page.goto(url, { waitUntil: "networkidle" })
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot()

const mapBoundingBox = await page.locator("#map").boundingBox()
await page.mouse.move(mapBoundingBox!.x, mapBoundingBox!.y)
await page.mouse.down()
await page.mouse.move(
mapBoundingBox!.x + mapBoundingBox!.width / 2,
mapBoundingBox!.y + mapBoundingBox!.height / 2,
)
await waitNetworkIdleWithTimeout(page)

await expect(page.locator("#result")).toHaveText(
"영역좌표는 남서쪽 위도, 경도는 (33.45065294391403, 126.55706658514791)이고 북동쪽 위도, 경도는 (33.45385631221043, 126.57064566190085)입니다 ",
)
await page.mouse.move(
mapBoundingBox!.x + mapBoundingBox!.width / 3,
mapBoundingBox!.y + mapBoundingBox!.height / 3,
)
await page.mouse.up()
await waitNetworkIdleWithTimeout(page)
await expect(page.locator("#result")).toHaveText(
"영역좌표는 남서쪽 위도, 경도는 (33.45012909463751, 126.55933862932383)이고 북동쪽 위도, 경도는 (33.45333221438989, 126.57291771102653)입니다 ",
)
})

0 comments on commit cde68c5

Please sign in to comment.