consumerGroupSlice.spec.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { store } from 'redux/store';
  2. import {
  3. sortBy,
  4. getConsumerGroupsOrderBy,
  5. getConsumerGroupsSortOrder,
  6. getAreConsumerGroupsPagedFulfilled,
  7. fetchConsumerGroupsPaged,
  8. selectAll,
  9. } from 'redux/reducers/consumerGroups/consumerGroupsSlice';
  10. import { ConsumerGroupOrdering, SortOrder } from 'generated-sources';
  11. import { consumerGroups } from 'redux/reducers/consumerGroups/__test__/fixtures';
  12. describe('Consumer Groups Slice', () => {
  13. describe('Actions', () => {
  14. it('should test the sortBy actions', () => {
  15. expect(store.getState().consumerGroups.sortOrder).toBe(SortOrder.ASC);
  16. store.dispatch(sortBy(ConsumerGroupOrdering.STATE));
  17. expect(getConsumerGroupsOrderBy(store.getState())).toBe(
  18. ConsumerGroupOrdering.STATE
  19. );
  20. expect(getConsumerGroupsSortOrder(store.getState())).toBe(SortOrder.DESC);
  21. store.dispatch(sortBy(ConsumerGroupOrdering.STATE));
  22. expect(getConsumerGroupsSortOrder(store.getState())).toBe(SortOrder.ASC);
  23. });
  24. });
  25. describe('Thunk Actions', () => {
  26. it('should check the fetchConsumerPaged ', () => {
  27. store.dispatch({
  28. type: fetchConsumerGroupsPaged.fulfilled.type,
  29. payload: {
  30. consumerGroups,
  31. },
  32. });
  33. expect(getAreConsumerGroupsPagedFulfilled(store.getState())).toBeTruthy();
  34. expect(selectAll(store.getState())).toEqual(consumerGroups);
  35. store.dispatch({
  36. type: fetchConsumerGroupsPaged.fulfilled.type,
  37. payload: {
  38. consumerGroups: null,
  39. },
  40. });
  41. expect(selectAll(store.getState())).toEqual([]);
  42. });
  43. });
  44. });