foreman-tasks 0.15.1 → 0.15.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.babelrc +9 -1
  3. data/.eslintrc +6 -0
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +6 -0
  6. data/.storybook/webpack.config.js +51 -54
  7. data/app/controllers/foreman_tasks/api/tasks_controller.rb +0 -2
  8. data/app/controllers/foreman_tasks/tasks_controller.rb +6 -1
  9. data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +8 -0
  10. data/app/lib/actions/base.rb +7 -0
  11. data/app/lib/actions/helpers/lifecycle_logging.rb +21 -0
  12. data/app/lib/actions/proxy_action.rb +4 -2
  13. data/app/models/foreman_tasks/task.rb +23 -0
  14. data/app/models/foreman_tasks/task/summarizer.rb +96 -6
  15. data/app/models/foreman_tasks/triggering.rb +2 -2
  16. data/app/models/setting/foreman_tasks.rb +8 -1
  17. data/app/services/foreman_tasks/dashboard_table_filter.rb +47 -0
  18. data/app/services/foreman_tasks/troubleshooting_help_generator.rb +92 -0
  19. data/app/services/ui_notifications/tasks.rb +20 -0
  20. data/app/services/ui_notifications/tasks/task_paused_admin.rb +43 -0
  21. data/app/services/ui_notifications/tasks/task_paused_owner.rb +30 -0
  22. data/app/views/foreman_tasks/tasks/_details.html.erb +5 -3
  23. data/app/views/foreman_tasks/tasks/index.html.erb +13 -0
  24. data/config/routes.rb +1 -0
  25. data/db/migrate/20190318153925_add_task_state_updated_at.foreman_tasks.rb +5 -0
  26. data/db/migrate/20190404132157_add_implicit_varchar_uuid_cast.rb +25 -0
  27. data/db/seeds.d/30-notification_blueprints.rb +33 -0
  28. data/foreman-tasks.gemspec +1 -1
  29. data/lib/foreman_tasks/cleaner.rb +5 -4
  30. data/lib/foreman_tasks/engine.rb +1 -1
  31. data/lib/foreman_tasks/test_helpers.rb +10 -0
  32. data/lib/foreman_tasks/version.rb +1 -1
  33. data/package.json +14 -11
  34. data/test/controllers/tasks_controller_test.rb +10 -0
  35. data/test/foreman_tasks_test_helper.rb +4 -0
  36. data/test/support/dummy_dynflow_action.rb +29 -0
  37. data/test/support/history_tasks_builder.rb +42 -0
  38. data/test/unit/actions/action_with_sub_plans_test.rb +4 -1
  39. data/test/unit/actions/bulk_action_test.rb +2 -0
  40. data/test/unit/cleaner_test.rb +15 -0
  41. data/test/unit/dashboard_table_filter_test.rb +65 -0
  42. data/test/unit/summarizer_test.rb +39 -0
  43. data/test/unit/task_test.rb +14 -0
  44. data/test/unit/troubleshooting_help_generator_test.rb +71 -0
  45. data/test/unit/ui_notifications_test.rb +86 -0
  46. data/webpack/ForemanTasks/Components/Chart/Chart.js +128 -0
  47. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/PausedTasksCard.js +20 -0
  48. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/PausedTasksCard.stories.js +51 -0
  49. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/PausedTasksCard.test.js +11 -0
  50. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/PausedTasksCard/__snapshots__/PausedTasksCard.test.js.snap +36 -0
  51. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/RunningTasksCard.js +20 -0
  52. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/RunningTasksCard.stories.js +51 -0
  53. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/RunningTasksCard.test.js +11 -0
  54. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/RunningTasksCard/__snapshots__/RunningTasksCard.test.js.snap +36 -0
  55. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.js +64 -0
  56. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.scss +25 -0
  57. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.stories.js +28 -0
  58. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.test.js +18 -0
  59. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/__snapshots__/ScheduledTasksCard.test.js.snap +94 -0
  60. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.js +89 -0
  61. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.scss +46 -0
  62. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.stories.js +72 -0
  63. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.test.js +48 -0
  64. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCardHelper.js +63 -0
  65. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/__snapshots__/StoppedTasksCard.test.js.snap +973 -0
  66. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.js +96 -0
  67. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.scss +17 -0
  68. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.stories.js +46 -0
  69. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/TasksDonutCard.test.js +43 -0
  70. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutCard/__snapshots__/TasksDonutCard.test.js.snap +183 -0
  71. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.js +166 -0
  72. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.scss +24 -0
  73. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.stories.js +25 -0
  74. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChart.test.js +40 -0
  75. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChartConstants.js +13 -0
  76. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChartHelper.js +94 -0
  77. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/TasksDonutChartHelper.test.js +152 -0
  78. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/__snapshots__/TasksDonutChart.test.js.snap +302 -0
  79. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/TasksDonutChart/__snapshots__/TasksDonutChartHelper.test.js.snap +21 -0
  80. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.fixtures.js +25 -0
  81. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.js +72 -0
  82. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.stories.js +52 -0
  83. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/TasksCardsGrid.test.js +21 -0
  84. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/__snapshots__/TasksCardsGrid.test.js.snap +223 -0
  85. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js +57 -0
  86. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.scss +26 -0
  87. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.stories.js +22 -0
  88. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.test.js +57 -0
  89. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/__snapshots__/TasksLabelsRow.test.js.snap +47 -0
  90. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.js +51 -0
  91. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.stories.js +23 -0
  92. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/TimeDropDown.test.js +19 -0
  93. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/Components/TimeDropDown/__snapshots__/TimeDropDown.test.js.snap +85 -0
  94. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.js +33 -0
  95. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.scss +11 -0
  96. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.stories.js +22 -0
  97. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/TasksTimeRow.test.js +15 -0
  98. data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksTimeRow/__snapshots__/TasksTimeRow.test.js.snap +41 -0
  99. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboard.js +77 -0
  100. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboard.scss +6 -0
  101. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js +62 -0
  102. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardConstants.js +94 -0
  103. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardHelper.js +78 -0
  104. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardPropTypes.js +13 -0
  105. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardReducer.js +50 -0
  106. data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardSelectors.js +44 -0
  107. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboard.test.js +13 -0
  108. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardActions.test.js +37 -0
  109. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardHelper.test.js +36 -0
  110. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardReducer.test.js +58 -0
  111. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardSelectors.test..js +59 -0
  112. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/__snapshots__/TasksDashboard.test.js.snap +51 -0
  113. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/__snapshots__/TasksDashboardActions.test.js.snap +61 -0
  114. data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/__snapshots__/TasksDashboardReducer.test.js.snap +280 -0
  115. data/webpack/ForemanTasks/Components/TasksDashboard/index.js +25 -0
  116. data/webpack/ForemanTasks/ForemanTasksReducers.js +10 -0
  117. data/webpack/ForemanTasks/ForemanTasksSelectors.js +1 -0
  118. data/webpack/__mocks__/foremanReact/API.js +7 -0
  119. data/webpack/__mocks__/foremanReact/common/I18n.js +5 -0
  120. data/webpack/__mocks__/foremanReact/common/helpers.js +3 -0
  121. data/webpack/index.js +13 -1
  122. data/webpack/stories/decorators/index.js +1 -0
  123. data/webpack/stories/decorators/withCardsDecorator.js +14 -0
  124. data/webpack/stories/index.js +1 -3
  125. data/webpack/stories/index.scss +6 -0
  126. metadata +101 -8
  127. data/webpack/ForemanTasks/components/Hello/Hello.stories.js +0 -5
  128. data/webpack/ForemanTasks/components/Hello/__tests__/Hello.test.js +0 -11
  129. data/webpack/ForemanTasks/components/Hello/__tests__/__snapshots__/Hello.test.js.snap +0 -7
  130. data/webpack/ForemanTasks/components/Hello/index.js +0 -5
