mergeEnvMappings.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import type {MonitorBucketEnvMapping} from 'sentry/views/monitors/components/timeline/types';
  2. import {mergeEnvMappings} from './mergeEnvMappings';
  3. describe('mergeEnvMappings', function () {
  4. it('merges two empty mappings', function () {
  5. const envMappingA: MonitorBucketEnvMapping = {};
  6. const envMappingB: MonitorBucketEnvMapping = {};
  7. const mergedMapping = mergeEnvMappings(envMappingA, envMappingB);
  8. expect(mergedMapping).toEqual({});
  9. });
  10. it('merges one empty mapping with one filled mapping', function () {
  11. const envMappingA: MonitorBucketEnvMapping = {};
  12. const envMappingB: MonitorBucketEnvMapping = {
  13. prod: {in_progress: 0, ok: 1, missed: 0, timeout: 0, error: 0},
  14. };
  15. const mergedMapping = mergeEnvMappings(envMappingA, envMappingB);
  16. expect(mergedMapping).toEqual(envMappingB);
  17. });
  18. it('merges two filled mappings', function () {
  19. const envMappingA: MonitorBucketEnvMapping = {
  20. prod: {in_progress: 0, ok: 0, missed: 1, timeout: 2, error: 1},
  21. };
  22. const envMappingB: MonitorBucketEnvMapping = {
  23. prod: {in_progress: 2, ok: 1, missed: 1, timeout: 0, error: 2},
  24. };
  25. const expectedMerged: MonitorBucketEnvMapping = {
  26. prod: {in_progress: 2, ok: 1, missed: 2, timeout: 2, error: 3},
  27. };
  28. const mergedMapping = mergeEnvMappings(envMappingA, envMappingB);
  29. expect(mergedMapping).toEqual(expectedMerged);
  30. });
  31. it('merges two filled mappings with differing envs', function () {
  32. const envMappingA: MonitorBucketEnvMapping = {
  33. prod: {in_progress: 1, ok: 0, missed: 1, timeout: 2, error: 1},
  34. };
  35. const envMappingB: MonitorBucketEnvMapping = {
  36. dev: {in_progress: 0, ok: 1, missed: 1, timeout: 0, error: 2},
  37. };
  38. const expectedMerged: MonitorBucketEnvMapping = {
  39. prod: {in_progress: 1, ok: 0, missed: 1, timeout: 2, error: 1},
  40. dev: {in_progress: 0, ok: 1, missed: 1, timeout: 0, error: 2},
  41. };
  42. const mergedMapping = mergeEnvMappings(envMappingA, envMappingB);
  43. expect(mergedMapping).toEqual(expectedMerged);
  44. });
  45. });