connectors.spec.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import fetchMock from 'fetch-mock-jest';
  2. import * as actions from 'redux/actions/actions';
  3. import * as thunks from 'redux/actions/thunks';
  4. import mockStoreCreator from 'redux/store/configureStore/mockStoreCreator';
  5. const store = mockStoreCreator;
  6. const clusterName = 'local';
  7. describe('Thunks', () => {
  8. afterEach(() => {
  9. fetchMock.restore();
  10. store.clearActions();
  11. });
  12. describe('fetchConnects', () => {
  13. it('creates GET_CONNECTS__SUCCESS when fetching connects', async () => {
  14. fetchMock.getOnce(`/api/clusters/${clusterName}/connects`, [
  15. { name: 'first', address: 'localhost' },
  16. ]);
  17. await store.dispatch(thunks.fetchConnects(clusterName));
  18. expect(store.getActions()).toEqual([
  19. actions.fetchConnectsAction.request(),
  20. actions.fetchConnectsAction.success({
  21. ...store.getState().connect,
  22. connects: [{ name: 'first', address: 'localhost' }],
  23. }),
  24. ]);
  25. });
  26. it('creates GET_CONNECTS__FAILURE', async () => {
  27. fetchMock.getOnce(`/api/clusters/${clusterName}/connects`, 404);
  28. await store.dispatch(thunks.fetchConnects(clusterName));
  29. expect(store.getActions()).toEqual([
  30. actions.fetchConnectsAction.request(),
  31. actions.fetchConnectsAction.failure({
  32. alert: {
  33. subject: 'connects',
  34. title: `Kafka Connect`,
  35. response: {
  36. status: 404,
  37. statusText: 'Not Found',
  38. body: undefined,
  39. },
  40. },
  41. }),
  42. ]);
  43. });
  44. });
  45. });