@@ -0,0 +1,24 @@
1
+ .tasks-donut-chart {
2
+ .c3.not-focused {
3
+ opacity: 0.3;
4
+ }
5
+ .c3-chart-arcs-title {
6
+ cursor: pointer;
7
+
8
+ &:hover {
9
+ .donut-title-big-pf,
10
+ .donut-title-small-pf {
11
+ font-weight: bold;
12
+ }
13
+ }
14
+ }
15
+
16
+ &.tasks-donut-selected {
17
+ .c3-chart-arcs-title {
18
+ .donut-title-big-pf,
19
+ .donut-title-small-pf {
20
+ font-weight: bold;
21
+ }
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { storiesOf } from '@storybook/react';
3
+ import { withKnobs, number, text, select } from '@storybook/addon-knobs';
4
+ import { action } from '@storybook/addon-actions';
5
+
6
+ import { TASKS_DONUT_CHART_FOCUSED_ON_OPTIONS_ARRAY } from './TasksDonutChartConstants';
7
+ import TasksDonutChart from './TasksDonutChart';
8
+
9
+ storiesOf('TasksDashboard/TasksCardsGrid', module)
10
+ .addDecorator(withKnobs)
11
+ .add('TasksDonutChart', () => (
12
+ <TasksDonutChart
13
+ last={number('last', 3)}
14
+ older={number('older', 5)}
15
+ time={text('time', '24h')}
16
+ focusedOn={select(
17
+ 'focusedOn',
18
+ TASKS_DONUT_CHART_FOCUSED_ON_OPTIONS_ARRAY,
19
+ TasksDonutChart.defaultProps.focusedOn
20
+ )}
21
+ onTotalClick={action('onTotalClick')}
22
+ onLastClick={action('onLastClick')}
23
+ onOlderClick={action('onOlderClick')}
24
+ />
25
+ ));
@@ -0,0 +1,40 @@
1
+ import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
2
+
3
+ import { TASKS_DONUT_CHART_FOCUSED_ON_OPTIONS_ARRAY } from './TasksDonutChartConstants';
4
+ import TasksDonutChart from './TasksDonutChart';
5
+
6
+ jest.mock('./TasksDonutChartHelper', () => ({
7
+ shouleBeSelected: focusedOn => focusedOn !== 'normal' && focusedOn !== 'none',
8
+ getBaseChartConfig: jest.fn(() => ({ base: 'some-base-config' })),
9
+ createChartData: jest.fn(() => ({
10
+ columns: 'some-columns',
11
+ names: 'some-names',
12
+ onItemClick: jest.fn(),
13
+ })),
14
+ updateChartTitle: jest.fn(),
15
+ }));
16
+
17
+ const createRequiredProps = () => ({ last: 3, older: 5 });
18
+
19
+ const fixtures = {
20
+ 'render with minimal props': { ...createRequiredProps() },
21
+ 'render with props': {
22
+ ...createRequiredProps(),
23
+ className: 'some-class',
24
+ time: 'time-period',
25
+ colorsPattern: ['color1', 'color2'],
26
+ onTotalClick: jest.fn(),
27
+ onLastClick: jest.fn(),
28
+ onOlderClick: jest.fn(),
29
+ },
30
+ };
31
+
32
+ TASKS_DONUT_CHART_FOCUSED_ON_OPTIONS_ARRAY.forEach(mode => {
33
+ fixtures[`render with focused-on ${mode}`] = {
34
+ ...createRequiredProps(),
35
+ focusedOn: mode,
36
+ };
37
+ });
38
+
39
+ describe('TasksDonutChart', () =>
40
+ testComponentSnapshotsWithFixtures(TasksDonutChart, fixtures));
@@ -0,0 +1,13 @@
1
+ export const TASKS_DONUT_CHART_FOCUSED_ON_OPTIONS = {
2
+ NORMAL: 'normal', // normal-mode
3
+ TOTAL: 'total', // total-mode
4
+ LAST: 'last', // last X mode
5
+ OLDER: 'older', // older then X mode
6
+ NONE: 'none', // unfocus-mode: another card is selected
7
+ };
8
+
9
+ export const TASKS_DONUT_CHART_FOCUSED_ON_OPTIONS_ARRAY = Object.values(
10
+ TASKS_DONUT_CHART_FOCUSED_ON_OPTIONS
11
+ );
12
+
13
+ export const COLLOR_PATTERN = ['#C315C7', '#0089C9'];
@@ -0,0 +1,94 @@
1
+ import { translate as __, sprintf } from 'foremanReact/common/I18n';
2
+ import { TASKS_DONUT_CHART_FOCUSED_ON_OPTIONS } from './TasksDonutChartConstants';
3
+
4
+ const {
5
+ LAST,
6
+ OLDER,
7
+ TOTAL,
8
+ NONE,
9
+ NORMAL,
10
+ } = TASKS_DONUT_CHART_FOCUSED_ON_OPTIONS;
11
+
12
+ export const getBaseChartConfig = () =>
13
+ window.patternfly.c3ChartDefaults().getDefaultDonutConfig();
14
+
15
+ export const shouleBeSelected = focusedOn =>
16
+ focusedOn !== NORMAL && focusedOn !== NONE;
17
+
18
+ export const getFocusedOn = (query, wantedState, wantedTime) => {
19
+ if (query.state === wantedState) {
20
+ if (query.time === wantedTime) {
21
+ switch (query.mode) {
22
+ case 'last':
23
+ return LAST;
24
+ case 'older':
25
+ return OLDER;
26
+ default:
27
+ }
28
+ }
29
+
30
+ return TOTAL;
31
+ }
32
+
33
+ return query.state ? NONE : NORMAL;
34
+ };
35
+
36
+ export const createChartData = ({
37
+ last,
38
+ older,
39
+ time,
40
+ onLastClick,
41
+ onOlderClick,
42
+ }) => {
43
+ const lastKey = LAST;
44
+ const olderKey = OLDER;
45
+
46
+ const data = {
47
+ [lastKey]: {
48
+ name: sprintf(__('%(last)s Last %(time)s'), { last, time }),
49
+ value: last,
50
+ onClick: onLastClick,
51
+ },
52
+ [olderKey]: {
53
+ name: sprintf(__('%(older)s Older %(time)s'), {
54
+ older,
55
+ time,
56
+ }),
57
+ value: older,
58
+ onClick: onOlderClick,
59
+ },
60
+ };
61
+
62
+ const columns = Object.entries(data).map(([key, item]) => [key, item.value]);
63
+ const names = {
64
+ [lastKey]: data[lastKey].name,
65
+ [olderKey]: data[olderKey].name,
66
+ };
67
+ const onItemClick = key => data[key].onClick();
68
+
69
+ return { columns, names, onItemClick };
70
+ };
71
+
72
+ export const updateChartTitle = ({ chartElement, value }) =>
73
+ window.patternfly.pfSetDonutChartTitle(chartElement, value, __('Total'));
74
+
75
+ export const assignExtraChartEvents = ({
76
+ chartElement,
77
+ onClick,
78
+ onMouseOver,
79
+ onMouseOut,
80
+ }) =>
81
+ window.d3
82
+ .select(chartElement)
83
+ .select('text.c3-chart-arcs-title')
84
+ .on('click', onClick)
85
+ .on('mouseover', onMouseOver)
86
+ .on('mouseout', onMouseOut);
87
+
88
+ export const clearExtraChartEvents = chartElement =>
89
+ window.d3
90
+ .select(chartElement)
91
+ .select('text.c3-chart-arcs-title')
92
+ .on('click', null)
93
+ .on('mouseover', null)
94
+ .on('mouseout', null);
@@ -0,0 +1,152 @@
1
+ import { TASKS_DONUT_CHART_FOCUSED_ON_OPTIONS } from './TasksDonutChartConstants';
2
+ import {
3
+ getBaseChartConfig,
4
+ shouleBeSelected,
5
+ getFocusedOn,
6
+ createChartData,
7
+ updateChartTitle,
8
+ assignExtraChartEvents,
9
+ clearExtraChartEvents,
10
+ } from './TasksDonutChartHelper';
11
+
12
+ const {
13
+ LAST,
14
+ OLDER,
15
+ TOTAL,
16
+ NONE,
17
+ NORMAL,
18
+ } = TASKS_DONUT_CHART_FOCUSED_ON_OPTIONS;
19
+
20
+ const defaultChartConfig = {
21
+ baseConfig1: 'base-config-1',
22
+ baseConfig2: 'base-config-2',
23
+ };
24
+ const c3ChartDefaults = () => ({
25
+ getDefaultDonutConfig: () => defaultChartConfig,
26
+ });
27
+ let pfSetDonutChartTitle;
28
+ let d3Select;
29
+ let d3On;
30
+
31
+ describe('TasksDonutChartHelper', () => {
32
+ beforeEach(() => {
33
+ pfSetDonutChartTitle = jest.fn();
34
+ d3Select = jest.fn(() => global.window.d3);
35
+ d3On = jest.fn(() => global.window.d3);
36
+
37
+ global.window.patternfly = {
38
+ c3ChartDefaults,
39
+ pfSetDonutChartTitle,
40
+ };
41
+ global.window.d3 = {
42
+ select: d3Select,
43
+ on: d3On,
44
+ };
45
+ });
46
+
47
+ it('should contain the base chart config', () => {
48
+ expect(getBaseChartConfig()).toEqual(defaultChartConfig);
49
+ });
50
+
51
+ it('should decide if should-be-selected based on focused-on', () => {
52
+ const selectedFocusedOn = [LAST, OLDER, TOTAL];
53
+ const noneSelectedFocusedOn = [NONE, NORMAL];
54
+
55
+ selectedFocusedOn.forEach(opt => expect(shouleBeSelected(opt)).toBe(true));
56
+ noneSelectedFocusedOn.forEach(opt =>
57
+ expect(shouleBeSelected(opt)).toBe(false)
58
+ );
59
+ });
60
+
61
+ it('should get focused-on', () => {
62
+ const optionsMap = {
63
+ [NORMAL]: {
64
+ query: {},
65
+ wantedState: '',
66
+ wantedTime: '',
67
+ },
68
+ [NONE]: {
69
+ query: { state: 'some-state' },
70
+ wantedState: '',
71
+ wantedTime: '',
72
+ },
73
+ [LAST]: {
74
+ query: { state: 'wanted-state', time: 'wanted-time', mode: LAST },
75
+ wantedState: 'wanted-state',
76
+ wantedTime: 'wanted-time',
77
+ },
78
+ [OLDER]: {
79
+ query: { state: 'wanted-state', time: 'wanted-time', mode: OLDER },
80
+ wantedState: 'wanted-state',
81
+ wantedTime: 'wanted-time',
82
+ },
83
+ [TOTAL]: {
84
+ query: { state: 'wanted-state' },
85
+ wantedState: 'wanted-state',
86
+ wantedTime: 'wanted-time',
87
+ },
88
+ };
89
+
90
+ Object.entries(optionsMap).forEach(([focus, options]) => {
91
+ const focusedOn = getFocusedOn(
92
+ options.query,
93
+ options.wantedState,
94
+ options.wantedTime
95
+ );
96
+
97
+ expect(focusedOn).toBe(focus);
98
+ });
99
+ });
100
+
101
+ it('should create chart-data', () => {
102
+ expect(
103
+ createChartData({
104
+ last: 1,
105
+ older: 3,
106
+ time: '24h',
107
+ onLastClick: jest.fn(),
108
+ onOlderClick: jest.fn(),
109
+ })
110
+ ).toMatchSnapshot();
111
+ });
112
+
113
+ it('should update chart-title', () => {
114
+ const chartElement = 'some-element';
115
+ const value = 'some-value';
116
+ updateChartTitle({ chartElement, value });
117
+
118
+ expect(pfSetDonutChartTitle).toBeCalledWith(chartElement, value, 'Total');
119
+ });
120
+
121
+ it('should assign extra chart-events', () => {
122
+ const chartElement = 'some-element';
123
+ const onClick = jest.fn();
124
+ const onMouseOver = jest.fn();
125
+ const onMouseOut = jest.fn();
126
+
127
+ assignExtraChartEvents({
128
+ chartElement,
129
+ onClick,
130
+ onMouseOver,
131
+ onMouseOut,
132
+ });
133
+
134
+ expect(d3Select).toHaveBeenNthCalledWith(1, chartElement);
135
+ expect(d3Select).toHaveBeenNthCalledWith(2, 'text.c3-chart-arcs-title');
136
+ expect(d3On).toHaveBeenNthCalledWith(1, 'click', onClick);
137
+ expect(d3On).toHaveBeenNthCalledWith(2, 'mouseover', onMouseOver);
138
+ expect(d3On).toHaveBeenNthCalledWith(3, 'mouseout', onMouseOut);
139
+ });
140
+
141
+ it('should clear extra chart-events', () => {
142
+ const chartElement = 'some-element';
143
+
144
+ clearExtraChartEvents(chartElement);
145
+
146
+ expect(d3Select).toHaveBeenNthCalledWith(1, chartElement);
147
+ expect(d3Select).toHaveBeenNthCalledWith(2, 'text.c3-chart-arcs-title');
148
+ expect(d3On).toHaveBeenNthCalledWith(1, 'click', null);
149
+ expect(d3On).toHaveBeenNthCalledWith(2, 'mouseover', null);
150
+ expect(d3On).toHaveBeenNthCalledWith(3, 'mouseout', null);
151
+ });
152
+ });
@@ -0,0 +1,302 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`TasksDonutChart render with focused-on last 1`] = `
4
+ <C3Chart
5
+ base="some-base-config"
6
+ className="donut-chart-pf tasks-donut-chart tasks-donut-selected"
7
+ color={
8
+ Object {
9
+ "pattern": Array [
10
+ "#C315C7",
11
+ "#0089C9",
12
+ ],
13
+ }
14
+ }
15
+ data={
16
+ Object {
17
+ "columns": "some-columns",
18
+ "names": "some-names",
19
+ "onclick": [Function],
20
+ "onmouseout": [Function],
21
+ "onmouseover": [Function],
22
+ "type": "donut",
23
+ }
24
+ }
25
+ legend={
26
+ Object {
27
+ "item": Object {
28
+ "onclick": [Function],
29
+ "onmouseout": [Function],
30
+ "onmouseover": [Function],
31
+ },
32
+ "position": "right",
33
+ "show": true,
34
+ }
35
+ }
36
+ onChartCreate={[Function]}
37
+ size={
38
+ Object {
39
+ "height": 120,
40
+ }
41
+ }
42
+ type="donut"
43
+ />
44
+ `;
45
+
46
+ exports[`TasksDonutChart render with focused-on none 1`] = `
47
+ <C3Chart
48
+ base="some-base-config"
49
+ className="donut-chart-pf tasks-donut-chart"
50
+ color={
51
+ Object {
52
+ "pattern": Array [
53
+ "#C315C7",
54
+ "#0089C9",
55
+ ],
56
+ }
57
+ }
58
+ data={
59
+ Object {
60
+ "columns": "some-columns",
61
+ "names": "some-names",
62
+ "onclick": [Function],
63
+ "onmouseout": [Function],
64
+ "onmouseover": [Function],
65
+ "type": "donut",
66
+ }
67
+ }
68
+ legend={
69
+ Object {
70
+ "item": Object {
71
+ "onclick": [Function],
72
+ "onmouseout": [Function],
73
+ "onmouseover": [Function],
74
+ },
75
+ "position": "right",
76
+ "show": true,
77
+ }
78
+ }
79
+ onChartCreate={[Function]}
80
+ size={
81
+ Object {
82
+ "height": 120,
83
+ }
84
+ }
85
+ type="donut"
86
+ />
87
+ `;
88
+
89
+ exports[`TasksDonutChart render with focused-on normal 1`] = `
90
+ <C3Chart
91
+ base="some-base-config"
92
+ className="donut-chart-pf tasks-donut-chart"
93
+ color={
94
+ Object {
95
+ "pattern": Array [
96
+ "#C315C7",
97
+ "#0089C9",
98
+ ],
99
+ }
100
+ }
101
+ data={
102
+ Object {
103
+ "columns": "some-columns",
104
+ "names": "some-names",
105
+ "onclick": [Function],
106
+ "onmouseout": [Function],
107
+ "onmouseover": [Function],
108
+ "type": "donut",
109
+ }
110
+ }
111
+ legend={
112
+ Object {
113
+ "item": Object {
114
+ "onclick": [Function],
115
+ "onmouseout": [Function],
116
+ "onmouseover": [Function],
117
+ },
118
+ "position": "right",
119
+ "show": true,
120
+ }
121
+ }
122
+ onChartCreate={[Function]}
123
+ size={
124
+ Object {
125
+ "height": 120,
126
+ }
127
+ }
128
+ type="donut"
129
+ />
130
+ `;
131
+
132
+ exports[`TasksDonutChart render with focused-on older 1`] = `
133
+ <C3Chart
134
+ base="some-base-config"
135
+ className="donut-chart-pf tasks-donut-chart tasks-donut-selected"
136
+ color={
137
+ Object {
138
+ "pattern": Array [
139
+ "#C315C7",
140
+ "#0089C9",
141
+ ],
142
+ }
143
+ }
144
+ data={
145
+ Object {
146
+ "columns": "some-columns",
147
+ "names": "some-names",
148
+ "onclick": [Function],
149
+ "onmouseout": [Function],
150
+ "onmouseover": [Function],
151
+ "type": "donut",
152
+ }
153
+ }
154
+ legend={
155
+ Object {
156
+ "item": Object {
157
+ "onclick": [Function],
158
+ "onmouseout": [Function],
159
+ "onmouseover": [Function],
160
+ },
161
+ "position": "right",
162
+ "show": true,
163
+ }
164
+ }
165
+ onChartCreate={[Function]}
166
+ size={
167
+ Object {
168
+ "height": 120,
169
+ }
170
+ }
171
+ type="donut"
172
+ />
173
+ `;
174
+
175
+ exports[`TasksDonutChart render with focused-on total 1`] = `
176
+ <C3Chart
177
+ base="some-base-config"
178
+ className="donut-chart-pf tasks-donut-chart tasks-donut-selected"
179
+ color={
180
+ Object {
181
+ "pattern": Array [
182
+ "#C315C7",
183
+ "#0089C9",
184
+ ],
185
+ }
186
+ }
187
+ data={
188
+ Object {
189
+ "columns": "some-columns",
190
+ "names": "some-names",
191
+ "onclick": [Function],
192
+ "onmouseout": [Function],
193
+ "onmouseover": [Function],
194
+ "type": "donut",
195
+ }
196
+ }
197
+ legend={
198
+ Object {
199
+ "item": Object {
200
+ "onclick": [Function],
201
+ "onmouseout": [Function],
202
+ "onmouseover": [Function],
203
+ },
204
+ "position": "right",
205
+ "show": true,
206
+ }
207
+ }
208
+ onChartCreate={[Function]}
209
+ size={
210
+ Object {
211
+ "height": 120,
212
+ }
213
+ }
214
+ type="donut"
215
+ />
216
+ `;
217
+
218
+ exports[`TasksDonutChart render with minimal props 1`] = `
219
+ <C3Chart
220
+ base="some-base-config"
221
+ className="donut-chart-pf tasks-donut-chart"
222
+ color={
223
+ Object {
224
+ "pattern": Array [
225
+ "#C315C7",
226
+ "#0089C9",
227
+ ],
228
+ }
229
+ }
230
+ data={
231
+ Object {
232
+ "columns": "some-columns",
233
+ "names": "some-names",
234
+ "onclick": [Function],
235
+ "onmouseout": [Function],
236
+ "onmouseover": [Function],
237
+ "type": "donut",
238
+ }
239
+ }
240
+ legend={
241
+ Object {
242
+ "item": Object {
243
+ "onclick": [Function],
244
+ "onmouseout": [Function],
245
+ "onmouseover": [Function],
246
+ },
247
+ "position": "right",
248
+ "show": true,
249
+ }
250
+ }
251
+ onChartCreate={[Function]}
252
+ size={
253
+ Object {
254
+ "height": 120,
255
+ }
256
+ }
257
+ type="donut"
258
+ />
259
+ `;
260
+
261
+ exports[`TasksDonutChart render with props 1`] = `
262
+ <C3Chart
263
+ base="some-base-config"
264
+ className="donut-chart-pf tasks-donut-chart some-class"
265
+ color={
266
+ Object {
267
+ "pattern": Array [
268
+ "color1",
269
+ "color2",
270
+ ],
271
+ }
272
+ }
273
+ data={
274
+ Object {
275
+ "columns": "some-columns",
276
+ "names": "some-names",
277
+ "onclick": [Function],
278
+ "onmouseout": [Function],
279
+ "onmouseover": [Function],
280
+ "type": "donut",
281
+ }
282
+ }
283
+ legend={
284
+ Object {
285
+ "item": Object {
286
+ "onclick": [Function],
287
+ "onmouseout": [Function],
288
+ "onmouseover": [Function],
289
+ },
290
+ "position": "right",
291
+ "show": true,
292
+ }
293
+ }
294
+ onChartCreate={[Function]}
295
+ size={
296
+ Object {
297
+ "height": 120,
298
+ }
299
+ }
300
+ type="donut"
301
+ />
302
+ `;