mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-11 02:37:22 +03:00
Some minor refactorings
This commit is contained in:
parent
277b5e43f8
commit
8b2cbf7aea
4 changed files with 12 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { combineReducers } from 'redux';
|
import { combineReducers } from 'redux';
|
||||||
import serversReducer from '../servers/reducers/server';
|
import serversReducer from '../servers/reducers/servers';
|
||||||
import selectedServerReducer from '../servers/reducers/selectedServer';
|
import selectedServerReducer from '../servers/reducers/selectedServer';
|
||||||
import shortUrlsListReducer from '../short-urls/reducers/shortUrlsList';
|
import shortUrlsListReducer from '../short-urls/reducers/shortUrlsList';
|
||||||
import shortUrlsListParamsReducer from '../short-urls/reducers/shortUrlsListParams';
|
import shortUrlsListParamsReducer from '../short-urls/reducers/shortUrlsListParams';
|
||||||
|
|
|
@ -3,21 +3,21 @@ import { pipe, isEmpty, assoc, map, prop } from 'ramda';
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import { homepage } from '../../../package.json';
|
import { homepage } from '../../../package.json';
|
||||||
|
|
||||||
export const FETCH_SERVERS = 'shlink/servers/FETCH_SERVERS';
|
export const LIST_SERVERS = 'shlink/servers/LIST_SERVERS';
|
||||||
|
|
||||||
const initialState = {};
|
const initialState = {};
|
||||||
|
|
||||||
const assocId = (server) => assoc('id', server.id || uuid(), server);
|
const assocId = (server) => assoc('id', server.id || uuid(), server);
|
||||||
|
|
||||||
export default handleActions({
|
export default handleActions({
|
||||||
[FETCH_SERVERS]: (state, { list }) => list,
|
[LIST_SERVERS]: (state, { list }) => list,
|
||||||
}, initialState);
|
}, initialState);
|
||||||
|
|
||||||
export const listServers = ({ listServers, createServers }, { get }) => () => async (dispatch) => {
|
export const listServers = ({ listServers, createServers }, { get }) => () => async (dispatch) => {
|
||||||
const localList = listServers();
|
const localList = listServers();
|
||||||
|
|
||||||
if (!isEmpty(localList)) {
|
if (!isEmpty(localList)) {
|
||||||
dispatch({ type: FETCH_SERVERS, list: localList });
|
dispatch({ type: LIST_SERVERS, list: localList });
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ export const listServers = ({ listServers, createServers }, { get }) => () => as
|
||||||
.catch(() => []);
|
.catch(() => []);
|
||||||
|
|
||||||
createServers(remoteList);
|
createServers(remoteList);
|
||||||
dispatch({ type: FETCH_SERVERS, list: remoteList.reduce((map, server) => ({ ...map, [server.id]: server }), {}) });
|
dispatch({ type: LIST_SERVERS, list: remoteList.reduce((map, server) => ({ ...map, [server.id]: server }), {}) });
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createServer = ({ createServer }, listServersAction) => pipe(createServer, listServersAction);
|
export const createServer = ({ createServer }, listServersAction) => pipe(createServer, listServersAction);
|
|
@ -6,7 +6,7 @@ import DeleteServerButton from '../DeleteServerButton';
|
||||||
import { EditServer } from '../EditServer';
|
import { EditServer } from '../EditServer';
|
||||||
import ImportServersBtn from '../helpers/ImportServersBtn';
|
import ImportServersBtn from '../helpers/ImportServersBtn';
|
||||||
import { resetSelectedServer, selectServer } from '../reducers/selectedServer';
|
import { resetSelectedServer, selectServer } from '../reducers/selectedServer';
|
||||||
import { createServer, createServers, deleteServer, editServer, listServers } from '../reducers/server';
|
import { createServer, createServers, deleteServer, editServer, listServers } from '../reducers/servers';
|
||||||
import ForServerVersion from '../helpers/ForServerVersion';
|
import ForServerVersion from '../helpers/ForServerVersion';
|
||||||
import { ServerError } from '../helpers/ServerError';
|
import { ServerError } from '../helpers/ServerError';
|
||||||
import ServersImporter from './ServersImporter';
|
import ServersImporter from './ServersImporter';
|
||||||
|
|
|
@ -5,15 +5,15 @@ import reducer, {
|
||||||
listServers,
|
listServers,
|
||||||
createServers,
|
createServers,
|
||||||
editServer,
|
editServer,
|
||||||
FETCH_SERVERS,
|
LIST_SERVERS,
|
||||||
} from '../../../src/servers/reducers/server';
|
} from '../../../src/servers/reducers/servers';
|
||||||
|
|
||||||
describe('serverReducer', () => {
|
describe('serverReducer', () => {
|
||||||
const list = {
|
const list = {
|
||||||
abc123: { id: 'abc123' },
|
abc123: { id: 'abc123' },
|
||||||
def456: { id: 'def456' },
|
def456: { id: 'def456' },
|
||||||
};
|
};
|
||||||
const expectedFetchServersResult = { type: FETCH_SERVERS, list };
|
const expectedFetchServersResult = { type: LIST_SERVERS, list };
|
||||||
const ServersServiceMock = {
|
const ServersServiceMock = {
|
||||||
listServers: jest.fn(() => list),
|
listServers: jest.fn(() => list),
|
||||||
createServer: jest.fn(),
|
createServer: jest.fn(),
|
||||||
|
@ -25,8 +25,8 @@ describe('serverReducer', () => {
|
||||||
afterEach(jest.clearAllMocks);
|
afterEach(jest.clearAllMocks);
|
||||||
|
|
||||||
describe('reducer', () => {
|
describe('reducer', () => {
|
||||||
it('returns servers when action is FETCH_SERVERS', () =>
|
it('returns servers when action is LIST_SERVERS', () =>
|
||||||
expect(reducer({}, { type: FETCH_SERVERS, list })).toEqual(list));
|
expect(reducer({}, { type: LIST_SERVERS, list })).toEqual(list));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('action creators', () => {
|
describe('action creators', () => {
|
||||||
|
@ -89,7 +89,7 @@ describe('serverReducer', () => {
|
||||||
await listServers(NoListServersServiceMock, axios)()(dispatch);
|
await listServers(NoListServersServiceMock, axios)()(dispatch);
|
||||||
|
|
||||||
expect(dispatch).toHaveBeenCalledTimes(1);
|
expect(dispatch).toHaveBeenCalledTimes(1);
|
||||||
expect(dispatch).toHaveBeenNthCalledWith(1, { type: FETCH_SERVERS, list: expectedList });
|
expect(dispatch).toHaveBeenNthCalledWith(1, { type: LIST_SERVERS, list: expectedList });
|
||||||
expect(NoListServersServiceMock.listServers).toHaveBeenCalledTimes(1);
|
expect(NoListServersServiceMock.listServers).toHaveBeenCalledTimes(1);
|
||||||
expect(NoListServersServiceMock.createServer).not.toHaveBeenCalled();
|
expect(NoListServersServiceMock.createServer).not.toHaveBeenCalled();
|
||||||
expect(NoListServersServiceMock.editServer).not.toHaveBeenCalled();
|
expect(NoListServersServiceMock.editServer).not.toHaveBeenCalled();
|
||||||
|
|
Loading…
Reference in a new issue