Skip to content

Commit 4e1a731

Browse files
Fix: Render tooltip without content in NextExecutionTime component (#238378)
## Summary Problem this PR fixes: The workflow list view seems to only show trigger types for workflows that have a schedule trigger. <img width="5344" height="3054" alt="image" src="https://github.com/user-attachments/assets/3013be24-0632-4f76-8c97-f4c1d892be82" /> ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [ ] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ...
1 parent bc40db0 commit 4e1a731

2 files changed

Lines changed: 154 additions & 10 deletions

File tree

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import { render, screen } from '@testing-library/react';
11+
import React from 'react';
12+
import type { WorkflowTrigger } from '../../../server/lib/schedule_utils';
13+
import { NextExecutionTime } from './next_execution_time';
14+
import { useGetFormattedDateTime } from './use_formatted_date';
15+
import { getWorkflowNextExecutionTime } from '../../lib/next_execution_time';
16+
17+
// Mock the dependencies
18+
jest.mock('./use_formatted_date');
19+
jest.mock('../../lib/next_execution_time');
20+
21+
describe('NextExecutionTime', () => {
22+
const mockGetFormattedDateTime = jest.fn();
23+
const mockGetWorkflowNextExecutionTime = jest.fn();
24+
25+
beforeEach(() => {
26+
jest.clearAllMocks();
27+
(useGetFormattedDateTime as jest.Mock).mockReturnValue(mockGetFormattedDateTime);
28+
(getWorkflowNextExecutionTime as jest.Mock).mockImplementation(
29+
mockGetWorkflowNextExecutionTime
30+
);
31+
});
32+
33+
const createMockTriggers = (overrides: Partial<WorkflowTrigger>[] = []): WorkflowTrigger[] => {
34+
return overrides.map((override) => ({
35+
type: 'scheduled',
36+
enabled: true,
37+
with: { every: '5m' },
38+
...override,
39+
}));
40+
};
41+
42+
const TestChild = () => <div data-test-subj="test-child">Test Child</div>;
43+
44+
describe('children rendering', () => {
45+
it('should always render children regardless of nextExecutionTime', () => {
46+
mockGetWorkflowNextExecutionTime.mockReturnValue(null);
47+
48+
render(
49+
<NextExecutionTime triggers={[]} history={[]}>
50+
<TestChild />
51+
</NextExecutionTime>
52+
);
53+
54+
expect(screen.getByTestId('test-child')).toBeInTheDocument();
55+
});
56+
});
57+
58+
describe('tooltip behavior', () => {
59+
it('should show empty tooltip when nextExecutionTime is null', () => {
60+
mockGetWorkflowNextExecutionTime.mockReturnValue(null);
61+
62+
render(
63+
<NextExecutionTime triggers={[]} history={[]}>
64+
<TestChild />
65+
</NextExecutionTime>
66+
);
67+
68+
// Tooltip should be present but with empty content
69+
expect(screen.getByTestId('test-child')).toBeInTheDocument();
70+
// Verify that getWorkflowNextExecutionTime was called
71+
expect(mockGetWorkflowNextExecutionTime).toHaveBeenCalledWith([], []);
72+
});
73+
});
74+
75+
describe('different trigger combinations', () => {
76+
it('should handle empty triggers array', () => {
77+
mockGetWorkflowNextExecutionTime.mockReturnValue(null);
78+
79+
render(
80+
<NextExecutionTime triggers={[]} history={[]}>
81+
<TestChild />
82+
</NextExecutionTime>
83+
);
84+
85+
expect(mockGetWorkflowNextExecutionTime).toHaveBeenCalledWith([], []);
86+
expect(screen.getByTestId('test-child')).toBeInTheDocument();
87+
});
88+
89+
it('should handle non-scheduled triggers only', () => {
90+
const triggers = createMockTriggers([
91+
{ type: 'manual', enabled: true },
92+
{ type: 'alert', enabled: true },
93+
]);
94+
mockGetWorkflowNextExecutionTime.mockReturnValue(null);
95+
96+
render(
97+
<NextExecutionTime triggers={triggers} history={[]}>
98+
<TestChild />
99+
</NextExecutionTime>
100+
);
101+
102+
expect(mockGetWorkflowNextExecutionTime).toHaveBeenCalledWith(triggers, []);
103+
});
104+
105+
it('should handle scheduled triggers only', () => {
106+
const triggers = createMockTriggers([
107+
{ type: 'scheduled', enabled: true, with: { every: '5m' } },
108+
]);
109+
const nextExecutionTime = new Date('2025-01-15T11:00:00Z');
110+
mockGetWorkflowNextExecutionTime.mockReturnValue(nextExecutionTime);
111+
mockGetFormattedDateTime.mockReturnValue('Jan 15, 2025 11:00 AM');
112+
113+
render(
114+
<NextExecutionTime triggers={triggers} history={[]}>
115+
<TestChild />
116+
</NextExecutionTime>
117+
);
118+
119+
expect(mockGetWorkflowNextExecutionTime).toHaveBeenCalledWith(triggers, []);
120+
expect(screen.getByTestId('test-child')).toBeInTheDocument();
121+
expect(mockGetFormattedDateTime).toHaveBeenCalledWith(nextExecutionTime);
122+
});
123+
124+
it('should handle mixed trigger types', () => {
125+
const triggers = createMockTriggers([
126+
{ type: 'manual', enabled: true },
127+
{ type: 'alert', enabled: true },
128+
{ type: 'scheduled', enabled: true, with: { every: '30m' } },
129+
]);
130+
const nextExecutionTime = new Date('2025-01-15T10:30:00Z');
131+
mockGetWorkflowNextExecutionTime.mockReturnValue(nextExecutionTime);
132+
mockGetFormattedDateTime.mockReturnValue('Jan 15, 2025 10:30 AM');
133+
134+
render(
135+
<NextExecutionTime triggers={triggers} history={[]}>
136+
<TestChild />
137+
</NextExecutionTime>
138+
);
139+
140+
expect(mockGetWorkflowNextExecutionTime).toHaveBeenCalledWith(triggers, []);
141+
expect(screen.getByTestId('test-child')).toBeInTheDocument();
142+
expect(mockGetFormattedDateTime).toHaveBeenCalledWith(nextExecutionTime);
143+
});
144+
});
145+
});

src/platform/plugins/shared/workflows_management/public/shared/ui/next_execution_time.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@ export function NextExecutionTime({ triggers, history, children }: NextExecution
2525
const nextExecutionTime = getWorkflowNextExecutionTime(triggers, history);
2626
const getFormattedDateTime = useGetFormattedDateTime();
2727

28-
if (!nextExecutionTime) {
29-
return null;
30-
}
31-
3228
return (
3329
<EuiToolTip
34-
content={i18n.translate('workflows.workflowList.nextExecutionTime.tooltip', {
35-
defaultMessage: 'Next execution: {date}',
36-
values: {
37-
date: getFormattedDateTime(nextExecutionTime),
38-
},
39-
})}
30+
content={
31+
nextExecutionTime &&
32+
i18n.translate('workflows.workflowList.nextExecutionTime.tooltip', {
33+
defaultMessage: 'Next execution: {date}',
34+
values: {
35+
date: getFormattedDateTime(nextExecutionTime),
36+
},
37+
})
38+
}
4039
>
4140
{children}
4241
</EuiToolTip>

0 commit comments

Comments
 (0)