mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 09:47:28 +03:00
Fixed tests
This commit is contained in:
parent
4f54e3315f
commit
79a0a5e4ea
6 changed files with 23 additions and 23 deletions
|
@ -29,9 +29,6 @@ describe('selectedServerReducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('selectServer', () => {
|
describe('selectServer', () => {
|
||||||
const ShlinkApiClientMock = {
|
|
||||||
setConfig: sinon.spy(),
|
|
||||||
};
|
|
||||||
const serverId = 'abc123';
|
const serverId = 'abc123';
|
||||||
const selectedServer = {
|
const selectedServer = {
|
||||||
id: serverId,
|
id: serverId,
|
||||||
|
@ -41,7 +38,6 @@ describe('selectedServerReducer', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
ShlinkApiClientMock.setConfig.resetHistory();
|
|
||||||
ServersServiceMock.findServerById.resetHistory();
|
ServersServiceMock.findServerById.resetHistory();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -49,7 +45,7 @@ describe('selectedServerReducer', () => {
|
||||||
const dispatch = sinon.spy();
|
const dispatch = sinon.spy();
|
||||||
const expectedDispatchCalls = 2;
|
const expectedDispatchCalls = 2;
|
||||||
|
|
||||||
_selectServer(ShlinkApiClientMock, ServersServiceMock)(serverId)(dispatch);
|
_selectServer(ServersServiceMock)(serverId)(dispatch);
|
||||||
|
|
||||||
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
|
expect(dispatch.callCount).toEqual(expectedDispatchCalls);
|
||||||
expect(dispatch.firstCall.calledWith({ type: RESET_SHORT_URL_PARAMS })).toEqual(true);
|
expect(dispatch.firstCall.calledWith({ type: RESET_SHORT_URL_PARAMS })).toEqual(true);
|
||||||
|
@ -60,9 +56,8 @@ describe('selectedServerReducer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('invokes dependencies', () => {
|
it('invokes dependencies', () => {
|
||||||
_selectServer(ShlinkApiClientMock, ServersServiceMock)(serverId)(() => {});
|
_selectServer(ServersServiceMock)(serverId)(() => {});
|
||||||
|
|
||||||
expect(ShlinkApiClientMock.setConfig.callCount).toEqual(1);
|
|
||||||
expect(ServersServiceMock.findServerById.callCount).toEqual(1);
|
expect(ServersServiceMock.findServerById.callCount).toEqual(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -54,6 +54,7 @@ describe('shortUrlCreationReducer', () => {
|
||||||
createShortUrl: sinon.fake.returns(result),
|
createShortUrl: sinon.fake.returns(result),
|
||||||
});
|
});
|
||||||
const dispatch = sinon.spy();
|
const dispatch = sinon.spy();
|
||||||
|
const getState = () => ({});
|
||||||
|
|
||||||
afterEach(() => dispatch.resetHistory());
|
afterEach(() => dispatch.resetHistory());
|
||||||
|
|
||||||
|
@ -61,9 +62,9 @@ describe('shortUrlCreationReducer', () => {
|
||||||
const expectedDispatchCalls = 2;
|
const expectedDispatchCalls = 2;
|
||||||
const result = 'foo';
|
const result = 'foo';
|
||||||
const apiClientMock = createApiClientMock(Promise.resolve(result));
|
const apiClientMock = createApiClientMock(Promise.resolve(result));
|
||||||
const dispatchable = _createShortUrl(apiClientMock, {});
|
const dispatchable = _createShortUrl(() => apiClientMock, {});
|
||||||
|
|
||||||
await dispatchable(dispatch);
|
await dispatchable(dispatch, getState);
|
||||||
|
|
||||||
expect(apiClientMock.createShortUrl.callCount).toEqual(1);
|
expect(apiClientMock.createShortUrl.callCount).toEqual(1);
|
||||||
|
|
||||||
|
@ -76,10 +77,10 @@ describe('shortUrlCreationReducer', () => {
|
||||||
const expectedDispatchCalls = 2;
|
const expectedDispatchCalls = 2;
|
||||||
const error = 'Error';
|
const error = 'Error';
|
||||||
const apiClientMock = createApiClientMock(Promise.reject(error));
|
const apiClientMock = createApiClientMock(Promise.reject(error));
|
||||||
const dispatchable = _createShortUrl(apiClientMock, {});
|
const dispatchable = _createShortUrl(() => apiClientMock, {});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await dispatchable(dispatch);
|
await dispatchable(dispatch, getState);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e).toEqual(error);
|
expect(e).toEqual(error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ describe('tagDeleteReducer', () => {
|
||||||
deleteTags: sinon.fake.returns(result),
|
deleteTags: sinon.fake.returns(result),
|
||||||
});
|
});
|
||||||
const dispatch = sinon.spy();
|
const dispatch = sinon.spy();
|
||||||
|
const getState = () => ({});
|
||||||
|
|
||||||
afterEach(() => dispatch.resetHistory());
|
afterEach(() => dispatch.resetHistory());
|
||||||
|
|
||||||
|
@ -55,9 +56,9 @@ describe('tagDeleteReducer', () => {
|
||||||
const expectedDispatchCalls = 2;
|
const expectedDispatchCalls = 2;
|
||||||
const tag = 'foo';
|
const tag = 'foo';
|
||||||
const apiClientMock = createApiClientMock(Promise.resolve());
|
const apiClientMock = createApiClientMock(Promise.resolve());
|
||||||
const dispatchable = _deleteTag(apiClientMock, tag);
|
const dispatchable = _deleteTag(() => apiClientMock, tag);
|
||||||
|
|
||||||
await dispatchable(dispatch);
|
await dispatchable(dispatch, getState);
|
||||||
|
|
||||||
expect(apiClientMock.deleteTags.callCount).toEqual(1);
|
expect(apiClientMock.deleteTags.callCount).toEqual(1);
|
||||||
expect(apiClientMock.deleteTags.getCall(0).args).toEqual([[ tag ]]);
|
expect(apiClientMock.deleteTags.getCall(0).args).toEqual([[ tag ]]);
|
||||||
|
@ -72,10 +73,10 @@ describe('tagDeleteReducer', () => {
|
||||||
const error = 'Error';
|
const error = 'Error';
|
||||||
const tag = 'foo';
|
const tag = 'foo';
|
||||||
const apiClientMock = createApiClientMock(Promise.reject(error));
|
const apiClientMock = createApiClientMock(Promise.reject(error));
|
||||||
const dispatchable = _deleteTag(apiClientMock, tag);
|
const dispatchable = _deleteTag(() => apiClientMock, tag);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await dispatchable(dispatch);
|
await dispatchable(dispatch, getState);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e).toEqual(error);
|
expect(e).toEqual(error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ describe('tagEditReducer', () => {
|
||||||
setColorForKey: sinon.spy(),
|
setColorForKey: sinon.spy(),
|
||||||
};
|
};
|
||||||
const dispatch = sinon.spy();
|
const dispatch = sinon.spy();
|
||||||
|
const getState = () => ({});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
colorGenerator.setColorForKey.resetHistory();
|
colorGenerator.setColorForKey.resetHistory();
|
||||||
|
@ -67,9 +68,9 @@ describe('tagEditReducer', () => {
|
||||||
const newName = 'bar';
|
const newName = 'bar';
|
||||||
const color = '#ff0000';
|
const color = '#ff0000';
|
||||||
const apiClientMock = createApiClientMock(Promise.resolve());
|
const apiClientMock = createApiClientMock(Promise.resolve());
|
||||||
const dispatchable = _editTag(apiClientMock, colorGenerator, oldName, newName, color);
|
const dispatchable = _editTag(() => apiClientMock, colorGenerator, oldName, newName, color);
|
||||||
|
|
||||||
await dispatchable(dispatch);
|
await dispatchable(dispatch, getState);
|
||||||
|
|
||||||
expect(apiClientMock.editTag.callCount).toEqual(1);
|
expect(apiClientMock.editTag.callCount).toEqual(1);
|
||||||
expect(apiClientMock.editTag.getCall(0).args).toEqual([ oldName, newName ]);
|
expect(apiClientMock.editTag.getCall(0).args).toEqual([ oldName, newName ]);
|
||||||
|
@ -89,10 +90,10 @@ describe('tagEditReducer', () => {
|
||||||
const newName = 'bar';
|
const newName = 'bar';
|
||||||
const color = '#ff0000';
|
const color = '#ff0000';
|
||||||
const apiClientMock = createApiClientMock(Promise.reject(error));
|
const apiClientMock = createApiClientMock(Promise.reject(error));
|
||||||
const dispatchable = _editTag(apiClientMock, colorGenerator, oldName, newName, color);
|
const dispatchable = _editTag(() => apiClientMock, colorGenerator, oldName, newName, color);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await dispatchable(dispatch);
|
await dispatchable(dispatch, getState);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e).toEqual(error);
|
expect(e).toEqual(error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ describe('shortUrlDetailReducer', () => {
|
||||||
getShortUrl: sinon.fake.returns(returned),
|
getShortUrl: sinon.fake.returns(returned),
|
||||||
});
|
});
|
||||||
const dispatchMock = sinon.spy();
|
const dispatchMock = sinon.spy();
|
||||||
|
const getState = () => ({});
|
||||||
|
|
||||||
beforeEach(() => dispatchMock.resetHistory());
|
beforeEach(() => dispatchMock.resetHistory());
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ describe('shortUrlDetailReducer', () => {
|
||||||
const ShlinkApiClient = buildApiClientMock(Promise.reject());
|
const ShlinkApiClient = buildApiClientMock(Promise.reject());
|
||||||
const expectedDispatchCalls = 2;
|
const expectedDispatchCalls = 2;
|
||||||
|
|
||||||
await _getShortUrlDetail(ShlinkApiClient, 'abc123')(dispatchMock);
|
await _getShortUrlDetail(() => ShlinkApiClient, 'abc123')(dispatchMock, getState);
|
||||||
|
|
||||||
const [ firstCallArg ] = dispatchMock.getCall(0).args;
|
const [ firstCallArg ] = dispatchMock.getCall(0).args;
|
||||||
const { type: firstCallType } = firstCallArg;
|
const { type: firstCallType } = firstCallArg;
|
||||||
|
@ -76,7 +77,7 @@ describe('shortUrlDetailReducer', () => {
|
||||||
const ShlinkApiClient = buildApiClientMock(Promise.resolve(resolvedShortUrl));
|
const ShlinkApiClient = buildApiClientMock(Promise.resolve(resolvedShortUrl));
|
||||||
const expectedDispatchCalls = 2;
|
const expectedDispatchCalls = 2;
|
||||||
|
|
||||||
await _getShortUrlDetail(ShlinkApiClient, 'abc123')(dispatchMock);
|
await _getShortUrlDetail(() => ShlinkApiClient, 'abc123')(dispatchMock, getState);
|
||||||
|
|
||||||
const [ firstCallArg ] = dispatchMock.getCall(0).args;
|
const [ firstCallArg ] = dispatchMock.getCall(0).args;
|
||||||
const { type: firstCallType } = firstCallArg;
|
const { type: firstCallType } = firstCallArg;
|
||||||
|
|
|
@ -50,6 +50,7 @@ describe('shortUrlVisitsReducer', () => {
|
||||||
getShortUrlVisits: sinon.fake.returns(returned),
|
getShortUrlVisits: sinon.fake.returns(returned),
|
||||||
});
|
});
|
||||||
const dispatchMock = sinon.spy();
|
const dispatchMock = sinon.spy();
|
||||||
|
const getState = () => ({});
|
||||||
|
|
||||||
beforeEach(() => dispatchMock.resetHistory());
|
beforeEach(() => dispatchMock.resetHistory());
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ describe('shortUrlVisitsReducer', () => {
|
||||||
const ShlinkApiClient = buildApiClientMock(Promise.reject());
|
const ShlinkApiClient = buildApiClientMock(Promise.reject());
|
||||||
const expectedDispatchCalls = 2;
|
const expectedDispatchCalls = 2;
|
||||||
|
|
||||||
await _getShortUrlVisits(ShlinkApiClient, 'abc123')(dispatchMock);
|
await _getShortUrlVisits(() => ShlinkApiClient, 'abc123')(dispatchMock, getState);
|
||||||
|
|
||||||
const [ firstCallArg ] = dispatchMock.getCall(0).args;
|
const [ firstCallArg ] = dispatchMock.getCall(0).args;
|
||||||
const { type: firstCallType } = firstCallArg;
|
const { type: firstCallType } = firstCallArg;
|
||||||
|
@ -76,7 +77,7 @@ describe('shortUrlVisitsReducer', () => {
|
||||||
const ShlinkApiClient = buildApiClientMock(Promise.resolve(resolvedVisits));
|
const ShlinkApiClient = buildApiClientMock(Promise.resolve(resolvedVisits));
|
||||||
const expectedDispatchCalls = 2;
|
const expectedDispatchCalls = 2;
|
||||||
|
|
||||||
await _getShortUrlVisits(ShlinkApiClient, 'abc123')(dispatchMock);
|
await _getShortUrlVisits(() => ShlinkApiClient, 'abc123')(dispatchMock, getState);
|
||||||
|
|
||||||
const [ firstCallArg ] = dispatchMock.getCall(0).args;
|
const [ firstCallArg ] = dispatchMock.getCall(0).args;
|
||||||
const { type: firstCallType } = firstCallArg;
|
const { type: firstCallType } = firstCallArg;
|
||||||
|
|
Loading…
Reference in a new issue