Skip to content

Commit 9731654

Browse files
fix: time conversion issue for table freshness test (#24900)
* fix: time conversion issue for table freshness test * Update openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TestSummaryCustomTooltip/TestSummaryCustomTooltip.test.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f7fba14 commit 9731654

7 files changed

Lines changed: 611 additions & 24 deletions

File tree

openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TestSummary/TestSummaryGraph.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jest.mock('../../../../utils/date-time/DateTimeUtils', () => ({
127127
getEpochMillisForPastDays: jest.fn().mockReturnValue(1709424034000),
128128
getStartOfDayInMillis: jest.fn().mockImplementation((val) => val),
129129
getEndOfDayInMillis: jest.fn().mockImplementation((val) => val),
130-
convertMillisecondsToHumanReadableFormat: jest
130+
convertSecondsToHumanReadableFormat: jest
131131
.fn()
132132
.mockImplementation((val) => `${val}ms`),
133133
}));

openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TestSummary/TestSummaryGraph.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import {
6262
} from '../../../../utils/ChartUtils';
6363
import { prepareChartData } from '../../../../utils/DataQuality/TestSummaryGraphUtils';
6464
import {
65-
convertMillisecondsToHumanReadableFormat,
65+
convertSecondsToHumanReadableFormat,
6666
formatDateTime,
6767
} from '../../../../utils/date-time/DateTimeUtils';
6868
import { useActivityFeedProvider } from '../../../ActivityFeed/ActivityFeedProvider/ActivityFeedProvider';
@@ -179,8 +179,8 @@ function TestSummaryGraph({
179179
// Todo: need to find better approach to create dynamic scale for graph, need to work with @TeddyCr for the same!
180180
const formatYAxis = (value: number) => {
181181
return testDefinitionName === TABLE_DATA_TO_BE_FRESH || isFreshnessTest
182-
? // table freshness will always have output value in seconds, so we need to convert it to milliseconds
183-
convertMillisecondsToHumanReadableFormat(value * 1000, 2)
182+
? // table freshness value is in seconds from Python/backend, use dedicated seconds converter
183+
convertSecondsToHumanReadableFormat(value, 2)
184184
: axisTickFormatter(value);
185185
};
186186

openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TestSummaryCustomTooltip/TestSummaryCustomTooltip.component.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { TABLE_FRESHNESS_KEY } from '../../../../constants/TestSuite.constant';
2020
import { Thread } from '../../../../generated/entity/feed/thread';
2121
import { formatNumberWithComma } from '../../../../utils/CommonUtils';
2222
import {
23-
convertMillisecondsToHumanReadableFormat,
23+
convertSecondsToHumanReadableFormat,
2424
formatDateTimeLong,
2525
} from '../../../../utils/date-time/DateTimeUtils';
2626
import { getTaskDetailPath } from '../../../../utils/TasksUtils';
@@ -91,11 +91,10 @@ const TestSummaryCustomTooltip = (
9191
</span>
9292
<span className="font-medium" data-testid={key}>
9393
{key === TABLE_FRESHNESS_KEY && isNumber(value)
94-
? // freshness will always be in seconds, so we need to convert it to milliseconds
95-
convertMillisecondsToHumanReadableFormat(
96-
value * 1000,
94+
? // freshness value is in seconds from Python/backend, use dedicated seconds converter
95+
convertSecondsToHumanReadableFormat(
96+
value,
9797
undefined,
98-
false,
9998
// negative value will be shown as late by
10099
`${t('label.late-by')} `
101100
)

openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TestSummaryCustomTooltip/TestSummaryCustomTooltip.test.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jest.mock('../../../../utils/date-time/DateTimeUtils', () => ({
6161
formatDateTimeLong: jest
6262
.fn()
6363
.mockReturnValue('Jan 3, 2024, 6:45 PM (UTC+05:30)'),
64-
convertMillisecondsToHumanReadableFormat: jest
64+
convertSecondsToHumanReadableFormat: jest
6565
.fn()
6666
.mockReturnValue('7Y 2M 22d 9m 24s'),
6767
}));
@@ -88,29 +88,29 @@ describe('Test TestSummaryCustomTooltip component', () => {
8888
expect(
8989
await screen.findByTestId('test-summary-tooltip-container')
9090
).toBeInTheDocument();
91-
expect((await screen.findByTestId('status')).textContent).toEqual('Failed');
92-
expect((await screen.findByTestId('minValueLength')).textContent).toEqual(
91+
expect((await screen.findByTestId('status')).textContent).toBe('Failed');
92+
expect((await screen.findByTestId('minValueLength')).textContent).toBe(
9393
'12'
9494
);
95-
expect((await screen.findByTestId('maxValueLength')).textContent).toEqual(
95+
expect((await screen.findByTestId('maxValueLength')).textContent).toBe(
9696
'24'
9797
);
98-
expect((await screen.findByTestId('passedRows')).textContent).toEqual('4');
99-
expect((await screen.findByTestId('failedRows')).textContent).toEqual('2');
98+
expect((await screen.findByTestId('passedRows')).textContent).toBe('4');
99+
expect((await screen.findByTestId('failedRows')).textContent).toBe('2');
100100
expect(
101101
(await screen.findByTestId('passedRowsPercentage')).textContent
102-
).toEqual('60%');
102+
).toBe('60%');
103103
expect(
104104
(await screen.findByTestId('failedRowsPercentage')).textContent
105-
).toEqual('40%');
105+
).toBe('40%');
106106
expect(screen.queryByText('name')).not.toBeInTheDocument();
107107
});
108108

109-
it('should display freshness in values in milliseconds', async () => {
109+
it('should display freshness values in seconds', async () => {
110110
render(<TestSummaryCustomTooltip {...mockPropsWithFreshness} />);
111111

112-
expect((await screen.findByTestId('status')).textContent).toEqual('Failed');
113-
expect((await screen.findByTestId('freshness')).textContent).toEqual(
112+
expect((await screen.findByTestId('status')).textContent).toBe('Failed');
113+
expect((await screen.findByTestId('freshness')).textContent).toBe(
114114
'7Y 2M 22d 9m 24s'
115115
);
116116
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2025 Collate.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
export const MONTHS_IN_YEAR = 12;
14+
export const DAYS_IN_MONTH = 30;
15+
export const HOURS_IN_DAY = 24;
16+
export const HOUR_SECONDS = 3600;
17+
export const MINUTE_SECONDS = 60;
18+
export const YEAR_SECONDS =
19+
MONTHS_IN_YEAR * DAYS_IN_MONTH * HOURS_IN_DAY * HOUR_SECONDS; // 31,104,000 seconds (12 months × 30 days)
20+
export const MONTH_SECONDS = DAYS_IN_MONTH * HOURS_IN_DAY * HOUR_SECONDS; // 2,592,000 seconds (average month)
21+
export const DAY_SECONDS = HOURS_IN_DAY * HOUR_SECONDS; // 86,400 seconds

0 commit comments

Comments
 (0)