Test the users store.

This commit is contained in:
joshaber 2016-05-31 15:18:34 -04:00
parent f81a44623d
commit ab160b7bf9
2 changed files with 42 additions and 1 deletions

View file

@ -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(<App usersStore={new UsersStore()}/>) as React.Component<any, any>
const app = TestUtils.renderIntoDocument(<App usersStore={usersStore}/>) as React.Component<any, any>
const node = ReactDOM.findDOMNode(app)
expect(node).not.to.equal(null)
})

33
test/users-store-test.ts Normal file
View file

@ -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)
})
})
})