-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Add E2E addMapClickEventWithMarker
- #61
- Loading branch information
Showing
4 changed files
with
89 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/react-kakao-maps-sdk/__test__/addMapClickEventWithMarker.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) |