Skip to content

Commit

Permalink
Merge pull request #41 from kadirahq/tests
Browse files Browse the repository at this point in the history
Write test cases for dataStore
  • Loading branch information
arunoda authored Oct 17, 2016
2 parents 50d7e58 + d061da0 commit 0a55209
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/manager/containers/CommentsPanel/dataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
73 changes: 73 additions & 0 deletions src/tests/dataStore.js
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);
});
});
29 changes: 0 additions & 29 deletions src/tests/index.js

This file was deleted.

0 comments on commit 0a55209

Please sign in to comment.