-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(nucleus): consolidate get/create (#236)
- Loading branch information
Showing
20 changed files
with
268 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
describe('get-object', () => { | ||
const optional = 'optional'; | ||
let context = {}; | ||
let create; | ||
let sandbox; | ||
let init; | ||
let objectModel; | ||
before(() => { | ||
sandbox = sinon.createSandbox(); | ||
init = sandbox.stub(); | ||
[{ default: create }] = aw.mock([['**/initiate.js', () => init]], ['../get-object.js']); | ||
}); | ||
|
||
beforeEach(() => { | ||
objectModel = sandbox.stub(); | ||
init.returns('api'); | ||
context = { app: { id: 'appid', getObject: id => Promise.resolve(objectModel(id)) } }; | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.reset(); | ||
}); | ||
|
||
it('should get object from app only once', async () => { | ||
const model = 'model-x'; | ||
objectModel.withArgs('x').returns(model); | ||
const spy = sandbox.spy(context.app, 'getObject'); | ||
await create({ id: 'x' }, optional, context); | ||
await create({ id: 'x' }, optional, context); | ||
await create({ id: 'x' }, optional, context); | ||
expect(spy.callCount).to.equal(1); | ||
expect(spy).to.have.been.calledWithExactly('x'); | ||
}); | ||
|
||
it('should call init', async () => { | ||
const model = 'model-x'; | ||
objectModel.withArgs('x').returns(model); | ||
const ret = await create({ id: 'x' }, optional, context); | ||
expect(ret).to.equal('api'); | ||
expect(init).to.have.been.calledWithExactly(model, optional, context); | ||
}); | ||
}); |
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,49 @@ | ||
describe('initiate api', () => { | ||
const optional = 'optional'; | ||
const context = 'context'; | ||
const model = 'model'; | ||
let create; | ||
let sandbox; | ||
let viz; | ||
let api; | ||
before(() => { | ||
sandbox = sinon.createSandbox(); | ||
viz = sandbox.stub(); | ||
[{ default: create }] = aw.mock([['**/viz.js', () => viz]], ['../initiate.js']); | ||
}); | ||
|
||
beforeEach(() => { | ||
api = { | ||
mount: sandbox.stub(), | ||
options: sandbox.stub(), | ||
context: sandbox.stub(), | ||
}; | ||
viz.returns(api); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.reset(); | ||
}); | ||
|
||
it('should call viz api', async () => { | ||
const initialError = 'err'; | ||
const ret = await create(model, optional, context, initialError); | ||
expect(viz).to.have.been.calledWithExactly({ model, context, initialError }); | ||
expect(ret).to.equal(api); | ||
}); | ||
|
||
it('should call mount when element is provided ', async () => { | ||
await create(model, { element: 'el' }, context); | ||
expect(api.mount).to.have.been.calledWithExactly('el'); | ||
}); | ||
|
||
it('should call options when provided ', async () => { | ||
await create(model, { options: 'opts' }, context); | ||
expect(api.options).to.have.been.calledWithExactly('opts'); | ||
}); | ||
|
||
it('should call context when provided ', async () => { | ||
await create(model, { context: 'ctx' }, context); | ||
expect(api.context).to.have.been.calledWithExactly('ctx'); | ||
}); | ||
}); |
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,20 @@ | ||
import vizualizationAPI from '../viz'; | ||
|
||
export default async function(model, optional, context, initialError) { | ||
const api = vizualizationAPI({ | ||
model, | ||
context, | ||
initialError, | ||
}); | ||
if (optional.element) { | ||
await api.mount(optional.element); | ||
} | ||
if (optional.options) { | ||
api.options(optional.options); | ||
} | ||
if (optional.context) { | ||
api.context(optional.context); | ||
} | ||
|
||
return api; | ||
} |
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
Oops, something went wrong.