diff --git a/superset-frontend/src/dashboard/components/CrossFilterScopingModal/CrossFilterScopingForm/CrossFilterScopingForm.test.tsx b/superset-frontend/src/dashboard/components/CrossFilterScopingModal/CrossFilterScopingForm/CrossFilterScopingForm.test.tsx new file mode 100644 index 0000000000000..581ac8e31e3c7 --- /dev/null +++ b/superset-frontend/src/dashboard/components/CrossFilterScopingModal/CrossFilterScopingForm/CrossFilterScopingForm.test.tsx @@ -0,0 +1,60 @@ +/** + * 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 { render } from 'spec/helpers/testing-library'; +import FilterScope from 'src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FilterScope/FilterScope'; +import CrossFilterScopingForm from '.'; + +jest.mock( + 'src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FilterScope/FilterScope', + () => jest.fn(() => null), +); + +const createProps = () => { + const getFieldValue = jest.fn(); + getFieldValue.mockImplementation(name => name); + return { + chartId: 123, + scope: 'Scope', + form: { getFieldValue }, + }; +}; + +test('Should send correct props', () => { + const props = createProps(); + render(); + + expect(FilterScope).toHaveBeenCalledWith( + expect.objectContaining({ + chartId: 123, + scope: 'Scope', + formScope: 'scope', + formScoping: 'scoping', + }), + {}, + ); +}); + +test('Should get correct filds', () => { + const props = createProps(); + render(); + expect(props.form.getFieldValue).toBeCalledTimes(2); + expect(props.form.getFieldValue).toHaveBeenNthCalledWith(1, 'scope'); + expect(props.form.getFieldValue).toHaveBeenNthCalledWith(2, 'scoping'); +}); diff --git a/superset-frontend/src/dashboard/components/CrossFilterScopingModal/CrossFilterScopingForm.tsx b/superset-frontend/src/dashboard/components/CrossFilterScopingModal/CrossFilterScopingForm/index.tsx similarity index 75% rename from superset-frontend/src/dashboard/components/CrossFilterScopingModal/CrossFilterScopingForm.tsx rename to superset-frontend/src/dashboard/components/CrossFilterScopingModal/CrossFilterScopingForm/index.tsx index c1a173dc5384d..c184f9e0d3e9a 100644 --- a/superset-frontend/src/dashboard/components/CrossFilterScopingModal/CrossFilterScopingForm.tsx +++ b/superset-frontend/src/dashboard/components/CrossFilterScopingModal/CrossFilterScopingForm/index.tsx @@ -18,11 +18,11 @@ */ import React, { FC } from 'react'; import { FormInstance } from 'antd/lib/form'; -import FilterScope from '../nativeFilters/FiltersConfigModal/FiltersConfigForm/FilterScope/FilterScope'; -import { setCrossFilterFieldValues } from './utils'; -import { Scope } from '../nativeFilters/types'; -import { useForceUpdate } from '../nativeFilters/FiltersConfigModal/FiltersConfigForm/utils'; -import { CrossFilterScopingFormType } from './types'; +import FilterScope from 'src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FilterScope/FilterScope'; +import { setCrossFilterFieldValues } from 'src/dashboard/components/CrossFilterScopingModal/utils'; +import { Scope } from 'src/dashboard/components/nativeFilters/types'; +import { useForceUpdate } from 'src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/utils'; +import { CrossFilterScopingFormType } from 'src/dashboard/components/CrossFilterScopingModal/types'; type CrossFilterScopingFormProps = { chartId: number;