bito-code-review[bot] commented on code in PR #36996: URL: https://github.com/apache/superset/pull/36996#discussion_r2698381460
########## superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControls.test.tsx: ########## @@ -0,0 +1,259 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { render } from 'spec/helpers/testing-library'; +import { Provider } from 'react-redux'; +import { Store } from 'redux'; +import configureStore from 'redux-mock-store'; +import thunk from 'redux-thunk'; +import { FilterBarOrientation } from 'src/dashboard/types'; +import FilterControls from './FilterControls'; + +const mockStore = configureStore([thunk]); + +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 setup(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()} + {...props} + /> + </Provider>, + ); +} + +test('FilterControls should mark out-of-scope filters as not overflowed in vertical mode', () => { + const stateWithVertical = getDefaultState(FilterBarOrientation.Vertical); + + // Set up filters where filter-3 is out of scope (not on active tab) + stateWithVertical.nativeFilters.filters['filter-3'].scope = { + rootPath: ['ROOT_ID'], + excluded: ['TAB-1'] as string[], // Exclude from active tab + }; + + const { container } = setup(stateWithVertical); + + // In vertical mode, out-of-scope filters should be in the collapse panel + // not in the overflow dropdown + expect(container).toBeInTheDocument(); + + // The component should render without errors and properly calculate + // that out-of-scope filters are not "overflowed" in vertical mode +}); + +test('FilterControls should mark out-of-scope filters as overflowed in horizontal mode', () => { + const stateWithHorizontal = getDefaultState(FilterBarOrientation.Horizontal); + + // Set up filters where filter-3 is out of scope + stateWithHorizontal.nativeFilters.filters['filter-3'].scope = { + rootPath: ['ROOT_ID'], + excluded: ['TAB-1'] as string[], + }; + + const { container } = setup(stateWithHorizontal); + + // In horizontal mode, out-of-scope filters go to the overflow dropdown + expect(container).toBeInTheDocument(); + + // The component should render and treat out-of-scope filters as overflowed +}); Review Comment: <!-- Bito Reply --> This question isn’t related to the pull request. I can only help with questions about the PR’s code or comments. ########## superset-frontend/src/explore/components/controls/DateFilterControl/tests/DateFilterLabel.test.tsx: ########## @@ -93,3 +93,45 @@ test('Open and close popover', () => { expect(defaultProps.onClosePopover).toHaveBeenCalled(); expect(screen.queryByText('Edit time range')).not.toBeInTheDocument(); }); + +test('DateFilter popover should attach to document.body when not overflowing', () => { + render(setup({ ...defaultProps, isOverflowingFilterBar: false })); + + userEvent.click(screen.getByText(NO_TIME_RANGE)); + + const popover = document.querySelector('.time-range-popover'); + expect(popover?.parentElement).toBe(document.body); +}); + +test('DateFilter popover should attach to parent node when overflowing in filter bar', () => { + render(setup({ ...defaultProps, isOverflowingFilterBar: true })); + + userEvent.click(screen.getByText(NO_TIME_RANGE)); + + // When overflowing, the popover should be attached to the trigger's parent node + // instead of document.body to prevent clipping issues + const popover = document.querySelector('.time-range-popover'); + const trigger = screen.getByTestId(DateFilterTestKey.PopoverOverlay); + + // Verify that the popover's container is the trigger's parent (not document.body) + expect(popover?.parentElement).toBe(trigger.parentElement); +}); + +test('DateFilter should properly handle isOverflowingFilterBar prop changes', () => { + const { rerender } = render( + setup({ ...defaultProps, isOverflowingFilterBar: false }), + ); + + userEvent.click(screen.getByText(NO_TIME_RANGE)); + const popover = document.querySelector('.time-range-popover'); + expect(popover?.parentElement).toBe(document.body); + + // Close and reopen with different prop + userEvent.click(screen.getByText('CANCEL')); + + rerender(setup({ ...defaultProps, isOverflowingFilterBar: true })); + userEvent.click(screen.getByText(NO_TIME_RANGE)); + + // The getPopupContainer behavior should update based on the new prop + expect(defaultProps.onOpenPopover).toHaveBeenCalled(); Review Comment: <!-- Bito Reply --> This question isn’t related to the pull request. I can only help with questions about the PR’s code or comments. ########## superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControls.test.tsx: ########## @@ -0,0 +1,259 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { render } from 'spec/helpers/testing-library'; +import { Provider } from 'react-redux'; +import { Store } from 'redux'; +import configureStore from 'redux-mock-store'; +import thunk from 'redux-thunk'; +import { FilterBarOrientation } from 'src/dashboard/types'; +import FilterControls from './FilterControls'; + +const mockStore = configureStore([thunk]); + +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 setup(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()} + {...props} + /> + </Provider>, + ); +} + +test('FilterControls should mark out-of-scope filters as not overflowed in vertical mode', () => { + const stateWithVertical = getDefaultState(FilterBarOrientation.Vertical); + + // Set up filters where filter-3 is out of scope (not on active tab) + stateWithVertical.nativeFilters.filters['filter-3'].scope = { + rootPath: ['ROOT_ID'], + excluded: ['TAB-1'] as string[], // Exclude from active tab + }; + + const { container } = setup(stateWithVertical); + + // In vertical mode, out-of-scope filters should be in the collapse panel + // not in the overflow dropdown + expect(container).toBeInTheDocument(); + + // The component should render without errors and properly calculate + // that out-of-scope filters are not "overflowed" in vertical mode +}); + +test('FilterControls should mark out-of-scope filters as overflowed in horizontal mode', () => { + const stateWithHorizontal = getDefaultState(FilterBarOrientation.Horizontal); + + // Set up filters where filter-3 is out of scope + stateWithHorizontal.nativeFilters.filters['filter-3'].scope = { + rootPath: ['ROOT_ID'], + excluded: ['TAB-1'] as string[], + }; + + const { container } = setup(stateWithHorizontal); + + // In horizontal mode, out-of-scope filters go to the overflow dropdown + expect(container).toBeInTheDocument(); + + // The component should render and treat out-of-scope filters as overflowed +}); + +test('FilterControls overflowedByIndex calculation respects filter bar orientation', () => { + // Test vertical orientation + const verticalState = getDefaultState(FilterBarOrientation.Vertical); + verticalState.nativeFilters.filters['filter-2'].scope = { + rootPath: ['ROOT_ID'], + excluded: ['TAB-1'] as string[], + }; + + const { rerender, container } = setup(verticalState); + expect(container).toBeInTheDocument(); + + // Test horizontal orientation with same filter setup + const horizontalState = getDefaultState(FilterBarOrientation.Horizontal); + horizontalState.nativeFilters.filters['filter-2'].scope = { + rootPath: ['ROOT_ID'], + excluded: ['TAB-1'] as string[], + }; + + rerender( + <Provider store={mockStore(horizontalState) as Store}> + <FilterControls + dataMaskSelected={{}} + onFilterSelectionChange={jest.fn()} + /> + </Provider>, + ); + + // Component should handle orientation change without errors + expect(container).toBeInTheDocument(); +}); Review Comment: <!-- Bito Reply --> This question isn’t related to the pull request. I can only help with questions about the PR’s code or comments. -- 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]
