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 19fa31d commit 601503c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 8 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/enhancers/layoutEnhancer/SettingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class SettingsManager<
pageHorizontalMargin,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
pageVerticalMargin,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
layoutLayerTransition,
...rest
} = settings

Expand All @@ -41,6 +43,7 @@ export class SettingsManager<
layoutAutoResize: "container",
pageHorizontalMargin: 24,
pageVerticalMargin: 24,
layoutLayerTransition: true
}
}
}
40 changes: 34 additions & 6 deletions packages/core/src/enhancers/layoutEnhancer/layoutEnhancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
filter,
switchMap,
debounceTime,
delay,
} from "rxjs/operators"
import { createMovingSafePan$ } from "./createMovingSafePan$"
import { mapKeysTo } from "../../utils/rxjs"
Expand All @@ -21,7 +20,7 @@ import { isDefined } from "../../utils/isDefined"
import { SettingsInterface } from "../../settings/SettingsInterface"
import { SettingsManager } from "./SettingsManager"
import { InputSettings, OutputSettings } from "./types"
import { animationFrameScheduler, merge, Observable } from "rxjs"
import { merge, Observable } from "rxjs"
import { detectMimeTypeFromName } from "@prose-reader/shared"
import { upsertCSS } from "../../utils/frames"

Expand All @@ -45,8 +44,12 @@ export const layoutEnhancer =
next: (options: InheritOptions) => InheritOutput,
) =>
(options: InheritOptions & Partial<InputSettings>): Output => {
const { pageHorizontalMargin, pageVerticalMargin, layoutAutoResize } =
options
const {
pageHorizontalMargin,
pageVerticalMargin,
layoutAutoResize,
layoutLayerTransition,
} = options
const reader = next(options)

const settingsManager = new SettingsManager<
Expand All @@ -57,6 +60,7 @@ export const layoutEnhancer =
pageHorizontalMargin,
pageVerticalMargin,
layoutAutoResize,
layoutLayerTransition,
},
reader.settings as SettingsInterface<
InheritSettings,
Expand Down Expand Up @@ -163,7 +167,9 @@ export const layoutEnhancer =
* Hide document until it's ready
*/
element.style.opacity = `0`
element.style.transition = `opacity 300ms`
if (settingsManager.values.layoutLayerTransition) {
element.style.transition = `opacity 300ms`
}
})
})

Expand Down Expand Up @@ -234,7 +240,29 @@ export const layoutEnhancer =
)
.subscribe()

merge(revealItemOnReady$, movingSafePan$, layoutOnContainerResize$)
/**
* Apply some extra classes to spine item to help debugging,
* styling, testing, etc.
*/
const updateSpineItemClassName$ =
reader.spineItemsObserver.itemIsReady$.pipe(
tap(({ item, isReady }) => {
const className = `prose-spineItem-ready`

if (isReady) {
item.containerElement.classList.add(className)
} else {
item.containerElement.classList.remove(className)
}
}),
)

merge(
updateSpineItemClassName$,
revealItemOnReady$,
movingSafePan$,
layoutOnContainerResize$,
)
.pipe(takeUntil(reader.$.destroy$))
.subscribe()

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/enhancers/layoutEnhancer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export type InputSettings = {
* `false`: do not automatically resize.
*/
layoutAutoResize: `container` | false
/**
* Whether to use a CSS transition when spine item is ready.
*/
layoutLayerTransition: boolean
}

export type OutputSettings = InputSettings
1 change: 1 addition & 0 deletions packages/tests/tests/bookmarks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async function run() {

const reader = createReaderWithEnhancers({
pageTurnAnimation: "none",
layoutLayerTransition: false,
pdf: {
pdfjsViewerInlineCss,
getArchiveForItem: () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/tests/tests/bookmarks/pdf.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ test("should be able to mark bookmarks on pdf (no nodes)", async ({ page }) => {

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

await page.waitForTimeout(500)
// wait for first item to be ready
await page.waitForSelector(".prose-spineItem-ready")

await page.keyboard.press("ArrowRight")

Expand Down
1 change: 1 addition & 0 deletions packages/tests/tests/text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async function run() {
const reader = createReaderWithEnhancers({
pageTurnAnimation: "none",
getResource: (item) => from(streamer.fetchResource({ key: `_`, resourcePath: item.href })),
layoutLayerTransition: false
})

reader.load({
Expand Down
3 changes: 2 additions & 1 deletion packages/tests/tests/text/text.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ test("should display basic text", async ({ page }) => {

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

await page.waitForTimeout(1000)
// wait for first item to be ready
await page.waitForSelector(".prose-spineItem-ready")

expect(await page.screenshot()).toMatchSnapshot(`text.png`)
})

0 comments on commit 601503c

Please sign in to comment.