From ab160b7bf9ea37f888f28334c2879ff509040a53 Mon Sep 17 00:00:00 2001 From: joshaber Date: Tue, 31 May 2016 15:18:34 -0400 Subject: [PATCH] Test the users store. --- test/app-test.tsx | 10 +++++++++- test/users-store-test.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/users-store-test.ts diff --git a/test/app-test.tsx b/test/app-test.tsx index ae5e4c2a24..41df327f91 100644 --- a/test/app-test.tsx +++ b/test/app-test.tsx @@ -7,10 +7,18 @@ import * as TestUtils from 'react-addons-test-utils' import App from '../src/app' import UsersStore from '../src/users-store' +import InMemoryStore from './in-memory-store' describe('App', () => { + let usersStore: UsersStore = null + + beforeEach(() => { + const inMemoryStore = new InMemoryStore() + usersStore = new UsersStore(inMemoryStore, inMemoryStore) + }) + it('renders', () => { - const app = TestUtils.renderIntoDocument() as React.Component + const app = TestUtils.renderIntoDocument() as React.Component const node = ReactDOM.findDOMNode(app) expect(node).not.to.equal(null) }) diff --git a/test/users-store-test.ts b/test/users-store-test.ts new file mode 100644 index 0000000000..d47b2f041f --- /dev/null +++ b/test/users-store-test.ts @@ -0,0 +1,33 @@ +import * as chai from 'chai' +const expect = chai.expect + +import User from '../src/user' +import UsersStore from '../src/users-store' +import InMemoryStore from './in-memory-store' + +describe('UsersStore', () => { + let usersStore: UsersStore = null + beforeEach(() => { + const inMemoryStore = new InMemoryStore() + usersStore = new UsersStore(inMemoryStore, inMemoryStore) + }) + + describe('adding a new user', () => { + it('contains the added user', () => { + const newUserLogin = 'tonald-drump' + usersStore.addUser(new User(newUserLogin, '', '')) + + const users = usersStore.getUsers() + expect(users[0].getLogin()).to.equal('newUserLogin') + }) + + it('notifies when a user is added', () => { + let changed = false + usersStore.onUsersChanged(() => { + changed = true + }) + usersStore.addUser(new User('', '', '')) + expect(changed).to.equal(true) + }) + }) +})