-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from kadirahq/tests
Write test cases for dataStore
- Loading branch information
Showing
3 changed files
with
74 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// import { shallow, mount } from 'enzyme'; | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import addons from '@kadira/storybook-addons'; | ||
import DataStore from '../manager/containers/CommentsPanel/dataStore'; | ||
|
||
const { describe, it } = global; | ||
|
||
const dbGetPromiseReturn = sinon.stub(); | ||
const dbSetPromiseReturn = sinon.stub(); | ||
|
||
const myDb = { | ||
getCollection() { | ||
return { | ||
get() { | ||
return new Promise(dbGetPromiseReturn); | ||
}, | ||
set() { | ||
return new Promise(dbSetPromiseReturn); | ||
}, | ||
}; | ||
}, | ||
}; | ||
addons.setDatabase(myDb); | ||
|
||
const db = addons.getDatabase(); | ||
const theStore = new DataStore(db); | ||
|
||
describe('DataStore', () => { | ||
|
||
it('set current story - when user not logged in', () => { | ||
theStore.setCurrentStory('Components', 'CommentList - No Comments'); | ||
|
||
expect(dbGetPromiseReturn.called).to.equal(false); | ||
expect(theStore.currentStory).to.deep.equal({ sbKind: 'Components', sbStory: 'CommentList - No Comments' }); | ||
}); | ||
|
||
it('set current user', () => { | ||
theStore.setCurrentUser({ | ||
id: 'user-id', | ||
name: 'user-name', | ||
}); | ||
|
||
expect(theStore.user).to.deep.equal({ id: 'user-id', name: 'user-name' }); | ||
}); | ||
|
||
it('set current story - when user already logged in', () => { | ||
theStore.setCurrentStory('Components', 'CommentList - No Comments'); | ||
|
||
expect(dbGetPromiseReturn.called).to.equal(true); | ||
expect(theStore.currentStory).to.deep.equal({ sbKind: 'Components', sbStory: 'CommentList - No Comments' }); | ||
}); | ||
|
||
it('add comment', () => { | ||
const comment = { | ||
text: 'sample comment', | ||
time: 1476435982029, | ||
userId: 'user-id', | ||
}; | ||
|
||
theStore.addComment(comment); | ||
|
||
expect(dbGetPromiseReturn.called).to.equal(true); | ||
expect(dbSetPromiseReturn.called).to.equal(true); | ||
}); | ||
|
||
it('onComments', () => { | ||
theStore.onComments((comments) => { | ||
return comments; | ||
}); | ||
expect(dbGetPromiseReturn.called).to.equal(true); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.