Skip to content

Commit

Permalink
Merge pull request #4062 from ProjectMirador/flaky-viewer-test-debug
Browse files Browse the repository at this point in the history
Fix CI testing flakiness
  • Loading branch information
marlo-longley authored Dec 18, 2024
2 parents 41e2a86 + f7fed3e commit 644b804
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
export default {
id: 'mirador',
theme: {
transitions: window.location.port === '4488' ? { create: () => 'none' } : {},
},
windows: [{
canvasId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174892',
initialViewerConfig: {
Expand Down
24 changes: 15 additions & 9 deletions __tests__/integration/mirador/tests/viewer-config.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { expect, it } from 'vitest';
import { screen } from '@testing-library/react';
import { screen, waitFor } from '@testing-library/react';
import { setupIntegrationTestViewer } from '@tests/utils/test-utils';
import config from '../mirador-configs/initial-viewer-config';

describe('initialViewerConfig', () => {
setupIntegrationTestViewer(config);

it('allows initialViewerConfig to be passed', async (context) => {
expect(await screen.findByRole('region', { name: /Window: Self-Portrait Dedicated to Paul Gauguin/i })).toBeInTheDocument();
describe('initialViewerConfig', () => {
it('allows initialViewerConfig to be passed', async (context) => {
expect(await screen.findByRole('region', { name: /Window: Self-Portrait Dedicated to Paul Gauguin/i })).toBeInTheDocument();

const { viewers } = context.miradorInstance.store.getState();
const viewerObject = viewers[Object.keys(viewers)[0]];
// You can see these values passed in initial-viewer-config.js
expect(viewerObject.x).toBe(934);
expect(viewerObject.y).toBe(782);
expect(viewerObject.zoom).toBe(0.0007);
let viewerObject;
await waitFor(() => {
const { viewers = {} } = context.miradorInstance.store.getState();
viewerObject = viewers[Object.keys(viewers)[0]];
expect(viewerObject?.x).toBe(934);
}, { timeout: 3000 });

expect(viewerObject.x).toBe(934);
expect(viewerObject.y).toBe(782);
expect(viewerObject.zoom).toBe(0.0007);
});
});
});
4 changes: 3 additions & 1 deletion src/components/OpenSeadragonComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function OpenSeadragonComponent({
const onViewportChange = useCallback((event) => {
const { viewport } = event.eventSource;

if (!initialViewportSet.current) return;

onUpdateViewport({
bounds: viewport.getBounds(),
flip: viewport.getFlip(),
Expand All @@ -35,7 +37,7 @@ function OpenSeadragonComponent({
y: Math.round(viewport.centerSpringY.target.value),
zoom: viewport.zoomSpring.target.value,
});
}, [onUpdateViewport]);
}, [onUpdateViewport, initialViewportSet]);

const setInitialBounds = useCallback(({ viewport }) => {
if (initialViewportSet.current) return;
Expand Down

0 comments on commit 644b804

Please sign in to comment.