-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20a91cd
commit b71b263
Showing
1 changed file
with
142 additions
and
0 deletions.
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
apis/nucleus/src/components/__tests__/nebulaapp.spec.jsx
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,142 @@ | ||
const mockedReactDOM = { render: sinon.stub() }; | ||
const [{ default: boot }] = aw.mock([[require.resolve('react-dom'), () => mockedReactDOM]], ['../NebulaApp']); | ||
|
||
describe('<NebulaApp />', () => { | ||
let sandbox; | ||
|
||
beforeEach(() => { | ||
mockedReactDOM.render.reset(); | ||
sandbox = sinon.createSandbox(); | ||
const mockedElement = { | ||
style: {}, | ||
setAttribute: sandbox.spy(), | ||
appendChild: sandbox.spy(), | ||
}; | ||
global.document = { | ||
createElement: sandbox.stub().returns(mockedElement), | ||
body: mockedElement, | ||
}; | ||
}); | ||
afterEach(() => { | ||
sandbox.restore(); | ||
delete global.document; | ||
}); | ||
|
||
it('should render default', () => { | ||
boot({ app: { id: 'foo' } }); | ||
expect(mockedReactDOM.render.callCount).to.equal(1); | ||
}); | ||
it('should return api', () => { | ||
const api = boot({ app: { id: 'foo' } }); | ||
expect(api.add).to.be.a('function'); | ||
expect(api.remove).to.be.a('function'); | ||
expect(api.theme).to.be.a('function'); | ||
expect(api.direction).to.be.a('function'); | ||
}); | ||
it('should add', () => { | ||
const app = { id: 'foo' }; | ||
const translator = {}; | ||
const api = boot({ app, translator }); | ||
api.add('foo'); | ||
expect(mockedReactDOM.render).to.have.been.calledWith( | ||
sinon.match({ | ||
props: { | ||
app, | ||
translator, | ||
children: ['foo'], | ||
}, | ||
}) | ||
); | ||
}); | ||
it('should remove', () => { | ||
const app = { id: 'foo' }; | ||
const translator = {}; | ||
const api = boot({ app, translator }); | ||
api.add('foo'); | ||
expect(mockedReactDOM.render).to.have.been.calledWith( | ||
sinon.match({ | ||
props: { | ||
app, | ||
translator, | ||
children: ['foo'], | ||
}, | ||
}) | ||
); | ||
api.remove('bar'); | ||
expect(mockedReactDOM.render).to.have.been.calledWith( | ||
sinon.match({ | ||
props: { | ||
app, | ||
translator, | ||
children: ['foo'], | ||
}, | ||
}) | ||
); | ||
api.remove('foo'); | ||
expect(mockedReactDOM.render).to.have.been.calledWith( | ||
sinon.match({ | ||
props: { | ||
app, | ||
translator, | ||
children: [], | ||
}, | ||
}) | ||
); | ||
}); | ||
it('should theme', () => { | ||
const app = { id: 'foo' }; | ||
const translator = {}; | ||
const api = boot({ app, translator }); | ||
api.add('foo'); | ||
expect(mockedReactDOM.render).to.have.been.calledWith( | ||
sinon.match({ | ||
props: { | ||
app, | ||
translator, | ||
children: ['foo'], | ||
themeName: 'light', | ||
}, | ||
}) | ||
); | ||
mockedReactDOM.render.reset(); | ||
api.theme('baz'); | ||
expect(mockedReactDOM.render).to.have.been.calledWith( | ||
sinon.match({ | ||
props: { | ||
app, | ||
translator, | ||
children: ['foo'], | ||
themeName: 'baz', | ||
}, | ||
}) | ||
); | ||
}); | ||
it('should direction', () => { | ||
const app = { id: 'foo' }; | ||
const translator = {}; | ||
const api = boot({ app, translator }); | ||
api.add('foo'); | ||
expect(mockedReactDOM.render).to.have.been.calledWith( | ||
sinon.match({ | ||
props: { | ||
app, | ||
translator, | ||
children: ['foo'], | ||
direction: undefined, | ||
}, | ||
}) | ||
); | ||
mockedReactDOM.render.reset(); | ||
api.direction('rtl'); | ||
expect(mockedReactDOM.render).to.have.been.calledWith( | ||
sinon.match({ | ||
props: { | ||
app, | ||
translator, | ||
children: ['foo'], | ||
direction: 'rtl', | ||
}, | ||
}) | ||
); | ||
}); | ||
}); |