Switched to Jest testing framework.

Made tests pass again. Created entries.spec.js + made it pass.
Added wallaby.config.js to support wallaby.js runner.
This commit is contained in:
Andrey Okonetchnikov
2016-09-20 14:00:03 +02:00
parent d7363f276e
commit 0b69f6fa98
9 changed files with 112 additions and 70 deletions

View File

@ -0,0 +1,40 @@
import expect from 'expect';
import Immutable from 'immutable';
import { authenticating, authenticate, authError } from '../../actions/auth';
import auth from '../auth';
describe('auth', () => {
it('should handle an empty state', () => {
expect(
auth(undefined, {})
).toEqual(
null
);
});
it('should handle an authentication request', () => {
expect(
auth(undefined, authenticating())
).toEqual(
Immutable.Map({ isFetching: true })
);
});
it('should handle authentication', () => {
expect(
auth(undefined, authenticate({ email: 'joe@example.com' }))
).toEqual(
Immutable.fromJS({ user: { email: 'joe@example.com' } })
);
});
it('should handle an authentication error', () => {
expect(
auth(undefined, authError(new Error('Bad credentials')))
).toEqual(
Immutable.Map({
error: 'Error: Bad credentials'
})
);
});
});

View File

@ -0,0 +1,26 @@
import expect from 'expect';
import { OrderedMap, fromJS } from 'immutable';
import { configLoaded } from '../../actions/config';
import collections from '../collections';
describe('collections', () => {
it('should handle an empty state', () => {
expect(
collections(undefined, {})
).toEqual(
null
);
});
it('should load the collections from the config', () => {
expect(
collections(undefined, configLoaded({ collections: [
{ name: 'posts', folder: '_posts', fields: [{ name: 'title', widget: 'string' }] }
] }))
).toEqual(
OrderedMap({
posts: fromJS({ name: 'posts', folder: '_posts', fields: [{ name: 'title', widget: 'string' }] })
})
);
});
});

View File

@ -0,0 +1,38 @@
import expect from 'expect';
import Immutable from 'immutable';
import { configLoaded, configLoading, configFailed } from '../../actions/config';
import config from '../config';
describe('config', () => {
it('should handle an empty state', () => {
expect(
config(undefined, {})
).toEqual(
null
);
});
it('should handle an update', () => {
expect(
config(Immutable.Map({ 'a': 'b', 'c': 'd' }), configLoaded({ 'a': 'changed', 'e': 'new' }))
).toEqual(
Immutable.Map({ 'a': 'changed', 'e': 'new' })
);
});
it('should mark the config as loading', () => {
expect(
config(undefined, configLoading())
).toEqual(
Immutable.Map({ isFetching: true })
);
});
it('should handle an error', () => {
expect(
config(Immutable.Map({ isFetching: true }), configFailed(new Error('Config could not be loaded')))
).toEqual(
Immutable.Map({ error: 'Error: Config could not be loaded' })
);
});
});

View File

@ -0,0 +1,47 @@
import expect from 'expect';
import { Map, OrderedMap, fromJS } from 'immutable';
import { entriesLoading, entriesLoaded } from '../../actions/entries';
import reducer from '../entries';
describe('entries', () => {
it('should mark entries as fetching', () => {
const state = OrderedMap({
'posts': Map({ name: 'posts' })
});
expect(
reducer(state, entriesLoading(Map({ name: 'posts' })))
).toEqual(
OrderedMap(fromJS({
'posts': { name: 'posts' },
'pages': {
'posts': { isFetching: true }
}
}))
);
});
it('should handle loaded entries', () => {
const state = OrderedMap({
'posts': Map({ name: 'posts' })
});
const entries = [{ slug: 'a', path: '' }, { slug: 'b', title: 'B' }];
expect(
reducer(state, entriesLoaded(Map({ name: 'posts' }), entries))
).toEqual(
OrderedMap(fromJS(
{
posts: { name: 'posts' },
entities: {
'posts.a': { slug: 'a', path: '', isFetching: false },
'posts.b': { slug: 'b', title: 'B', isFetching: false },
},
pages: {
posts: {
ids: ['a', 'b']
}
}
}
))
);
});
});