Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ const onWheelEvent = (e: WheelEvent) => {
}

const setTransform = ({ scale, x, y }: { scale: number; x: number; y: number }) => {
// panzoom calls this deferred, possibly after it got destroyed on unmount
if (!unref(panzoom)) {
return
}

let h: number
let v: number

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defaultPlugins, shallowMount } from '@opencloud-eu/web-test-helpers'
import { flushPromises } from '@vue/test-utils'
import { Resource } from '@opencloud-eu/web-client'
import { MediaFile } from '../../../src/helpers/types'
import Panzoom, { PanzoomOptions } from '@panzoom/panzoom'

// panzoom touches real DOM geometry which jsdom does not provide
const panzoom = {
Expand All @@ -13,7 +14,7 @@ const panzoom = {
getScale: () => 1,
getPan: () => ({ x: 0, y: 0 })
}
vi.mock('@panzoom/panzoom', () => ({ default: () => panzoom }))
vi.mock('@panzoom/panzoom', () => ({ default: vi.fn(() => panzoom) }))

const mediaFile = (mimeType: string): MediaFile =>
({
Expand Down Expand Up @@ -92,6 +93,19 @@ describe('MediaImage component', () => {
})
})

it('ignores a deferred panzoom transform after unmount', async () => {
const { wrapper } = getWrapper('image/png')
await flushPromises()
const { setTransform } = vi.mocked(Panzoom).mock.calls[0][1] as PanzoomOptions

wrapper.unmount()

expect(() =>
setTransform(document.createElement('div'), { scale: 1, x: 0, y: 0 }, {})
).not.toThrow()
expect(panzoom.setStyle).not.toHaveBeenCalled()
})

it('reports an image the browser cannot decode', async () => {
const { wrapper } = getWrapper('image/heic')

Expand Down
Loading