Merge branch 'react' into markitup-react
This commit is contained in:
@ -24,8 +24,9 @@ export const ENTRY_PERSIST_FAILURE = 'ENTRY_PERSIST_FAILURE';
|
||||
|
||||
/*
|
||||
* Simple Action Creators (Internal)
|
||||
* We still need to export them for tests
|
||||
*/
|
||||
function entryLoading(collection, slug) {
|
||||
export function entryLoading(collection, slug) {
|
||||
return {
|
||||
type: ENTRY_REQUEST,
|
||||
payload: {
|
||||
@ -35,7 +36,7 @@ function entryLoading(collection, slug) {
|
||||
};
|
||||
}
|
||||
|
||||
function entryLoaded(collection, entry) {
|
||||
export function entryLoaded(collection, entry) {
|
||||
return {
|
||||
type: ENTRY_SUCCESS,
|
||||
payload: {
|
||||
@ -45,7 +46,7 @@ function entryLoaded(collection, entry) {
|
||||
};
|
||||
}
|
||||
|
||||
function entriesLoading(collection) {
|
||||
export function entriesLoading(collection) {
|
||||
return {
|
||||
type: ENTRIES_REQUEST,
|
||||
payload: {
|
||||
@ -54,7 +55,7 @@ function entriesLoading(collection) {
|
||||
};
|
||||
}
|
||||
|
||||
function entriesLoaded(collection, entries, pagination) {
|
||||
export function entriesLoaded(collection, entries, pagination) {
|
||||
return {
|
||||
type: ENTRIES_SUCCESS,
|
||||
payload: {
|
||||
@ -65,7 +66,7 @@ function entriesLoaded(collection, entries, pagination) {
|
||||
};
|
||||
}
|
||||
|
||||
function entriesFailed(collection, error) {
|
||||
export function entriesFailed(collection, error) {
|
||||
return {
|
||||
type: ENTRIES_FAILURE,
|
||||
error: 'Failed to load entries',
|
||||
@ -74,7 +75,7 @@ function entriesFailed(collection, error) {
|
||||
};
|
||||
}
|
||||
|
||||
function entryPersisting(collection, entry) {
|
||||
export function entryPersisting(collection, entry) {
|
||||
return {
|
||||
type: ENTRY_PERSIST_REQUEST,
|
||||
payload: {
|
||||
@ -84,7 +85,7 @@ function entryPersisting(collection, entry) {
|
||||
};
|
||||
}
|
||||
|
||||
function entryPersisted(collection, entry) {
|
||||
export function entryPersisted(collection, entry) {
|
||||
return {
|
||||
type: ENTRY_PERSIST_SUCCESS,
|
||||
payload: {
|
||||
@ -94,7 +95,7 @@ function entryPersisted(collection, entry) {
|
||||
};
|
||||
}
|
||||
|
||||
function entryPersistFail(collection, entry, error) {
|
||||
export function entryPersistFail(collection, entry, error) {
|
||||
return {
|
||||
type: ENTRIES_FAILURE,
|
||||
error: 'Failed to persist entry',
|
||||
@ -102,7 +103,7 @@ function entryPersistFail(collection, entry, error) {
|
||||
};
|
||||
}
|
||||
|
||||
function emmptyDraftCreated(entry) {
|
||||
export function emmptyDraftCreated(entry) {
|
||||
return {
|
||||
type: DRAFT_CREATE_EMPTY,
|
||||
payload: entry
|
||||
|
40
src/reducers/__tests__/auth.spec.js
Normal file
40
src/reducers/__tests__/auth.spec.js
Normal 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'
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
26
src/reducers/__tests__/collections.spec.js
Normal file
26
src/reducers/__tests__/collections.spec.js
Normal 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' }] })
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
38
src/reducers/__tests__/config.spec.js
Normal file
38
src/reducers/__tests__/config.spec.js
Normal 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' })
|
||||
);
|
||||
});
|
||||
});
|
47
src/reducers/__tests__/entries.spec.js
Normal file
47
src/reducers/__tests__/entries.spec.js
Normal 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']
|
||||
}
|
||||
}
|
||||
}
|
||||
))
|
||||
);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user