Moving coral-framework tests over and updating mocha to transpile them.

This commit is contained in:
David Jay
2016-11-09 14:10:01 -05:00
parent 13aabb9974
commit e0e80aa5cd
5 changed files with 11 additions and 9 deletions
@@ -1,31 +0,0 @@
import { Map } from 'immutable'
import {expect} from 'chai'
import authReducer from '../../store/reducers/auth'
import * as actions from '../../store/actions/auth'
describe ('authReducer', () => {
describe('SET_LOGGED_IN_USER', () => {
it('should set a logged in user', () => {
const action = {
type: actions.SET_LOGGED_IN_USER,
user_id: '123'
}
const store = new Map({})
const result = authReducer(store, action)
expect(result.get('user')).to.equal(action.user_id)
})
})
describe('LOG_OUT_USER', () => {
it('should clear the user store', () => {
const action = {
type: actions.LOG_OUT_USER
}
const store = new Map({
user: '123'
})
const result = authReducer(store, action)
expect(result.get('user')).to.equal(undefined)
})
})
})
@@ -1,152 +0,0 @@
import 'react'
import 'redux'
import {expect} from 'chai'
import fetchMock from 'fetch-mock'
import * as actions from '../../store/actions/items'
import {Map} from 'immutable'
import configureStore from 'redux-mock-store'
const mockStore = configureStore()
describe('itemActions', () => {
let store
const host = 'http://test.host'
beforeEach(() => {
store = mockStore(new Map({}))
fetchMock.restore()
})
describe('getItemsQuery', () => {
const query = 'all'
const rootId = '1234'
const view = 'testView'
const response = {results: [
{Docs: [
{type: 'comment', data: {content: 'stuff'}, item_id: '123'},
{type: 'comment', data: {content: 'morestuff'}, item_id: '456'}
]}
]}
it('should get an item from a query and send the appropriate dispatches', () => {
fetchMock.get('*', JSON.stringify(response))
return actions.getItemsQuery(query, rootId, view, host)(store.dispatch)
.then((res) => {
expect(fetchMock.calls().matched[0][0]).to.equal('http://test.host/v1/exec/all/view/testView/1234')
expect(res).to.deep.equal(response.results[0].Docs)
expect(store.getActions()[0]).to.deep.equal({
type: actions.ADD_ITEM,
item: response.results[0].Docs[0],
item_id: '123'
})
expect(store.getActions()[1]).to.deep.equal({
type: actions.ADD_ITEM,
item: response.results[0].Docs[1],
item_id: '456'
})
})
})
it('should handle an error', () => {
fetchMock.get('*', 404)
return actions.getItemsQuery(query, rootId, view, host)(store.dispatch)
.catch((err) => {
expect(err).to.be.truthy
})
})
})
describe('getItemsArray', () => {
const response = {items: [{type: 'comment', item_id: '123'}, {type: 'comment', item_id: '456'}]}
const ids = [1, 2]
it('should get an item from an array of ids and send the appropriate dispatches', () => {
fetchMock.get('*', JSON.stringify(response))
return actions.getItemsArray(ids, host)(store.dispatch)
.then((res) => {
expect(res).to.deep.equal(response.items)
expect(store.getActions()[0]).to.deep.equal({
type: actions.ADD_ITEM,
item: {
type: 'comment',
item_id: '123'
},
item_id: '123'
})
expect(store.getActions()[1]).to.deep.equal({
type: actions.ADD_ITEM,
item: {
type: 'comment', item_id: '456'
},
item_id: '456'
})
})
})
it('should handle an error', () => {
fetchMock.get('*', 404)
return actions.getItemsArray(ids, host)(store.dispatch)
.catch((err) => {
expect(err).to.be.truthy
})
})
})
describe('postItem', () => {
const item = {
type: 'comment',
data:{content: 'stuff'}
}
it ('should post an item, return an id, then dispatch that item to the store', () => {
fetchMock.post('*', {item_id: '123', type: 'comment', data: {content: 'stuff'}})
return actions.postItem(item.data, item.type, undefined, host)(store.dispatch)
.then((id) => {
expect(fetchMock.calls().matched[0][1]).to.deep.equal(
{
method: 'POST',
body: JSON.stringify({...item, version: 1})
}
)
expect(id).to.equal('123')
expect(store.getActions()[0]).to.deep.equal({
type: actions.ADD_ITEM,
item: {
type: 'comment',
data: {
content: 'stuff'
},
item_id: '123'
},
item_id: '123'
})
})
})
it('should handle an error', () => {
fetchMock.post('*', 404)
return actions.postItem(item, host)(store.dispatch)
.catch((err) => {
expect(err).to.be.truthy
})
})
})
describe('postAction', () => {
it ('should post an action', () => {
fetchMock.post('*', 200)
return actions.postAction('abc', 'flag', '123', host)(store.dispatch)
.then(response => {
expect(fetchMock.calls().matched[0][0]).to.equal('http://test.host/v1/action/flag/user/123/on/item/abc')
expect(response).to.equal('')
})
})
it('should handle an error', () => {
fetchMock.post('*', 404)
return actions.postItem('abc', 'flag', '123', host)(store.dispatch)
.catch((err) => {
expect(err).to.be.truthy
})
})
})
})
@@ -1,149 +0,0 @@
import { Map, fromJS } from 'immutable'
import {expect} from 'chai'
import itemsReducer from '../../store/reducers/items'
import * as actions from '../../store/actions/items'
describe ('itemsReducer', () => {
describe('ADD_ITEM', () => {
it('should add an item', () => {
const action = {
type: 'ADD_ITEM',
item: {
type: 'comment',
data: {
content: 'stuff'
},
item_id: '123'
},
item_id: '123'
}
const store = new Map({})
const result = itemsReducer(store, action)
expect(result.get('123').toJS()).to.deep.equal({
type: 'comment',
data: {
content: 'stuff'
},
item_id: '123'
})
})
})
describe ('UPDATE_ITEM', () => {
it ('should update an item', () => {
const action = {
type: 'UPDATE_ITEM',
property: 'stuff',
value: 'things',
item_id: '123'
}
const store = fromJS({
'123': {
item_id: '123',
data: {
stuff: 'morestuff'
}
}
})
const result = itemsReducer(store, action)
expect(result.get('123').toJS()).to.deep.equal({
item_id: '123',
data: {
stuff: 'things'
}
})
})
})
describe('APPEND_ITEM_ARRAY', () => {
let action
let store
beforeEach (() => {
action = {
type: 'APPEND_ITEM_ARRAY',
property: 'stuff',
value: 'things',
item_id: '123'
}
store = fromJS({
'123': {
item_id: '123',
data: {
stuff: ['morestuff']
}
}
})
})
it ('should append to an existing array', () => {
const result = itemsReducer(store, action)
expect(result.get('123').toJS()).to.deep.equal({
item_id: '123',
data: {
stuff: ['morestuff', 'things']
}
})
})
it ('should create a new array', () => {
store = fromJS({
'123': {
item_id: '123',
data: {}
}
})
const result = itemsReducer(store, action)
expect(result.get('123').toJS()).to.deep.equal({
item_id: '123',
data: {
stuff: ['things']
}
})
})
})
describe('APPEND_ITEM_RELATED', () => {
let action
let store
beforeEach (() => {
action = {
type: 'APPEND_ITEM_RELATED',
property: 'stuff',
value: 'things',
item_id: '123'
}
store = fromJS({
'123': {
item_id: '123',
related: {
stuff: ['morestuff']
}
}
})
})
it ('should append to an existing array', () => {
const result = itemsReducer(store, action)
expect(result.get('123').toJS()).to.deep.equal({
item_id: '123',
related: {
stuff: ['morestuff', 'things']
}
})
})
it ('should create a new array', () => {
store = fromJS({
'123': {
item_id: '123',
related: {}
}
})
const result = itemsReducer(store, action)
expect(result.get('123').toJS()).to.deep.equal({
item_id: '123',
related: {
stuff: ['things']
}
})
})
})
})
@@ -1,35 +0,0 @@
import { Map } from 'immutable'
import {expect} from 'chai'
import notificationReducer from '../../store/reducers/notification'
import * as actions from '../../store/actions/notification'
describe ('notificationsReducer', () => {
describe('ADD_NOTIFICATION', () => {
it('should add a notification', () => {
const action = {
type: actions.ADD_NOTIFICATION,
text: 'Test notification',
notifType: 'test'
}
const store = new Map({})
const result = notificationReducer(store, action)
expect(result.get('text')).to.equal(action.text)
expect(result.get('type')).to.equal(action.notifType)
})
})
describe('CLEAR_NOTIFICATION', () => {
it('should clear a notification', () => {
const action = {
type: actions.CLEAR_NOTIFICATION
}
const store = new Map({
text: 'Test notification',
type: 'test'
})
const result = notificationReducer(store, action)
expect(result.get('text')).to.equal(undefined)
expect(result.get('type')).to.equal(undefined)
})
})
})