You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions-test.ts 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { DEFAULT_GRAPH } from '../../../components/activity-graph/utils';
  21. import { parseDate } from '../../../helpers/dates';
  22. import { ProjectAnalysisEventCategory } from '../../../types/project-activity';
  23. import * as actions from '../actions';
  24. const ANALYSES = [
  25. {
  26. key: 'A1',
  27. date: parseDate('2016-10-27T16:33:50+0200'),
  28. events: [
  29. {
  30. key: 'E1',
  31. category: ProjectAnalysisEventCategory.Version,
  32. name: '6.5-SNAPSHOT',
  33. },
  34. ],
  35. },
  36. {
  37. key: 'A2',
  38. date: parseDate('2016-10-27T12:21:15+0200'),
  39. events: [],
  40. },
  41. {
  42. key: 'A3',
  43. date: parseDate('2016-10-26T12:17:29+0200'),
  44. events: [
  45. {
  46. key: 'E2',
  47. category: ProjectAnalysisEventCategory.Other,
  48. name: 'foo',
  49. },
  50. {
  51. key: 'E3',
  52. category: ProjectAnalysisEventCategory.Other,
  53. name: 'foo',
  54. },
  55. ],
  56. },
  57. ];
  58. const newEvent = {
  59. key: 'Enew',
  60. name: 'Foo',
  61. category: ProjectAnalysisEventCategory.Other,
  62. };
  63. const emptyState = {
  64. analyses: [],
  65. analysesLoading: false,
  66. graphLoading: false,
  67. initialized: true,
  68. measuresHistory: [],
  69. measures: [],
  70. metrics: [],
  71. query: { category: '', graph: DEFAULT_GRAPH, project: '', customMetrics: [] },
  72. };
  73. const state = { ...emptyState, analyses: ANALYSES };
  74. it('should never throw when there is no analyses', () => {
  75. expect(actions.addCustomEvent('A1', newEvent)(emptyState).analyses).toHaveLength(0);
  76. expect(actions.deleteEvent('A1', 'Enew')(emptyState).analyses).toHaveLength(0);
  77. expect(actions.changeEvent('A1', newEvent)(emptyState).analyses).toHaveLength(0);
  78. expect(actions.deleteAnalysis('Anew')(emptyState).analyses).toHaveLength(0);
  79. });
  80. describe('addCustomEvent', () => {
  81. it('should correctly add a custom event', () => {
  82. expect(actions.addCustomEvent('A2', newEvent)(state).analyses[1]).toMatchSnapshot();
  83. expect(actions.addCustomEvent('A1', newEvent)(state).analyses[0].events).toContain(newEvent);
  84. });
  85. });
  86. describe('deleteEvent', () => {
  87. it('should correctly remove an event', () => {
  88. expect(actions.deleteEvent('A1', 'E1')(state).analyses[0]).toMatchSnapshot();
  89. expect(actions.deleteEvent('A2', 'E1')(state).analyses[1]).toMatchSnapshot();
  90. expect(actions.deleteEvent('A3', 'E2')(state).analyses[2]).toMatchSnapshot();
  91. });
  92. });
  93. describe('changeEvent', () => {
  94. it('should correctly update an event', () => {
  95. expect(
  96. actions.changeEvent('A1', {
  97. key: 'E1',
  98. name: 'changed',
  99. category: ProjectAnalysisEventCategory.Version,
  100. })(state).analyses[0],
  101. ).toMatchSnapshot();
  102. expect(
  103. actions.changeEvent('A2', {
  104. key: 'E2',
  105. name: 'foo',
  106. category: ProjectAnalysisEventCategory.Version,
  107. })(state).analyses[1].events,
  108. ).toHaveLength(0);
  109. });
  110. });
  111. describe('deleteAnalysis', () => {
  112. it('should correctly delete an analyses', () => {
  113. expect(actions.deleteAnalysis('A1')(state).analyses).toMatchSnapshot();
  114. expect(actions.deleteAnalysis('A5')(state).analyses).toHaveLength(3);
  115. expect(actions.deleteAnalysis('A2')(state).analyses).toHaveLength(2);
  116. });
  117. });