-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: Show banner when doc has xrefs (#1013)
- Loading branch information
1 parent
6b72ec9
commit 6f9fca7
Showing
9 changed files
with
150 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import DocumentViewer from './DocumentViewer'; | ||
import metadataAPI from '../../metadataAPI'; | ||
import { METADATA } from '../../constants'; | ||
|
||
const { FIELD_HASXREFS, TEMPLATE_AUTOCAD } = METADATA; | ||
|
||
class AutoCADViewer extends DocumentViewer { | ||
/** | ||
* @inheritdoc | ||
*/ | ||
load() { | ||
super.load(); | ||
|
||
this.checkForXrefs(); | ||
} | ||
|
||
/** | ||
* Checks for xrefs, depending on file extension | ||
* @return {void} | ||
*/ | ||
checkForXrefs() { | ||
const { id } = this.options.file; | ||
|
||
metadataAPI.getXrefsMetadata(id, TEMPLATE_AUTOCAD, this.options).then(({ [FIELD_HASXREFS]: hasxrefsValue }) => { | ||
if (hasxrefsValue) { | ||
this.options.ui.showNotification(__('has_x_refs'), null, true); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export default AutoCADViewer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
import DocumentViewer from '../DocumentViewer'; | ||
import AutoCADViewer from '../AutoCADViewer'; | ||
import metadataAPI from '../../../metadataAPI'; | ||
import { METADATA } from '../../../constants'; | ||
|
||
const { FIELD_HASXREFS, TEMPLATE_AUTOCAD } = METADATA; | ||
const sandbox = sinon.sandbox.create(); | ||
|
||
let containerEl; | ||
let autocad; | ||
let stubs = {}; | ||
|
||
describe('lib/viewers/doc/AutoCADViewer', () => { | ||
beforeEach(() => { | ||
containerEl = document.querySelector('.container'); | ||
autocad = new AutoCADViewer({ | ||
container: containerEl, | ||
file: { | ||
id: '0' | ||
} | ||
}); | ||
|
||
stubs.getXrefsMetadata = sandbox.stub(metadataAPI, 'getXrefsMetadata'); | ||
stubs.showNotification = sandbox.stub(); | ||
|
||
autocad.options = { | ||
file: { | ||
id: '123' | ||
}, | ||
ui: { | ||
showNotification: stubs.showNotification | ||
} | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.verifyAndRestore(); | ||
fixture.cleanup(); | ||
stubs = {}; | ||
}); | ||
|
||
describe('load()', () => { | ||
it('Should call the super.load and checkForXrefs', () => { | ||
stubs.docLoad = sandbox.stub(DocumentViewer.prototype, 'load'); | ||
stubs.checkForXrefs = sandbox.stub(autocad, 'checkForXrefs'); | ||
|
||
autocad.load(); | ||
|
||
expect(stubs.docLoad).to.have.been.called; | ||
expect(stubs.checkForXrefs).to.have.been.called; | ||
}); | ||
}); | ||
|
||
describe('checkForXrefs()', () => { | ||
it('Should show notification if has external refs', () => { | ||
const xrefsPromise = Promise.resolve({ [FIELD_HASXREFS]: true }); | ||
stubs.getXrefsMetadata.resolves(xrefsPromise); | ||
|
||
autocad.checkForXrefs(); | ||
|
||
expect(stubs.getXrefsMetadata).to.have.been.calledWith('123', TEMPLATE_AUTOCAD, autocad.options); | ||
|
||
return xrefsPromise.then(() => { | ||
expect(stubs.showNotification).to.have.been.called; | ||
}); | ||
}); | ||
|
||
it('Should not show notification if does not have external refs', () => { | ||
const xrefsPromise = Promise.resolve({ [FIELD_HASXREFS]: false }); | ||
stubs.getXrefsMetadata.resolves(xrefsPromise); | ||
|
||
autocad.checkForXrefs(); | ||
|
||
expect(stubs.getXrefsMetadata).to.have.been.calledWith('123', TEMPLATE_AUTOCAD, autocad.options); | ||
|
||
return xrefsPromise.then(() => { | ||
expect(stubs.showNotification).not.to.have.been.called; | ||
}); | ||
}); | ||
}); | ||
}); |