michael-s-molina commented on a change in pull request #14028: URL: https://github.com/apache/superset/pull/14028#discussion_r610620656
########## File path: superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterSets/utils/findExistingFilterSet.test.ts ########## @@ -0,0 +1,161 @@ +/** + * 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 { FilterSet } from 'src/dashboard/reducers/types'; +import { findExistingFilterSet } from '.'; + +const createDataMaskSelected = () => ({ + filterId: { currentState: { value: 'value-1' } }, + filterId2: { currentState: { value: 'value-2' } }, +}); + +test('Should find correct filter', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: { + nativeFilters: { + filterId: { currentState: { value: 'value-1' } }, + filterId2: { currentState: { value: 'value-2' } }, + }, + } as any, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toEqual({ + dataMask: { + nativeFilters: { + filterId: { currentState: { value: 'value-1' } }, + filterId2: { currentState: { value: 'value-2' } }, + }, + }, + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + }); +}); + +test('Should return undefined when nativeFilters has less values', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: { + nativeFilters: { + filterId: { currentState: { value: 'value-1' } }, + }, + } as any, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toBeUndefined(); +}); + +test('Should return undefined when nativeFilters has diferent values', () => { Review comment: ```suggestion test('Should return undefined when nativeFilters has different values', () => { ``` ########## File path: superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterSets/utils/findExistingFilterSet.test.ts ########## @@ -0,0 +1,161 @@ +/** + * 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 { FilterSet } from 'src/dashboard/reducers/types'; +import { findExistingFilterSet } from '.'; + +const createDataMaskSelected = () => ({ + filterId: { currentState: { value: 'value-1' } }, + filterId2: { currentState: { value: 'value-2' } }, +}); + +test('Should find correct filter', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: { + nativeFilters: { + filterId: { currentState: { value: 'value-1' } }, + filterId2: { currentState: { value: 'value-2' } }, + }, + } as any, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toEqual({ + dataMask: { + nativeFilters: { + filterId: { currentState: { value: 'value-1' } }, + filterId2: { currentState: { value: 'value-2' } }, + }, + }, + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + }); +}); + +test('Should return undefined when nativeFilters has less values', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: { + nativeFilters: { + filterId: { currentState: { value: 'value-1' } }, + }, + } as any, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toBeUndefined(); +}); + +test('Should return undefined when nativeFilters has diferent values', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: { + nativeFilters: { + filterId: { currentState: { value: 'value-1' } }, + filterId2: { currentState: { value: 'value-1' } }, + }, + } as any, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toBeUndefined(); +}); + +test('Should return undefined when dataMask:{}', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: {}, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toBeUndefined(); +}); + +test('Should return undefined when dataMask.nativeFilters is undefined}', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: { nativeFilters: undefined }, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toBeUndefined(); +}); + +test('Should return undefined when dataMask.nativeFilters is undefined', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: { nativeFilters: undefined }, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toBeUndefined(); +}); Review comment: ```suggestion ``` ########## File path: superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterSets/utils/findExistingFilterSet.test.ts ########## @@ -0,0 +1,161 @@ +/** + * 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 { FilterSet } from 'src/dashboard/reducers/types'; +import { findExistingFilterSet } from '.'; + +const createDataMaskSelected = () => ({ + filterId: { currentState: { value: 'value-1' } }, + filterId2: { currentState: { value: 'value-2' } }, +}); + +test('Should find correct filter', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: { + nativeFilters: { + filterId: { currentState: { value: 'value-1' } }, + filterId2: { currentState: { value: 'value-2' } }, + }, + } as any, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toEqual({ + dataMask: { + nativeFilters: { + filterId: { currentState: { value: 'value-1' } }, + filterId2: { currentState: { value: 'value-2' } }, + }, + }, + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + }); +}); + +test('Should return undefined when nativeFilters has less values', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: { + nativeFilters: { + filterId: { currentState: { value: 'value-1' } }, + }, + } as any, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toBeUndefined(); +}); + +test('Should return undefined when nativeFilters has diferent values', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: { + nativeFilters: { + filterId: { currentState: { value: 'value-1' } }, + filterId2: { currentState: { value: 'value-1' } }, + }, + } as any, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toBeUndefined(); +}); + +test('Should return undefined when dataMask:{}', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: {}, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toBeUndefined(); +}); + +test('Should return undefined when dataMask.nativeFilters is undefined}', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: { nativeFilters: undefined }, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toBeUndefined(); +}); + +test('Should return undefined when dataMask.nativeFilters is undefined', () => { + const dataMaskSelected = createDataMaskSelected(); + const filterSetFilterValues = [ + { + id: 'id-01', + name: 'name-01', + nativeFilters: {}, + dataMask: { nativeFilters: undefined }, + }, + ]; + const response = findExistingFilterSet({ + filterSetFilterValues, + dataMaskSelected, + }); + expect(response).toBeUndefined(); +}); Review comment: Duplicated test. ########## File path: superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterSets/utils/generateFiltersSetId.test.ts ########## @@ -0,0 +1,24 @@ +/** + * 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 { generateFiltersSetId } from '.'; Review comment: Maybe also check for expected ID length? ########## File path: superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterSets/utils/generateFiltersSetId.test.ts ########## @@ -0,0 +1,24 @@ +/** + * 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 { generateFiltersSetId } from '.'; + +test('Should follow a pattern', () => { Review comment: ```suggestion test('Should follow the pattern "FILTERS_SET-"', () => { ``` -- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
