Skip to content

Commit 738ce66

Browse files
committed
fix frontend tests
1 parent 7bef855 commit 738ce66

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

datahub-web-react/src/app/entityV2/shared/tabs/Dataset/Stats/StatsTabV2/graphs/__tests__/utils/getCalendarStartTimeByTimeRange.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,43 @@ const MOCKED_NOW = 1739791888317;
55

66
describe('getCalendarStartTimeByTimeRange', () => {
77
it('should return correct value for Day of TimeRange', () => {
8-
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.Day);
8+
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.Day, true);
99

1010
expect(response).toEqual(1739705488317);
1111
});
1212

1313
it('should return correct value for Week of TimeRange', () => {
14-
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.Week);
14+
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.Week, true);
1515

1616
expect(response).toEqual(1739187088317);
1717
});
1818

1919
it('should return correct value for Month of TimeRange', () => {
20-
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.Month);
20+
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.Month, true);
2121

2222
expect(response).toEqual(1737113488317);
2323
});
2424

2525
it('should return correct value for Quarter of TimeRange', () => {
26-
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.Quarter);
26+
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.Quarter, true);
2727

2828
expect(response).toEqual(1731843088317);
2929
});
3030

3131
it('should return correct value for HalfYear of TimeRange', () => {
32-
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.HalfYear);
32+
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.HalfYear, true);
3333

3434
expect(response).toEqual(1723894288317);
3535
});
3636

3737
it('should return correct value for Year of TimeRange', () => {
38-
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.Year);
38+
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.Year, true);
3939

4040
expect(response).toEqual(1708169488317);
4141
});
4242

4343
it('should return undefined value for All of TimeRange', () => {
44-
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.All);
44+
const response = getCalendarStartTimeByTimeRange(MOCKED_NOW, TimeRange.All, true);
4545

4646
expect(response).toEqual(undefined);
4747
});

datahub-web-react/src/app/entityV2/shared/tabs/Dataset/Stats/StatsTabV2/graphs/__tests__/utils/roundTimeByTimeRange.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,43 @@ const MOCKED_NOW = 1739791888317;
55

66
describe('roundTimeByTimeRange', () => {
77
it('should return correct value for Day of TimeRange', () => {
8-
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.Day);
8+
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.Day, true);
99

10-
expect(response).toEqual(1739739600000);
10+
expect(response).toEqual(1739750400000);
1111
});
1212

1313
it('should return correct value for Week of TimeRange', () => {
14-
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.Week);
14+
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.Week, true);
1515

16-
expect(response).toEqual(1739739600000);
16+
expect(response).toEqual(1739750400000);
1717
});
1818

1919
it('should return correct value for Month of TimeRange', () => {
20-
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.Month);
20+
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.Month, true);
2121

22-
expect(response).toEqual(1739739600000);
22+
expect(response).toEqual(1739750400000);
2323
});
2424

2525
it('should return correct value for Quarter of TimeRange', () => {
26-
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.Quarter);
26+
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.Quarter, true);
2727

28-
expect(response).toEqual(1739653200000);
28+
expect(response).toEqual(1739664000000);
2929
});
3030

3131
it('should return correct value for HalfYear of TimeRange', () => {
32-
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.HalfYear);
32+
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.HalfYear, true);
3333

34-
expect(response).toEqual(1738357200000);
34+
expect(response).toEqual(1738368000000);
3535
});
3636

3737
it('should return correct value for Year of TimeRange', () => {
38-
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.Year);
38+
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.Year, true);
3939

40-
expect(response).toEqual(1738357200000);
40+
expect(response).toEqual(1738368000000);
4141
});
4242

4343
it('should return the same value for All of TimeRange', () => {
44-
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.All);
44+
const response = roundTimeByTimeRange(MOCKED_NOW, TimeRange.All, true);
4545

4646
expect(response).toEqual(MOCKED_NOW);
4747
});

datahub-web-react/src/app/entityV2/shared/tabs/Dataset/Stats/StatsTabV2/graphs/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ export function getStartTimeByWindowSize(window?: LookbackWindow): number | unde
154154
return getTimeWindowStart(endTimemillis, window.windowSize.interval, window.windowSize.count);
155155
}
156156

157-
export function getCalendarStartTimeByTimeRange(time: number, range: TimeRange): number | undefined {
158-
const dayjsTime = dayjs(time);
157+
export function getCalendarStartTimeByTimeRange(time: number, range: TimeRange, useUtc?: boolean): number | undefined {
158+
let dayjsTime = dayjs(time);
159+
if (useUtc) dayjsTime = dayjsTime.utc();
159160

160161
switch (range) {
161162
case TimeRange.Day:
@@ -175,10 +176,11 @@ export function getCalendarStartTimeByTimeRange(time: number, range: TimeRange):
175176
}
176177
}
177178

178-
export function roundTimeByTimeRange(time: number | undefined, range: TimeRange) {
179+
export function roundTimeByTimeRange(time: number | undefined, range: TimeRange, useUtc?: boolean) {
179180
if (time === undefined) return time;
180181

181-
const dayjsTime = dayjs(time);
182+
let dayjsTime = dayjs(time);
183+
if (useUtc) dayjsTime = dayjsTime.utc();
182184

183185
switch (range) {
184186
case TimeRange.Day:

0 commit comments

Comments
 (0)