Add feature room-admin
Change-Id: I3bbe7bd7299b56e84ab918d2a8bb22facafecbf1
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { List } from '../../../src/features/room-admin/List';
|
||||
|
||||
describe('room-admin/List', () => {
|
||||
it('renders node with correct class name', () => {
|
||||
const props = {
|
||||
roomAdmin: {},
|
||||
actions: {},
|
||||
};
|
||||
const renderedComponent = shallow(
|
||||
<List {...props} />
|
||||
);
|
||||
|
||||
expect(
|
||||
renderedComponent.find('.room-admin-list').length
|
||||
).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,97 @@
|
||||
import configureMockStore from 'redux-mock-store';
|
||||
import thunk from 'redux-thunk';
|
||||
import nock from 'nock';
|
||||
|
||||
import {
|
||||
ROOM_ADMIN_FETCH_PUBLIC_ROOMS_BEGIN,
|
||||
ROOM_ADMIN_FETCH_PUBLIC_ROOMS_SUCCESS,
|
||||
ROOM_ADMIN_FETCH_PUBLIC_ROOMS_FAILURE,
|
||||
ROOM_ADMIN_FETCH_PUBLIC_ROOMS_DISMISS_ERROR,
|
||||
} from '../../../../src/features/room-admin/redux/constants';
|
||||
|
||||
import {
|
||||
fetchPublicRooms,
|
||||
dismissFetchPublicRoomsError,
|
||||
reducer,
|
||||
} from '../../../../src/features/room-admin/redux/fetchPublicRooms';
|
||||
|
||||
const middlewares = [thunk];
|
||||
const mockStore = configureMockStore(middlewares);
|
||||
|
||||
describe('room-admin/redux/fetchPublicRooms', () => {
|
||||
afterEach(() => {
|
||||
nock.cleanAll();
|
||||
});
|
||||
|
||||
it('dispatches success action when fetchPublicRooms succeeds', () => {
|
||||
const store = mockStore({});
|
||||
|
||||
return store.dispatch(fetchPublicRooms())
|
||||
.then(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0]).toHaveProperty('type', ROOM_ADMIN_FETCH_PUBLIC_ROOMS_BEGIN);
|
||||
expect(actions[1]).toHaveProperty('type', ROOM_ADMIN_FETCH_PUBLIC_ROOMS_SUCCESS);
|
||||
});
|
||||
});
|
||||
|
||||
it('dispatches failure action when fetchPublicRooms fails', () => {
|
||||
const store = mockStore({});
|
||||
|
||||
return store.dispatch(fetchPublicRooms({ error: true }))
|
||||
.catch(() => {
|
||||
const actions = store.getActions();
|
||||
expect(actions[0]).toHaveProperty('type', ROOM_ADMIN_FETCH_PUBLIC_ROOMS_BEGIN);
|
||||
expect(actions[1]).toHaveProperty('type', ROOM_ADMIN_FETCH_PUBLIC_ROOMS_FAILURE);
|
||||
expect(actions[1]).toHaveProperty('data.error', expect.anything());
|
||||
});
|
||||
});
|
||||
|
||||
it('returns correct action by dismissFetchPublicRoomsError', () => {
|
||||
const expectedAction = {
|
||||
type: ROOM_ADMIN_FETCH_PUBLIC_ROOMS_DISMISS_ERROR,
|
||||
};
|
||||
expect(dismissFetchPublicRoomsError()).toEqual(expectedAction);
|
||||
});
|
||||
|
||||
it('handles action type ROOM_ADMIN_FETCH_PUBLIC_ROOMS_BEGIN correctly', () => {
|
||||
const prevState = { fetchPublicRoomsPending: false };
|
||||
const state = reducer(
|
||||
prevState,
|
||||
{ type: ROOM_ADMIN_FETCH_PUBLIC_ROOMS_BEGIN }
|
||||
);
|
||||
expect(state).not.toBe(prevState); // should be immutable
|
||||
expect(state.fetchPublicRoomsPending).toBe(true);
|
||||
});
|
||||
|
||||
it('handles action type ROOM_ADMIN_FETCH_PUBLIC_ROOMS_SUCCESS correctly', () => {
|
||||
const prevState = { fetchPublicRoomsPending: true };
|
||||
const state = reducer(
|
||||
prevState,
|
||||
{ type: ROOM_ADMIN_FETCH_PUBLIC_ROOMS_SUCCESS, data: {} }
|
||||
);
|
||||
expect(state).not.toBe(prevState); // should be immutable
|
||||
expect(state.fetchPublicRoomsPending).toBe(false);
|
||||
});
|
||||
|
||||
it('handles action type ROOM_ADMIN_FETCH_PUBLIC_ROOMS_FAILURE correctly', () => {
|
||||
const prevState = { fetchPublicRoomsPending: true };
|
||||
const state = reducer(
|
||||
prevState,
|
||||
{ type: ROOM_ADMIN_FETCH_PUBLIC_ROOMS_FAILURE, data: { error: new Error('some error') } }
|
||||
);
|
||||
expect(state).not.toBe(prevState); // should be immutable
|
||||
expect(state.fetchPublicRoomsPending).toBe(false);
|
||||
expect(state.fetchPublicRoomsError).toEqual(expect.anything());
|
||||
});
|
||||
|
||||
it('handles action type ROOM_ADMIN_FETCH_PUBLIC_ROOMS_DISMISS_ERROR correctly', () => {
|
||||
const prevState = { fetchPublicRoomsError: new Error('some error') };
|
||||
const state = reducer(
|
||||
prevState,
|
||||
{ type: ROOM_ADMIN_FETCH_PUBLIC_ROOMS_DISMISS_ERROR }
|
||||
);
|
||||
expect(state).not.toBe(prevState); // should be immutable
|
||||
expect(state.fetchPublicRoomsError).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import reducer from '../../../../src/features/room-admin/redux/reducer';
|
||||
|
||||
describe('room-admin/redux/reducer', () => {
|
||||
it('does nothing if no matched action', () => {
|
||||
const prevState = {};
|
||||
const state = reducer(
|
||||
prevState,
|
||||
{ type: '__UNKNOWN_ACTION_TYPE__' }
|
||||
);
|
||||
expect(state).toBe(prevState);
|
||||
});
|
||||
|
||||
// TODO: add global reducer test if needed.
|
||||
});
|
||||
Reference in New Issue
Block a user