mirror of
https://github.com/apache/superset.git
synced 2026-04-07 10:31:50 +00:00
test(native-filters): add integration tests for filter bar (#14098)
* test: add tests for filter bar * test: merge filter bar tests with master * test: add test for filter set * test: filter set tests * test: merge with master * test: fix tests for filter bar * fix: fix CR notes * fix: fix CR notes
This commit is contained in:
@@ -1,110 +0,0 @@
|
||||
/**
|
||||
* 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 React from 'react';
|
||||
import { Provider } from 'react-redux';
|
||||
import { render, screen, fireEvent } from 'spec/helpers/testing-library';
|
||||
import { mockStoreWithChartsInTabsAndRoot } from 'spec/fixtures/mockStore';
|
||||
import { Form, FormInstance } from 'src/common/components';
|
||||
import { NativeFiltersForm } from 'src/dashboard/components/nativeFilters/FiltersConfigModal/types';
|
||||
import FiltersConfigForm from 'src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm';
|
||||
|
||||
describe('FilterScope', () => {
|
||||
const save = jest.fn();
|
||||
let form: FormInstance<NativeFiltersForm>;
|
||||
const mockedProps = {
|
||||
filterId: 'DefaultFilterId',
|
||||
restoreFilter: jest.fn(),
|
||||
parentFilters: [],
|
||||
save,
|
||||
};
|
||||
|
||||
const MockModal = ({ scope }: { scope: object | undefined }) => {
|
||||
const [newForm] = Form.useForm<NativeFiltersForm>();
|
||||
form = newForm;
|
||||
if (scope) {
|
||||
form.setFieldsValue({
|
||||
filters: {
|
||||
[mockedProps.filterId]: {
|
||||
scope,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
return (
|
||||
<Provider store={mockStoreWithChartsInTabsAndRoot}>
|
||||
<Form form={form}>
|
||||
<FiltersConfigForm form={form} {...mockedProps} />
|
||||
</Form>
|
||||
</Provider>
|
||||
);
|
||||
};
|
||||
|
||||
const getWrapper = (scope?: object) => {
|
||||
render(<MockModal scope={scope} />);
|
||||
};
|
||||
|
||||
const getTreeSwitcher = (order = 0) =>
|
||||
document.querySelectorAll('.ant-tree-switcher')[order];
|
||||
|
||||
it('renders "apply to all" filter scope', () => {
|
||||
getWrapper();
|
||||
expect(screen.queryByRole('tree')).toBe(null);
|
||||
});
|
||||
|
||||
it('select tree values with 1 excluded', () => {
|
||||
getWrapper();
|
||||
fireEvent.click(screen.getByLabelText('Apply to specific panels'));
|
||||
expect(screen.getByRole('tree')).not.toBe(null);
|
||||
fireEvent.click(getTreeSwitcher(2));
|
||||
fireEvent.click(screen.getByText('CHART_ID2'));
|
||||
expect(form.getFieldValue('filters')?.[mockedProps.filterId].scope).toEqual(
|
||||
{
|
||||
excluded: [20],
|
||||
rootPath: ['ROOT_ID'],
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('select 1 value only', () => {
|
||||
getWrapper();
|
||||
fireEvent.click(screen.getByLabelText('Apply to specific panels'));
|
||||
expect(screen.getByRole('tree')).not.toBe(null);
|
||||
fireEvent.click(getTreeSwitcher(2));
|
||||
fireEvent.click(screen.getByText('CHART_ID2'));
|
||||
fireEvent.click(screen.getByText('tab1'));
|
||||
expect(form.getFieldValue('filters')?.[mockedProps.filterId].scope).toEqual(
|
||||
{
|
||||
excluded: [18, 20],
|
||||
rootPath: ['ROOT_ID'],
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('correct init tree with values', () => {
|
||||
getWrapper({
|
||||
rootPath: ['TAB_ID'],
|
||||
excluded: [],
|
||||
});
|
||||
fireEvent.click(screen.getByLabelText('Apply to specific panels'));
|
||||
expect(screen.getByRole('tree')).not.toBe(null);
|
||||
expect(document.querySelectorAll('.ant-tree-checkbox-checked').length).toBe(
|
||||
1,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user