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,11 @@
import React from 'react';
import { shallow } from 'enzyme';
import { PageNotFound } from '../../../src/features/common';
describe('common/PageNotFound', () => {
it('renders node with correct class name', () => {
const renderedComponent = shallow(<PageNotFound />);
expect(renderedComponent.find('.common-page-not-found').length).toBe(1);
});
});
@@ -0,0 +1,35 @@
import React from 'react';
import { shallow } from 'enzyme';
import { CounterPage } from '../../../src/features/examples/CounterPage';
describe('examples/CounterPage', () => {
it('renders node with correct class name', () => {
const props = {
examples: {},
actions: {},
};
const renderedComponent = shallow(<CounterPage {...props} />);
expect(renderedComponent.find('.examples-counter-page').length).toBe(1);
});
it('counter actions are called when buttons clicked', () => {
const pageProps = {
examples: {},
actions: {
counterPlusOne: jest.fn(),
counterMinusOne: jest.fn(),
counterReset: jest.fn(),
},
};
const renderedComponent = shallow(
<CounterPage {...pageProps} />
);
renderedComponent.find('.btn-plus-one').simulate('click');
renderedComponent.find('.btn-minus-one').simulate('click');
renderedComponent.find('.btn-reset').simulate('click');
expect(pageProps.actions.counterPlusOne.mock.calls.length).toBe(1);
expect(pageProps.actions.counterMinusOne.mock.calls.length).toBe(1);
expect(pageProps.actions.counterReset.mock.calls.length).toBe(1);
});
});
+11
View File
@@ -0,0 +1,11 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Layout } from '../../../src/features/examples';
describe('examples/Layout', () => {
it('renders node with correct class name', () => {
const renderedComponent = shallow(<Layout />);
expect(renderedComponent.find('.examples-layout').length).toBe(1);
});
});
@@ -0,0 +1,51 @@
import React from 'react';
import { shallow } from 'enzyme';
import { RedditListPage } from '../../../src/features/examples/RedditListPage';
describe('examples/RedditListPage', () => {
it('renders node with correct class name', () => {
const props = {
examples: { redditList: [] },
actions: {},
};
const renderedComponent = shallow(<RedditListPage {...props} />);
expect(renderedComponent.find('.examples-reddit-list-page').length).toBe(1);
expect(renderedComponent.find('.no-items-tip').length).toBe(1);
});
it("renders list items when there's data", () => {
const props = {
examples: { redditList: [{ data: { id: 'id', title: 'title', url: 'url' } }] },
actions: {},
};
const renderedComponent = shallow(<RedditListPage {...props} />);
expect(renderedComponent.find('.examples-reddit-list-page').length).toBe(1);
});
it('should disable fetch button when fetching reddit', () => {
const pageProps = {
examples: {
redditList: [],
fetchRedditListPending: true,
},
actions: {},
};
const renderedComponent = shallow(<RedditListPage {...pageProps} />);
expect(renderedComponent.find('.btn-fetch-reddit[disabled]').length).toBe(1);
});
it('should show error if fetch failed', () => {
const pageProps = {
examples: {
redditList: [],
fetchRedditListError: new Error('server error'),
},
actions: {},
};
const renderedComponent = shallow(<RedditListPage {...pageProps} />);
expect(renderedComponent.find('.fetch-list-error').length).toBe(1);
});
});
+15
View File
@@ -0,0 +1,15 @@
import React from 'react';
import { shallow } from 'enzyme';
import { SidePanel } from '../../../src/features/examples/SidePanel';
describe('examples/SidePanel', () => {
it('renders node with correct class name', () => {
const props = {
examples: {},
actions: {},
};
const renderedComponent = shallow(<SidePanel {...props} />);
expect(renderedComponent.find('.examples-side-panel').length).toBe(1);
});
});
@@ -0,0 +1,15 @@
import React from 'react';
import { shallow } from 'enzyme';
import { WelcomePage } from '../../../src/features/examples/WelcomePage';
describe('examples/WelcomePage', () => {
it('renders node with correct class name', () => {
const props = {
examples: {},
actions: {},
};
const renderedComponent = shallow(<WelcomePage {...props} />);
expect(renderedComponent.find('.examples-welcome-page').length).toBe(1);
});
});
@@ -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.
});
+11
View File
@@ -0,0 +1,11 @@
import React from 'react';
import { shallow } from 'enzyme';
import { App } from '../../../src/features/home';
describe('home/App', () => {
it('renders node with correct class name', () => {
const renderedComponent = shallow(<App />);
expect(renderedComponent.find('.home-app').length).toBe(1);
});
});
+15
View File
@@ -0,0 +1,15 @@
import React from 'react';
import { shallow } from 'enzyme';
import { DefaultPage } from '../../../src/features/home/DefaultPage';
describe('home/DefaultPage', () => {
it('renders node with correct class name', () => {
const props = {
home: {},
actions: {},
};
const renderedComponent = shallow(<DefaultPage {...props} />);
expect(renderedComponent.find('.home-default-page').length).toBe(1);
});
});