Skip to content

Commit

Permalink
Fix: updating metadata from repStatus (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press authored Apr 12, 2017
1 parent 762fad8 commit 51143b0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/lib/RepStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class RepStatus extends EventEmitter {
.then((info) => {
clearTimeout(this.statusTimeout);

if (info.metadata) {
this.representation.metadata = info.metadata;
}

const status = (typeof info.status === 'object') ? info.status.state : info.temp_status.state;
if (typeof this.representation.status === 'object') {
this.representation.status.state = status;
Expand Down
25 changes: 23 additions & 2 deletions src/lib/__tests__/RepStatus-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,43 @@ describe('lib/RepStatus', () => {
});

describe('updateStatus()', () => {
const state = 'success';
beforeEach(() => {
sandbox.stub(repStatus, 'handleResponse');
});

it('should fetch latest status', () => {
const state = 'success';
sandbox.mock(util).expects('get').returns(Promise.resolve({
status: {
state
}
}));

sandbox.mock(window).expects('clearTimeout').withArgs(repStatus.statusTimeout);
sandbox.stub(repStatus, 'handleResponse');

return repStatus.updateStatus().then(() => {
expect(repStatus.representation.status.state).to.equal(state);
expect(repStatus.handleResponse).to.be.called;
});
});

it('should update provided metadata', () => {
sandbox.mock(util).expects('get').returns(Promise.resolve({
status: {
state
},
metadata: {
pages: 10
}
}));

return repStatus.updateStatus().then(() => {
expect(repStatus.representation.status.state).to.equal(state);
expect(repStatus.handleResponse).to.be.called;
expect(repStatus.representation.metadata.pages).to.equal(10);
});
});

it('should return a resolved promise if there is no info url', () => {
sandbox.mock(util).expects('get').never();
repStatus.infoUrl = '';
Expand Down
7 changes: 3 additions & 4 deletions src/lib/viewers/image/MultiImageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,15 @@ class MultiImageViewer extends ImageBaseViewer {
this.setup();
super.load();

const template = this.options.representation.content.url_template;
this.imageUrls = this.constructImageUrls(template);


// Hides images until content is loaded
this.imageEl.classList.add(CLASS_INVISIBLE);
this.bindImageListeners(0);
this.bindDOMListeners();

return this.getRepStatus().getPromise().then(() => {
const template = this.options.representation.content.url_template;
this.imageUrls = this.constructImageUrls(template);

this.imageUrls.forEach((imageUrl, index) => this.setupImageEls(imageUrl, index));
}).catch(this.handleAssetError);
}
Expand Down

0 comments on commit 51143b0

Please sign in to comment.