reynoldmorel commented on code in PR #36996:
URL: https://github.com/apache/superset/pull/36996#discussion_r2700519505
##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControls.test.tsx:
##########
@@ -184,3 +190,222 @@ test('renders empty state when no chart customizations
provided', () => {
container.querySelector('.chart-customization-item-wrapper'),
).not.toBeInTheDocument();
});
+
+const createMockFilter = (id: string, name: string) => ({
+ id,
+ name,
+ filterType: 'filter_select',
+ targets: [{ datasetId: 1, column: { name: 'country' } }],
+ defaultDataMask: {},
+ controlValues: {},
+ cascadeParentIds: [],
+ scope: {
+ rootPath: ['ROOT_ID'],
+ excluded: [] as string[],
+ },
+ isInstant: true,
+ allowsMultipleValues: true,
+ isRequired: false,
+});
+
+const getDefaultState = (orientation: FilterBarOrientation) => ({
+ dashboardInfo: {
+ id: 1,
+ filterBarOrientation: orientation,
+ },
+ dashboardLayout: {
+ present: {
+ ROOT_ID: {
+ type: 'ROOT',
+ id: 'ROOT_ID',
+ children: ['TABS-1'],
+ },
+ 'TABS-1': {
+ type: 'TABS',
+ id: 'TABS-1',
+ children: ['TAB-1', 'TAB-2'],
+ },
+ 'TAB-1': {
+ type: 'TAB',
+ id: 'TAB-1',
+ children: ['CHART-1'],
+ },
+ 'TAB-2': {
+ type: 'TAB',
+ id: 'TAB-2',
+ children: ['CHART-2'],
+ },
+ 'CHART-1': {
+ type: 'CHART',
+ id: 'CHART-1',
+ meta: { chartId: 1 },
+ },
+ 'CHART-2': {
+ type: 'CHART',
+ id: 'CHART-2',
+ meta: { chartId: 2 },
+ },
+ },
+ },
+ charts: {
+ 1: { id: 1, formData: {} },
+ 2: { id: 2, formData: {} },
+ },
+ dataMask: {},
+ nativeFilters: {
+ filters: {
+ 'filter-1': createMockFilter('filter-1', 'Country Filter'),
+ 'filter-2': createMockFilter('filter-2', 'Region Filter'),
+ 'filter-3': createMockFilter('filter-3', 'City Filter'),
+ },
+ filterSets: {},
+ },
+ dashboardState: {
+ directPathToChild: [],
+ activeTabs: ['TAB-1'],
+ chartCustomizationItems: [],
+ },
+ sliceEntities: {
+ slices: {
+ 1: {
+ slice_id: 1,
+ slice_name: 'Chart 1',
+ form_data: {},
+ },
+ 2: {
+ slice_id: 2,
+ slice_name: 'Chart 2',
+ form_data: {},
+ },
+ },
+ },
+ datasources: {},
+});
+
+function setupWithFilters(overrideState: any = {}, props: any = {}) {
+ const state = {
+ ...getDefaultState(FilterBarOrientation.Vertical),
+ ...overrideState,
+ };
+ const store = mockStore(state) as Store;
+
+ return render(
+ <Provider store={store}>
+ <FilterControls
+ dataMaskSelected={{}}
+ onFilterSelectionChange={jest.fn()}
+ onPendingCustomizationDataMaskChange={jest.fn()}
+ chartCustomizationValues={[]}
+ {...props}
+ />
+ </Provider>,
+ );
+}
+
+test('FilterControls should mark out-of-scope filters as not overflowed in
vertical mode', () => {
+ const stateWithVertical = getDefaultState(FilterBarOrientation.Vertical);
+
+ stateWithVertical.nativeFilters.filters['filter-3'].scope = {
+ rootPath: ['ROOT_ID'],
+ excluded: ['TAB-1'],
+ };
+
+ const { container } = setupWithFilters(stateWithVertical);
+
+ expect(container).toBeInTheDocument();
+});
+
+test('FilterControls should mark out-of-scope filters as overflowed in
horizontal mode', () => {
+ const stateWithHorizontal = getDefaultState(FilterBarOrientation.Horizontal);
+
+ stateWithHorizontal.nativeFilters.filters['filter-3'].scope = {
+ rootPath: ['ROOT_ID'],
+ excluded: ['TAB-1'],
+ };
+
+ const { container } = setupWithFilters(stateWithHorizontal);
+
+ expect(container).toBeInTheDocument();
+});
+
+test('FilterControls overflowedByIndex calculation respects filter bar
orientation', () => {
+ const verticalState = getDefaultState(FilterBarOrientation.Vertical);
+ verticalState.nativeFilters.filters['filter-2'].scope = {
+ rootPath: ['ROOT_ID'],
+ excluded: ['TAB-1'],
+ };
Review Comment:
nit:
```
{
rootPath: ['ROOT_ID'],
excluded: ['TAB-1'],
}
```
Looks like it is repeated several times, could you move it to the top of the
file and store it a variable? you reuse this variable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]