Skip to content

Commit

Permalink
fix: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbret committed Nov 30, 2024
1 parent 4939995 commit 84436d4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"dependencies": {
"@vitejs/plugin-react": "^4.3.3",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"pdfjs-dist": "^4.7.76"
}
}
17 changes: 9 additions & 8 deletions packages/tests/tests/bookmarks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,34 @@ import { bookmarksEnhancer, RuntimeBookmark } from "@prose-reader/enhancer-bookm
import { createArchiveFromPdf, pdfEnhancer } from "@prose-reader/enhancer-pdf"
import * as pdfjsLib from "pdfjs-dist"
import pdfWorkerUrl from "pdfjs-dist/build/pdf.worker.min.mjs?url"
import { of } from "rxjs"
import { of, switchMap } from "rxjs"
import { createRoot } from "react-dom/client"
import { useEffect, useState } from "react"
import { gesturesEnhancer } from "@prose-reader/enhancer-gestures"
import pdfjsViewerInlineCss from "pdfjs-dist/web/pdf_viewer.css?inline"

pdfjsLib.GlobalWorkerOptions.workerSrc = new URL(pdfWorkerUrl, import.meta.url).toString()

async function run() {
const response = await fetch("http://localhost:3333/epubs/sample-3.pdf")
const pdfBlob = await response.blob()
const archive = await createArchiveFromPdf(pdfBlob)

const manifest = await generateManifestFromArchive(archive)

const createReaderWithEnhancers = gesturesEnhancer(pdfEnhancer(bookmarksEnhancer(createReader)))

const reader = createReaderWithEnhancers({
pageTurnAnimation: "none",
pdf: {
pdfjsViewerInlineCss,
getArchiveForItem: () => {
return of(archive)
},
},
})

const Bookmarks = () => {
const [bookmarks, setBookmarks] = useState<RuntimeBookmark[]>([])
const [bookmarks, setBookmarks] = useState<{ meta?: { absolutePageIndex?: number | undefined } }[]>([])
const [pagination, setPagination] = useState<{ beginAbsolutePageIndex?: number }>({ beginAbsolutePageIndex: 0 })

useEffect(() => {
Expand All @@ -40,12 +41,12 @@ async function run() {
}, [])

useEffect(() => {
reader.bookmarks.bookmarks$.subscribe((bookmarks) => {
setBookmarks(bookmarks)
reader.bookmarks.bookmarks$.pipe(switchMap((bookmarks) => reader.pagination.locate(bookmarks))).subscribe(({ data }) => {
setBookmarks(data)
})
}, [])
}, [reader])

const bookmarkForPage = bookmarks?.find((bookmark) => bookmark.absolutePageIndex === pagination.beginAbsolutePageIndex)
const bookmarkForPage = bookmarks?.find((bookmark) => bookmark.meta?.absolutePageIndex === pagination.beginAbsolutePageIndex)

return (
<button
Expand All @@ -61,7 +62,7 @@ async function run() {
color: "white",
}}
onClick={() => {
reader.bookmarks.addBookmark({ absolutePageIndex: pagination.beginAbsolutePageIndex ?? 0 })
reader.bookmarks.bookmark(pagination.beginAbsolutePageIndex ?? 0)
}}
>
Page {pagination.beginAbsolutePageIndex}
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/tests/text/text.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test("should display basic text", async ({ page }) => {

await page.goto("http://localhost:3333/tests/text/index.html")

await page.waitForTimeout(500)
await page.waitForTimeout(1000)

expect(await page.screenshot()).toMatchSnapshot(`text.png`)
})
2 changes: 2 additions & 0 deletions packages/tests/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="vite/client" />
/// <reference types="vite-plugin-svgr/client" />

0 comments on commit 84436d4

Please sign in to comment.