Skip to content

Commit

Permalink
Merge pull request #3980 from ProjectMirador/viewer-initiaizer
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne authored Nov 7, 2024
2 parents 44e7b2b + 23b8e24 commit dd5de5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 8 additions & 3 deletions __tests__/src/lib/MiradorViewer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ describe('MiradorViewer', () => {
});
describe('constructor', () => {
it('returns viewer store', () => {
const instance = new MiradorViewer({ id: 'mirador' });
const instance = new MiradorViewer({});

act(() => { instance.renderInto(document.getElementById('mirador')); }); // eslint-disable-line testing-library/no-unnecessary-act
expect(instance.store.dispatch).toBeDefined();
});
it('renders via ReactDOM', () => {
act(() => { new MiradorViewer({ id: 'mirador' }); }); // eslint-disable-line no-new
const instance = new MiradorViewer({});

act(() => { instance.renderInto(document.getElementById('mirador')); }); // eslint-disable-line testing-library/no-unnecessary-act

expect(screen.getByTestId('container')).not.toBeEmptyDOMElement();
});
Expand All @@ -35,7 +39,6 @@ describe('MiradorViewer', () => {
catalog: [
{ manifestId: 'http://media.nga.gov/public/manifests/nga_highlights.json', provider: 'National Gallery of Art' },
],
id: 'mirador',
windows: [
{
canvasId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174892',
Expand All @@ -60,6 +63,8 @@ describe('MiradorViewer', () => {
},
);

act(() => { instance.renderInto(document.getElementById('mirador')); }); // eslint-disable-line testing-library/no-unnecessary-act

const { windows, catalog, config } = instance.store.getState();
const windowIds = Object.keys(windows);
expect(Object.keys(windowIds).length).toBe(2);
Expand Down
16 changes: 11 additions & 5 deletions src/lib/MiradorViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ class MiradorViewer {
this.store = viewerConfig.store
|| createPluggableStore(this.config, this.plugins);

if (config.id) {
this.container = document.getElementById(config.id);
this.root = createRoot(this.container);
if (config.id) this.renderInto(document.getElementById(config.id));
}

/**
* @private
* @param {*} container
*/
renderInto(container) {
this.container = container;
this.root = createRoot(this.container);

this.root.render(this.render());
}
this.root.render(this.render());
}

/**
Expand Down

0 comments on commit dd5de5b

Please sign in to comment.