Create synapse-admin using 'rekit create --sass synapse-admin'

Change-Id: I14a94754264c83faffb7fea5099d37c97e60b07a
This commit is contained in:
Manuel Stahl
2019-02-07 12:47:18 +01:00
parent 427e91d123
commit 00d6959927
93 changed files with 3034 additions and 0 deletions
@@ -0,0 +1,28 @@
import {
EXAMPLES_COUNTER_MINUS_ONE,
} from '../../../../src/features/examples/redux/constants';
import {
counterMinusOne,
reducer,
} from '../../../../src/features/examples/redux/counterMinusOne';
describe('examples/redux/counterMinusOne', () => {
it('returns correct action by counterMinusOne', () => {
expect(counterMinusOne()).toHaveProperty('type', EXAMPLES_COUNTER_MINUS_ONE);
});
it('handles action type EXAMPLES_COUNTER_MINUS_ONE correctly', () => {
const prevState = { count: 3 };
// TODO: use real expected state.
const expectedState = { count: 2 };
const state = reducer(
prevState,
{ type: EXAMPLES_COUNTER_MINUS_ONE }
);
// Should be immutable
expect(state).not.toBe(prevState);
expect(state).toEqual(expectedState);
});
});
@@ -0,0 +1,25 @@
import {
EXAMPLES_COUNTER_PLUS_ONE,
} from '../../../../src/features/examples/redux/constants';
import {
counterPlusOne,
reducer,
} from '../../../../src/features/examples/redux/counterPlusOne';
describe('examples/redux/counterPlusOne', () => {
it('returns correct action by counterPlusOne', () => {
expect(counterPlusOne()).toHaveProperty('type', EXAMPLES_COUNTER_PLUS_ONE);
});
it('handles action type EXAMPLES_COUNTER_PLUS_ONE correctly', () => {
const prevState = { count: 0 };
const expectedState = { count: 1 };
const state = reducer(
prevState,
{ type: EXAMPLES_COUNTER_PLUS_ONE }
);
expect(state).not.toBe(prevState); // should be immutable
expect(state).toEqual(expectedState); // TODO: replace this line with real case.
});
});
@@ -0,0 +1,25 @@
import {
EXAMPLES_COUNTER_RESET,
} from '../../../../src/features/examples/redux/constants';
import {
counterReset,
reducer,
} from '../../../../src/features/examples/redux/counterReset';
describe('examples/redux/counterReset', () => {
it('returns correct action by counterReset', () => {
expect(counterReset()).toHaveProperty('type', EXAMPLES_COUNTER_RESET);
});
it('handles action type EXAMPLES_COUNTER_RESET correctly', () => {
const prevState = { count: 10 };
const expectedState = { count: 0 };
const state = reducer(
prevState,
{ type: EXAMPLES_COUNTER_RESET }
);
expect(state).not.toBe(prevState); // should be immutable
expect(state).toEqual(expectedState); // TODO: replace this line with real case.
});
});
@@ -0,0 +1,102 @@
import _ from 'lodash';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import nock from 'nock';
import {
EXAMPLES_FETCH_REDDIT_LIST_BEGIN,
EXAMPLES_FETCH_REDDIT_LIST_SUCCESS,
EXAMPLES_FETCH_REDDIT_LIST_FAILURE,
EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR,
} from '../../../../src/features/examples/redux/constants';
import {
fetchRedditList,
dismissFetchRedditListError,
reducer,
} from '../../../../src/features/examples/redux/fetchRedditList';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
describe('examples/redux/fetchRedditList', () => {
afterEach(() => {
nock.cleanAll();
});
it('dispatches success action when fetchRedditList succeeds', () => {
const list = _.times(2, i => ({
data: {
id: `id${i}`,
title: `test${i}`,
url: `http://example.com/test${i}`,
},
}));
nock('http://www.reddit.com/')
.get('/r/reactjs.json')
.reply(200, { data: { children: list } });
const store = mockStore({ redditReactjsList: [] });
return store.dispatch(fetchRedditList()).then(() => {
const actions = store.getActions();
expect(actions[0]).toHaveProperty('type', EXAMPLES_FETCH_REDDIT_LIST_BEGIN);
expect(actions[1]).toHaveProperty('type', EXAMPLES_FETCH_REDDIT_LIST_SUCCESS);
});
});
it('dispatches failure action when fetchRedditList fails', () => {
nock('http://www.reddit.com/')
.get('/r/reactjs.json')
.reply(500, null);
const store = mockStore({ redditReactjsList: [] });
return store.dispatch(fetchRedditList({ error: true })).catch(() => {
const actions = store.getActions();
expect(actions[0]).toHaveProperty('type', EXAMPLES_FETCH_REDDIT_LIST_BEGIN);
expect(actions[1]).toHaveProperty('type', EXAMPLES_FETCH_REDDIT_LIST_FAILURE);
expect(actions[1]).toHaveProperty('data.error', expect.anything());
});
});
it('returns correct action by dismissFetchRedditListError', () => {
const expectedAction = {
type: EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR,
};
expect(dismissFetchRedditListError()).toEqual(expectedAction);
});
it('handles action type EXAMPLES_FETCH_REDDIT_LIST_BEGIN correctly', () => {
const prevState = { fetchRedditListPending: false };
const state = reducer(prevState, { type: EXAMPLES_FETCH_REDDIT_LIST_BEGIN });
expect(state).not.toBe(prevState); // should be immutable
expect(state.fetchRedditListPending).toBe(true);
});
it('handles action type EXAMPLES_FETCH_REDDIT_LIST_SUCCESS correctly', () => {
const prevState = { fetchRedditListPending: true };
const state = reducer(prevState, {
type: EXAMPLES_FETCH_REDDIT_LIST_SUCCESS,
data: { data: { children: [] } },
});
expect(state).not.toBe(prevState); // should be immutable
expect(state.fetchRedditListPending).toBe(false);
});
it('handles action type EXAMPLES_FETCH_REDDIT_LIST_FAILURE correctly', () => {
const prevState = { fetchRedditListPending: true };
const state = reducer(prevState, {
type: EXAMPLES_FETCH_REDDIT_LIST_FAILURE,
data: { error: new Error('some error') },
});
expect(state).not.toBe(prevState); // should be immutable
expect(state.fetchRedditListPending).toBe(false);
expect(state.fetchRedditListError).toEqual(expect.anything());
});
it('handles action type EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR correctly', () => {
const prevState = { fetchRedditListError: new Error('some error') };
const state = reducer(prevState, { type: EXAMPLES_FETCH_REDDIT_LIST_DISMISS_ERROR });
expect(state).not.toBe(prevState); // should be immutable
expect(state.fetchRedditListError).toBe(null);
});
});
@@ -0,0 +1,14 @@
import reducer from '../../../../src/features/examples/redux/reducer';
describe('examples/redux/reducer', () => {
it('does nothing if no matched action', () => {
const prevState = {};
const state = reducer(
prevState,
{ type: '__UNKNOWN_ACTION_TYPE__' }
);
expect(state).toEqual(prevState);
});
// TODO: add global reducer test if needed.
});