mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-31 21:38:19 +03:00
Removed redundant createServer action, leaving just createServers
This commit is contained in:
parent
90ef41b419
commit
6f67f7bbf0
5 changed files with 11 additions and 24 deletions
|
@ -13,7 +13,7 @@ import { DuplicatedServersModal } from './helpers/DuplicatedServersModal';
|
|||
const SHOW_IMPORT_MSG_TIME = 4000;
|
||||
|
||||
interface CreateServerProps {
|
||||
createServer: (server: ServerWithId) => void;
|
||||
createServers: (servers: ServerWithId[]) => void;
|
||||
servers: ServersMap;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ const ImportResult = ({ type }: { type: 'error' | 'success' }) => (
|
|||
);
|
||||
|
||||
export const CreateServer = (ImportServersBtn: FC<ImportServersBtnProps>, useTimeoutToggle: TimeoutToggle) => (
|
||||
{ servers, createServer }: CreateServerProps,
|
||||
{ servers, createServers }: CreateServerProps,
|
||||
) => {
|
||||
const navigate = useNavigate();
|
||||
const goBack = useGoBack();
|
||||
|
@ -43,7 +43,7 @@ export const CreateServer = (ImportServersBtn: FC<ImportServersBtnProps>, useTim
|
|||
|
||||
const id = uuid();
|
||||
|
||||
createServer({ ...serverData, id });
|
||||
createServers([{ ...serverData, id }]);
|
||||
navigate(`/server/${id}`);
|
||||
};
|
||||
|
||||
|
|
|
@ -66,8 +66,6 @@ export const createServers = pipe(
|
|||
(newServers: ServersMap) => ({ type: CREATE_SERVERS, payload: newServers }),
|
||||
);
|
||||
|
||||
export const createServer = (server: ServerWithId) => createServers([server]);
|
||||
|
||||
export const editServer = (serverId: string, serverData: Partial<ServerData>) => ({
|
||||
type: EDIT_SERVER,
|
||||
payload: { serverId, serverData },
|
||||
|
|
|
@ -6,7 +6,7 @@ import { DeleteServerButton } from '../DeleteServerButton';
|
|||
import { EditServer } from '../EditServer';
|
||||
import { ImportServersBtn } from '../helpers/ImportServersBtn';
|
||||
import { resetSelectedServer, selectServer } from '../reducers/selectedServer';
|
||||
import { createServer, createServers, deleteServer, editServer, setAutoConnect } from '../reducers/servers';
|
||||
import { createServers, deleteServer, editServer, setAutoConnect } from '../reducers/servers';
|
||||
import { fetchServers } from '../reducers/remoteServers';
|
||||
import { ServerError } from '../helpers/ServerError';
|
||||
import { ConnectDecorator } from '../../container/types';
|
||||
|
@ -38,7 +38,7 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator) => {
|
|||
|
||||
bottle.serviceFactory('CreateServer', CreateServer, 'ImportServersBtn', 'useTimeoutToggle');
|
||||
bottle.decorator('CreateServer', withoutSelectedServer);
|
||||
bottle.decorator('CreateServer', connect(['selectedServer', 'servers'], ['createServer', 'resetSelectedServer']));
|
||||
bottle.decorator('CreateServer', connect(['selectedServer', 'servers'], ['createServers', 'resetSelectedServer']));
|
||||
|
||||
bottle.serviceFactory('EditServer', EditServer, 'ServerError');
|
||||
bottle.decorator('EditServer', connect(['selectedServer'], ['editServer', 'selectServer', 'resetSelectedServer']));
|
||||
|
@ -70,7 +70,6 @@ const provideServices = (bottle: Bottle, connect: ConnectDecorator) => {
|
|||
|
||||
// Actions
|
||||
bottle.serviceFactory('selectServer', selectServer, 'buildShlinkApiClient', 'loadMercureInfo');
|
||||
bottle.serviceFactory('createServer', () => createServer);
|
||||
bottle.serviceFactory('createServers', () => createServers);
|
||||
bottle.serviceFactory('deleteServer', () => deleteServer);
|
||||
bottle.serviceFactory('editServer', () => editServer);
|
||||
|
|
|
@ -8,7 +8,7 @@ import { renderWithEvents } from '../__helpers__/setUpTest';
|
|||
jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: jest.fn() }));
|
||||
|
||||
describe('<CreateServer />', () => {
|
||||
const createServerMock = jest.fn();
|
||||
const createServersMock = jest.fn();
|
||||
const navigate = jest.fn();
|
||||
const servers = { foo: Mock.of<ServerWithId>({ url: 'https://existing_url.com', apiKey: 'existing_api_key' }) };
|
||||
const setUp = (serversImported = false, importFailed = false) => {
|
||||
|
@ -22,7 +22,7 @@ describe('<CreateServer />', () => {
|
|||
});
|
||||
const CreateServer = createCreateServer(() => <>ImportServersBtn</>, useTimeoutToggle);
|
||||
|
||||
return renderWithEvents(<CreateServer createServer={createServerMock} servers={servers} />);
|
||||
return renderWithEvents(<CreateServer createServers={createServersMock} servers={servers} />);
|
||||
};
|
||||
|
||||
beforeEach(jest.clearAllMocks);
|
||||
|
@ -48,18 +48,18 @@ describe('<CreateServer />', () => {
|
|||
it('creates server data when form is submitted', async () => {
|
||||
const { user } = setUp();
|
||||
|
||||
expect(createServerMock).not.toHaveBeenCalled();
|
||||
expect(createServersMock).not.toHaveBeenCalled();
|
||||
|
||||
await user.type(screen.getByLabelText(/^Name/), 'the_name');
|
||||
await user.type(screen.getByLabelText(/^URL/), 'https://the_url.com');
|
||||
await user.type(screen.getByLabelText(/^API key/), 'the_api_key');
|
||||
fireEvent.submit(screen.getByRole('form'));
|
||||
|
||||
expect(createServerMock).toHaveBeenCalledWith(expect.objectContaining({
|
||||
expect(createServersMock).toHaveBeenCalledWith([expect.objectContaining({
|
||||
name: 'the_name',
|
||||
url: 'https://the_url.com',
|
||||
apiKey: 'the_api_key',
|
||||
}));
|
||||
})]);
|
||||
expect(navigate).toHaveBeenCalledWith(expect.stringMatching(/^\/server\//));
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
||||
});
|
||||
|
@ -75,7 +75,7 @@ describe('<CreateServer />', () => {
|
|||
await waitFor(() => expect(screen.getByRole('dialog')).toBeInTheDocument());
|
||||
await user.click(screen.getByRole('button', { name: 'Discard' }));
|
||||
|
||||
expect(createServerMock).not.toHaveBeenCalled();
|
||||
expect(createServersMock).not.toHaveBeenCalled();
|
||||
expect(navigate).toHaveBeenCalledWith(-1);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { dissoc, values } from 'ramda';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import reducer, {
|
||||
createServer,
|
||||
deleteServer,
|
||||
createServers,
|
||||
editServer,
|
||||
|
@ -104,15 +103,6 @@ describe('serversReducer', () => {
|
|||
});
|
||||
|
||||
describe('action creators', () => {
|
||||
describe('createServer', () => {
|
||||
it('returns expected action', () => {
|
||||
const serverToCreate = Mock.of<RegularServer>({ id: 'abc123' });
|
||||
const result = createServer(serverToCreate);
|
||||
|
||||
expect(result).toEqual(expect.objectContaining({ type: CREATE_SERVERS }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('editServer', () => {
|
||||
it('returns expected action', () => {
|
||||
const serverData = { name: 'edited' };
|
||||
|
|
Loading…
Reference in a new issue