Skip to content
Snippets Groups Projects
Commit ba39b030 authored by Chris Beer's avatar Chris Beer
Browse files

Fix infoResponsesMatch tests for IIIF v3

parent 5cc17197
No related branches found
No related tags found
No related merge requests found
...@@ -86,6 +86,19 @@ describe('OpenSeadragonViewer', () => { ...@@ -86,6 +86,19 @@ describe('OpenSeadragonViewer', () => {
it('when the @ids do not match', () => { it('when the @ids do not match', () => {
expect(wrapper.instance().infoResponsesMatch([{ id: 'a', json: { '@id': 'http://foo-degraded' } }])).toBe(false); expect(wrapper.instance().infoResponsesMatch([{ id: 'a', json: { '@id': 'http://foo-degraded' } }])).toBe(false);
}); });
it('when the id props match', () => {
wrapper.setProps({
infoResponses: [{
id: 'a',
json: {
height: 200,
id: 'http://foo',
width: 100,
},
}],
});
expect(wrapper.instance().infoResponsesMatch([{ id: 'a', json: { id: 'http://foo' } }])).toBe(true);
});
}); });
describe('nonTiledImagedMatch', () => { describe('nonTiledImagedMatch', () => {
......
...@@ -273,19 +273,25 @@ export class OpenSeadragonViewer extends Component { ...@@ -273,19 +273,25 @@ export class OpenSeadragonViewer extends Component {
*/ */
infoResponsesMatch(prevInfoResponses) { infoResponsesMatch(prevInfoResponses) {
const { infoResponses } = this.props; const { infoResponses } = this.props;
if (infoResponses.length === 0 && prevInfoResponses.length === 0) return true; if (infoResponses.length === 0 && prevInfoResponses.length === 0) return true;
if (infoResponses.length !== prevInfoResponses.length) return false; if (infoResponses.length !== prevInfoResponses.length) return false;
return infoResponses.some((infoResponse, index) => { return infoResponses.every((infoResponse, index) => {
if (!prevInfoResponses[index]) { if (!prevInfoResponses[index]) {
return false; return false;
} }
if (!infoResponse.json) { if (!infoResponse.json || !prevInfoResponses[index].json) {
return false; return false;
} }
if (infoResponse.json['@id'] === (prevInfoResponses[index].json || {})['@id']) { if (infoResponse.json['@id']
&& infoResponse.json['@id'] === prevInfoResponses[index].json['@id']) {
return true;
}
if (infoResponse.json.id
&& infoResponse.json.id === prevInfoResponses[index].json.id) {
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment