Skip to content

Commit 0ab1393

Browse files
committed
feat: added tests for RTL navigation
1 parent e35c7e3 commit 0ab1393

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>foo</title>
8+
9+
<style>
10+
body,
11+
html,
12+
#app {
13+
margin: 0;
14+
padding: 0;
15+
width: 100%;
16+
height: 100%;
17+
overflow: hidden;
18+
}
19+
</style>
20+
</head>
21+
<body>
22+
<div id="app"></div>
23+
<div id="bookmarks"></div>
24+
<script type="module" src="./index.tsx"></script>
25+
</body>
26+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { createReader } from "@prose-reader/core"
2+
import { Streamer, createArchiveFromJszip } from "@prose-reader/streamer"
3+
import { loadAsync } from "jszip"
4+
import { from } from "rxjs"
5+
6+
async function createStreamer() {
7+
const streamer = new Streamer({
8+
getArchive: async () => {
9+
const epubResponse = await fetch(
10+
"http://localhost:3333/epubs/haruko-html-jpeg.epub",
11+
)
12+
const epubBlob = await epubResponse.blob()
13+
const epubJszip = await loadAsync(epubBlob)
14+
const archive = await createArchiveFromJszip(epubJszip)
15+
16+
return archive
17+
},
18+
})
19+
20+
return streamer
21+
}
22+
23+
async function run() {
24+
const streamer = await createStreamer()
25+
const manifestResponse = await streamer.fetchManifest({
26+
key: `_`,
27+
})
28+
const manifest = await manifestResponse.json()
29+
30+
const reader = createReader({
31+
pageTurnAnimation: "none",
32+
layoutLayerTransition: false,
33+
getResource: (item) => {
34+
return from(streamer.fetchResource({ key: `_`, resourcePath: item.href }))
35+
},
36+
})
37+
38+
const query = new URLSearchParams(window.location.search)
39+
const cfi = query.get("cfi") || undefined
40+
41+
reader.load({
42+
// biome-ignore lint/style/noNonNullAssertion: <explanation>
43+
containerElement: document.getElementById(`app`)!,
44+
manifest,
45+
cfi,
46+
})
47+
48+
// @ts-expect-error export for debug
49+
window.reader = reader
50+
}
51+
52+
run()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { test } from "@playwright/test"
2+
import {
3+
expectSpineItemsInViewport,
4+
turnLeft,
5+
waitForSpineItemReady,
6+
} from "../../../utils"
7+
8+
const parameters = [
9+
["odd", { width: 323, height: 671 }],
10+
["even", { width: 322, height: 671 }],
11+
] as const
12+
13+
parameters.forEach(([type, { width, height }]) => {
14+
test.describe(`Given single page book with an ${type} width for the page`, () => {
15+
test.describe("When the user turns left", () => {
16+
test("should navigate to the left page", async ({ page }) => {
17+
await page.setViewportSize({
18+
width,
19+
height,
20+
})
21+
22+
await page.goto(
23+
`http://localhost:3333/tests/navigation/manual/rtl-haruko/index.html`,
24+
)
25+
26+
// Wait for both spine items to be ready
27+
await waitForSpineItemReady(page, [0])
28+
29+
await turnLeft({ page })
30+
31+
await expectSpineItemsInViewport({
32+
page,
33+
indexes: [1],
34+
})
35+
})
36+
})
37+
})
38+
})

packages/tests/tests/utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ export const expectSpineItemsInViewport = async ({
6161
export const turnRight = async ({ page }: { page: Page }) => {
6262
await page.keyboard.press("ArrowRight")
6363
}
64+
65+
export const turnLeft = async ({ page }: { page: Page }) => {
66+
await page.keyboard.press("ArrowLeft")
67+
}

0 commit comments

Comments
 (0)