diff --git a/src/manager/containers/CommentsPanel/dataStore.js b/src/manager/containers/CommentsPanel/dataStore.js index 884c6b67aa9f..c1268f8ae196 100644 --- a/src/manager/containers/CommentsPanel/dataStore.js +++ b/src/manager/containers/CommentsPanel/dataStore.js @@ -59,7 +59,7 @@ export default class DataStore { this.currentStory = { sbKind, sbStory }; // We don't need to do anything if the there's no loggedIn user. - if(!this.user) return; + if (!this.user) return; this._reloadCurrentComments(); const item = this._getFromCache(this.currentStory); diff --git a/src/tests/dataStore.js b/src/tests/dataStore.js new file mode 100644 index 000000000000..5cd8b0729dc1 --- /dev/null +++ b/src/tests/dataStore.js @@ -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); + }); +}); diff --git a/src/tests/index.js b/src/tests/index.js deleted file mode 100644 index 48f5b1e316cc..000000000000 --- a/src/tests/index.js +++ /dev/null @@ -1,29 +0,0 @@ -import React from 'react'; -import { shallow, mount } from 'enzyme'; -import { expect } from 'chai'; -import sinon from 'sinon'; -import Button from '../index'; - -const { describe, it } = global; - -describe('Button', () => { - it('should show the given text', () => { - const text = 'The Text'; - const wrapper = shallow(); - expect(wrapper.text()).to.be.equal(text); - }); - - it('should handle the click event', () => { - const clickMe = sinon.stub(); - // Here we do a JSDOM render. So, that's why we need to - // wrap this with a div. - const wrapper = mount( -