Skip to content

Commit

Permalink
✅ Add E2E disableMapDragMove test
Browse files Browse the repository at this point in the history
update E2E basicMap test

- #61
  • Loading branch information
JaeSeoKim committed Sep 12, 2023
1 parent cb695b1 commit df5d745
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 27 deletions.
35 changes: 35 additions & 0 deletions dev/src/pages/samples/disableMapDragMove.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Map } from "react-kakao-maps-sdk"
import useKakaoLoader from "./useKakaoLoader"
import { useState } from "react"

export default function DisableMapDragMove() {
useKakaoLoader()
const [draggable, setDraggable] = useState<boolean>(true)

return (
<Map // 지도를 표시할 Container
id="map"
center={{
// 지도의 중심좌표
lat: 33.450701,
lng: 126.570667,
}}
style={{
// 지도의 크기
width: "100%",
height: "350px",
}}
level={3} // 지도의 확대 레벨
draggable={draggable}
>
<p>
<button onClick={() => setDraggable(false)}>
지도 드래그 이동 끄기
</button>{" "}
<button onClick={() => setDraggable(true)}>
지도 드래그 이동 켜기
</button>
</p>
</Map>
)
}
5 changes: 5 additions & 0 deletions dev/src/pages/samples/sampleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ChangeLevel from "./changeLevel"
import MapInfo from "./mapInfo"
import AddMapControl from "./addMapControl"
import AddMapCustomControl from "./addMapCustomControl"
import DisableMapDragMove from "./disableMapDragMove"

export const samples: RouteObject[] = [
{
Expand All @@ -31,4 +32,8 @@ export const samples: RouteObject[] = [
path: "addMapCustomControl",
element: <AddMapCustomControl />,
},
{
path: "disableMapDragMove",
element: <DisableMapDragMove />,
},
]
29 changes: 2 additions & 27 deletions docs/docs/sample/map/disableMapDragMove.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,6 @@ sidebar_position: 6

> original docs : https://apis.map.kakao.com/web/sample/disableMapDragMove/
```jsx live
function(){
const Main = () => {
const [draggable, setDraggable] = useState(true)
import codesource from "!!raw-loader!../../../../dev/src/pages/samples/disableMapDragMove.tsx"

return (
<>
<Map // 지도를 표시할 Container
center={{
// 지도의 중심좌표
lat: 37.566826,
lng: 126.9786567,
}}
style={{
width: "100%",
height: "450px",
}}
level={3} // 지도의 확대 레벨
draggable={draggable}
/>
<button onClick={() => setDraggable(false)}>지도 드래그 이동 끄기</button>
<button onClick={() => setDraggable(true)}>지도 드래그 이동 켜기</button>
</>
)
}
return (<Main/>)
}
```
<LiveEditor>{codesource}</LiveEditor>
12 changes: 12 additions & 0 deletions packages/react-kakao-maps-sdk/__test__/basicMap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,16 @@ test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
const url = getUrl("basicMap", testInfo.config.updateSnapshots === "all")
await page.goto(url, { waitUntil: "networkidle" })
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 page.mouse.up()
await page.waitForLoadState("networkidle")
await expect(page).toHaveScreenshot()
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions packages/react-kakao-maps-sdk/__test__/disableMapDragMove.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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(
"disableMapDragMove",
testInfo.config.updateSnapshots === "all",
)
await page.goto(url, { waitUntil: "networkidle" })
await expect(page).toHaveScreenshot()
const firstRenderScreenshot = await page.screenshot()

const drag = async () => {
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 page.mouse.up()
await page.waitForLoadState("networkidle")
}

await page.getByText("지도 드래그 이동 끄기").click()
await drag()
expect(await page.screenshot()).toStrictEqual(firstRenderScreenshot)
await expect(page).toHaveScreenshot()

await page.getByText("지도 드래그 이동 켜기").click()
await drag()
expect(await page.screenshot()).not.toStrictEqual(firstRenderScreenshot)
await expect(page).toHaveScreenshot()
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/react-kakao-maps-sdk/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default defineConfig({

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
viewport: { width: 1280, height: 720 },
},

/* Configure projects for major browsers */
Expand Down

0 comments on commit df5d745

Please sign in to comment.