Skip to content

Commit e0e2b1d

Browse files
committed
test(dashboard): add RTL tests for Range filter vertical spacing
1 parent 65b0433 commit e0e2b1d

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. 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,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { render } from 'spec/helpers/testing-library';
20+
import { NativeFilterType, Filter, Preset } from '@superset-ui/core';
21+
import { FilterBarOrientation } from 'src/dashboard/types';
22+
import { RangeFilterPlugin } from 'src/filters/components';
23+
import FilterControl from './FilterControl';
24+
import { FilterBarScrollContext } from '../Vertical';
25+
26+
class TestPreset extends Preset {
27+
constructor() {
28+
super({
29+
name: 'Test filters',
30+
plugins: [new RangeFilterPlugin().configure({ key: 'filter_range' })],
31+
});
32+
}
33+
}
34+
35+
new TestPreset().register();
36+
37+
const mockFilter: Filter = {
38+
id: 'test-filter-id',
39+
name: 'Test Filter',
40+
filterType: 'filter_select',
41+
targets: [{ datasetId: 1, column: { name: 'test_column' } }],
42+
defaultDataMask: {},
43+
controlValues: {},
44+
cascadeParentIds: [],
45+
scope: { rootPath: [], excluded: [] },
46+
type: NativeFilterType.NativeFilter,
47+
description: 'Test filter description',
48+
};
49+
50+
const mockProps = {
51+
filter: mockFilter,
52+
onFilterSelectionChange: jest.fn(),
53+
inView: true,
54+
showOverflow: false,
55+
parentRef: { current: null },
56+
};
57+
58+
const mockInitialState = {
59+
dashboardLayout: {
60+
present: {},
61+
past: [],
62+
future: [],
63+
},
64+
dashboardState: {
65+
activeTabs: [],
66+
},
67+
nativeFilters: {
68+
filters: {},
69+
},
70+
};
71+
72+
test('vertical FilterControl applies default spacing', () => {
73+
const { container } = render(
74+
<FilterBarScrollContext.Provider value={false}>
75+
<FilterControl
76+
{...mockProps}
77+
orientation={FilterBarOrientation.Vertical}
78+
/>
79+
</FilterBarScrollContext.Provider>,
80+
{ useRedux: true, initialState: mockInitialState },
81+
);
82+
83+
const formItems = container.querySelectorAll('.ant-form-item');
84+
expect(formItems.length).toBeGreaterThan(0);
85+
86+
const firstFormItem = formItems[0] as HTMLElement;
87+
const styles = getComputedStyle(firstFormItem);
88+
const marginValue = parseInt(styles.marginBottom, 10);
89+
90+
expect(marginValue).toBe(24);
91+
});
92+
93+
test('horizontal FilterControl renders correctly', () => {
94+
const { container } = render(
95+
<FilterBarScrollContext.Provider value={false}>
96+
<FilterControl
97+
{...mockProps}
98+
orientation={FilterBarOrientation.Horizontal}
99+
/>
100+
</FilterBarScrollContext.Provider>,
101+
{ useRedux: true, initialState: mockInitialState },
102+
);
103+
104+
expect(container.querySelector('.ant-form-item')).toBeInTheDocument();
105+
});

0 commit comments

Comments
 (0)