globalSelectionStore.spec.jsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {
  2. updateDateTime,
  3. updateEnvironments,
  4. updateProjects,
  5. } from 'app/actionCreators/globalSelection';
  6. import GlobalSelectionStore from 'app/stores/globalSelectionStore';
  7. jest.mock('app/utils/localStorage', () => ({
  8. getItem: () => JSON.stringify({projects: [5], environments: ['staging']}),
  9. setItem: jest.fn(),
  10. }));
  11. describe('GlobalSelectionStore', function () {
  12. afterEach(function () {
  13. GlobalSelectionStore.reset();
  14. });
  15. it('get()', function () {
  16. expect(GlobalSelectionStore.get()).toEqual({
  17. isReady: false,
  18. selection: {
  19. projects: [],
  20. environments: [],
  21. datetime: {period: '14d', start: null, end: null, utc: null},
  22. },
  23. });
  24. });
  25. it('updateProjects()', async function () {
  26. expect(GlobalSelectionStore.get().selection.projects).toEqual([]);
  27. updateProjects([1]);
  28. await tick();
  29. expect(GlobalSelectionStore.get().selection.projects).toEqual([1]);
  30. });
  31. it('updateDateTime()', async function () {
  32. expect(GlobalSelectionStore.get().selection.datetime).toEqual({
  33. period: '14d',
  34. start: null,
  35. end: null,
  36. utc: null,
  37. });
  38. updateDateTime({period: '2h', start: null, end: null});
  39. await tick();
  40. expect(GlobalSelectionStore.get().selection.datetime).toEqual({
  41. period: '2h',
  42. start: null,
  43. end: null,
  44. });
  45. updateDateTime({
  46. period: null,
  47. start: '2018-08-08T00:00:00',
  48. end: '2018-09-08T00:00:00',
  49. utc: true,
  50. });
  51. await tick();
  52. expect(GlobalSelectionStore.get().selection.datetime).toEqual({
  53. period: null,
  54. start: '2018-08-08T00:00:00',
  55. end: '2018-09-08T00:00:00',
  56. utc: true,
  57. });
  58. updateDateTime({
  59. period: null,
  60. start: null,
  61. end: null,
  62. utc: null,
  63. });
  64. await tick();
  65. expect(GlobalSelectionStore.get().selection.datetime).toEqual({
  66. period: null,
  67. start: null,
  68. end: null,
  69. utc: null,
  70. });
  71. });
  72. it('updateEnvironments()', async function () {
  73. expect(GlobalSelectionStore.get().selection.environments).toEqual([]);
  74. updateEnvironments(['alpha']);
  75. await tick();
  76. expect(GlobalSelectionStore.get().selection.environments).toEqual(['alpha']);
  77. });
  78. });