Skip to content

Commit

Permalink
✅ Move common test function to util.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
JaeSeoKim committed Jan 19, 2024
1 parent 101895b commit 27ffe9a
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 158 deletions.
10 changes: 3 additions & 7 deletions packages/react-kakao-maps-sdk/__test__/addMapClickEvent.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
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}`
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

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

const mapBoundingBox = await page.locator("#map").boundingBox()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
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}`
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
const url = getUrl(
const url = getTestUrl(
"addMapClickEventWithMarker",
testInfo.config.updateSnapshots === "all",
)
await page.goto(url, { waitUntil: "networkidle" })
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot({
maxDiffPixels: 120, // map의 center값을 넘겼지만, `map.getCenter()` 시 넘어오는 값이 정확하게 일치하지 않아서 fail 나는 부분을 무시
})
Expand Down
11 changes: 5 additions & 6 deletions packages/react-kakao-maps-sdk/__test__/addMapControl.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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}`
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
const url = getUrl("addMapControl", testInfo.config.updateSnapshots === "all")
const url = getTestUrl(
"addMapControl",
testInfo.config.updateSnapshots === "all",
)
await page.goto(url, { waitUntil: "networkidle" })
await expect(page.getByRole("button", { name: "확대" })).toBeAttached()
await expect(page.getByRole("button", { name: "축소" })).toBeAttached()
Expand Down
16 changes: 6 additions & 10 deletions packages/react-kakao-maps-sdk/__test__/addMapCustomControl.spec.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
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}`
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

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

await page.locator("#btnSkyview").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot()

await page.locator("#btnRoadmap").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot()

await page.getByAltText("확대").click()
await page.getByAltText("확대").click()
await page.getByAltText("확대").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot()

await page.getByAltText("축소").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot()
})
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
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}`
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
const url = getUrl(
const url = getTestUrl(
"addRoadviewOverlay",
testInfo.config.updateSnapshots === "all",
)
Expand All @@ -22,6 +18,6 @@ test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
mapBoundingBox!.y + mapBoundingBox!.height / 2,
)
await page.mouse.up()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot()
})
10 changes: 3 additions & 7 deletions packages/react-kakao-maps-sdk/__test__/addTerrainOverlay.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
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}`
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
const url = getUrl(
const url = getTestUrl(
"addTerrainOverlay",
testInfo.config.updateSnapshots === "all",
)
Expand All @@ -22,6 +18,6 @@ test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
mapBoundingBox!.y + mapBoundingBox!.height / 2,
)
await page.mouse.up()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot()
})
10 changes: 3 additions & 7 deletions packages/react-kakao-maps-sdk/__test__/addTrafficOverlay.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
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}`
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
const url = getUrl(
const url = getTestUrl(
"addTrafficOverlay",
testInfo.config.updateSnapshots === "all",
)
Expand All @@ -24,7 +20,7 @@ test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
mapBoundingBox!.y + mapBoundingBox!.height / 2,
)
await page.mouse.up()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot({
maxDiffPixelRatio: 0.01,
})
Expand Down
10 changes: 3 additions & 7 deletions packages/react-kakao-maps-sdk/__test__/basicMap.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
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}`
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

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

Expand All @@ -19,6 +15,6 @@ test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
mapBoundingBox!.y + mapBoundingBox!.height / 2,
)
await page.mouse.up()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot()
})
15 changes: 7 additions & 8 deletions packages/react-kakao-maps-sdk/__test__/changeLevel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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}`
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
const url = getUrl("changeLevel", testInfo.config.updateSnapshots === "all")
const url = getTestUrl(
"changeLevel",
testInfo.config.updateSnapshots === "all",
)
await page.goto(url, { waitUntil: "networkidle" })
await expect(page.locator("#maplevel")).toHaveText(
"현재 지도 레벨은 3 레벨 입니다.",
Expand All @@ -19,14 +18,14 @@ test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
await expect(page.locator("#maplevel")).toHaveText(
"현재 지도 레벨은 6 레벨 입니다.",
)
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot()

await page.getByText("지도레벨 - 1").click()
await page.getByText("지도레벨 - 1").click()
await expect(page.locator("#maplevel")).toHaveText(
"현재 지도 레벨은 4 레벨 입니다.",
)
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot()
})
18 changes: 7 additions & 11 deletions packages/react-kakao-maps-sdk/__test__/changeOverlay1.spec.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
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}`
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

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

await page.getByText("교통정보 보기").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot({
maxDiffPixelRatio: 0.01,
})

await page.getByText("로드뷰 도로정보 보기").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot({
maxDiffPixelRatio: 0.01,
})

await page.getByText("지형정보 보기").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot({
maxDiffPixelRatio: 0.01,
})

await page.getByText("지적편집도 보기").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot({
maxDiffPixelRatio: 0.01,
})
Expand Down
20 changes: 8 additions & 12 deletions packages/react-kakao-maps-sdk/__test__/changeOverlay2.spec.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
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}`
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

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

await page.locator("#chkUseDistrict").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot({
maxDiffPixelRatio: 0.01,
})

await page.locator("#chkTerrain").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot({
maxDiffPixelRatio: 0.01,
})

await page.locator("#chkTraffic").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot({
maxDiffPixelRatio: 0.01,
})

await page.locator("#chkBicycle").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot({
maxDiffPixelRatio: 0.01,
})

await page.locator("#chkTerrain").click()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
await expect(page).toHaveScreenshot({
maxDiffPixelRatio: 0.01,
})
Expand Down
17 changes: 4 additions & 13 deletions packages/react-kakao-maps-sdk/__test__/disableMapDragMove.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { test, expect, Page } from "@playwright/test"

const waitNetworkIdleWithTimeout = async (page: Page, timeout?: number) => {
await page.waitForLoadState("networkidle")
await page.waitForTimeout(timeout ?? 300)
}

const getUrl = (id: string, isUpdateSanpShots: boolean = false) =>
isUpdateSanpShots
? `http://127.0.0.1:5252/samples/${id}.html`
: `/samples/${id}`
import { test, expect } from "@playwright/test"
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
const url = getUrl(
const url = getTestUrl(
"disableMapDragMove",
testInfo.config.updateSnapshots === "all",
)
Expand All @@ -28,7 +19,7 @@ test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
mapBoundingBox!.y + mapBoundingBox!.height / 2,
)
await page.mouse.up()
await page.waitForLoadState("networkidle")
await waitNetworkIdleWithTimeout(page)
}

await page.getByText("지도 드래그 이동 끄기").click()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { test, expect, Page } from "@playwright/test"

const waitNetworkIdleWithTimeout = async (page: Page, timeout?: number) => {
await page.waitForLoadState("networkidle")
await page.waitForTimeout(timeout ?? 300)
}

const getUrl = (id: string, isUpdateSanpShots: boolean = false) =>
isUpdateSanpShots
? `http://127.0.0.1:5252/samples/${id}.html`
: `/samples/${id}`
import { test, expect } from "@playwright/test"
import { getTestUrl, waitNetworkIdleWithTimeout } from "./util"

test("ScreenShot 렌더링 결과 비교", async ({ page }, testInfo) => {
const url = getUrl(
const url = getTestUrl(
"enableDisableZoomInOut",
testInfo.config.updateSnapshots === "all",
)
Expand Down
Loading

0 comments on commit 27ffe9a

Please sign in to comment.