Skip to content

Commit df69073

Browse files
committed
test: test splitRangerDateFilters
1 parent d94dbfb commit df69073

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/**
2+
* Datart
3+
*
4+
* Copyright 2021
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import { splitRangerDateFilters } from '../time';
20+
21+
describe('test splitRangerDateFilters', () => {
22+
const rangerDateFilter = {
23+
aggOperator: null,
24+
column: '日期',
25+
sqlOperator: 'BETWEEN',
26+
values: [
27+
{
28+
value: '2004-01-01 00:00:00',
29+
valueType: 'DATE',
30+
},
31+
{
32+
value: '2013-01-01 00:00:00',
33+
valueType: 'DATE',
34+
},
35+
],
36+
};
37+
const badRangerDateFilter = {
38+
aggOperator: null,
39+
column: '日期',
40+
sqlOperator: 'BETWEEN',
41+
values: [
42+
{
43+
value: '2004-01-01 00:00:00',
44+
valueType: 'DATE',
45+
},
46+
],
47+
};
48+
const otherFilter1 = {
49+
aggOperator: null,
50+
column: '日期',
51+
sqlOperator: 'LT',
52+
values: [
53+
{
54+
value: '2011-01-01 00:00:00',
55+
valueType: 'DATE',
56+
},
57+
],
58+
};
59+
60+
const splittedDateFilters = [
61+
{
62+
aggOperator: null,
63+
column: '日期',
64+
sqlOperator: 'GTE',
65+
values: [
66+
{
67+
value: '2004-01-01 00:00:00',
68+
valueType: 'DATE',
69+
},
70+
],
71+
},
72+
{
73+
aggOperator: null,
74+
column: '日期',
75+
sqlOperator: 'LT',
76+
values: [
77+
{
78+
value: '2013-01-01 00:00:00',
79+
valueType: 'DATE',
80+
},
81+
],
82+
},
83+
];
84+
85+
test('should splitRangerDateFilters to 2 filter', () => {
86+
const res1 = splitRangerDateFilters([rangerDateFilter, otherFilter1]);
87+
expect(res1).toEqual([...splittedDateFilters, otherFilter1]);
88+
const res2 = splitRangerDateFilters([rangerDateFilter]);
89+
expect(res2).toEqual([...splittedDateFilters]);
90+
const res3 = splitRangerDateFilters([otherFilter1]);
91+
expect(res3).toEqual([otherFilter1]);
92+
});
93+
test('should splitRangerDateFilters del bad rangeDateFilter', () => {
94+
const res4 = splitRangerDateFilters([badRangerDateFilter]);
95+
expect(res4).toEqual([]);
96+
const res5 = splitRangerDateFilters([badRangerDateFilter, otherFilter1]);
97+
expect(res5).toEqual([otherFilter1]);
98+
});
99+
test('should splitRangerDateFilters not arr to []', () => {
100+
const res1 = splitRangerDateFilters(null as any);
101+
expect(res1).toEqual([]);
102+
const res2 = splitRangerDateFilters(undefined as any);
103+
expect(res2).toEqual([]);
104+
const res4 = splitRangerDateFilters({} as any);
105+
expect(res4).toEqual([]);
106+
const res5 = splitRangerDateFilters('string' as any);
107+
expect(res5).toEqual([]);
108+
});
109+
});

frontend/src/app/utils/time.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function recommendTimeRangeConverter(relativeTimeRange) {
8383
}
8484

8585
export const splitRangerDateFilters = (filters: ChartDataRequestFilter[]) => {
86-
if (!Array.isArray(filters)) return filters;
86+
if (!Array.isArray(filters)) return [];
8787
const newFilter = [] as ChartDataRequestFilter[];
8888
filters.forEach(filter => {
8989
let isTargetFilter = false;

0 commit comments

Comments
 (0)