-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: FilterSets-utils #14028
Merged
Merged
test: FilterSets-utils #14028
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
db2b8ae
Tests for "nativeFilters/FilterBar/FilterSets/utils"
yardz 628ee2e
Update superset-frontend/src/dashboard/components/nativeFilters/Filte…
yardz 069b7e7
Update superset-frontend/src/dashboard/components/nativeFilters/Filte…
yardz 1aa7100
Update superset-frontend/src/dashboard/components/nativeFilters/Filte…
yardz 14e571d
Fix: Lint error
yardz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
...shboard/components/nativeFilters/FilterBar/FilterSets/utils/findExistingFilterSet.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/** | ||
* 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 different 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 filterSetFilterValues is []', () => { | ||
const dataMaskSelected = createDataMaskSelected(); | ||
const filterSetFilterValues: FilterSet[] = []; | ||
const response = findExistingFilterSet({ | ||
filterSetFilterValues, | ||
dataMaskSelected, | ||
}); | ||
expect(response).toBeUndefined(); | ||
}); |
24 changes: 24 additions & 0 deletions
24
...ashboard/components/nativeFilters/FilterBar/FilterSets/utils/generateFiltersSetId.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 the pattern "FILTERS_SET-"', () => { | ||
const id = generateFiltersSetId(); | ||
expect(id.startsWith('FILTERS_SET-', 0)).toBe(true); | ||
}); |
42 changes: 42 additions & 0 deletions
42
...oard/components/nativeFilters/FilterBar/FilterSets/utils/getFilterValueForDisplay.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* 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 { getFilterValueForDisplay } from '.'; | ||
|
||
test('Should return "" when value is null or undefined', () => { | ||
expect(getFilterValueForDisplay(null)).toBe(''); | ||
expect(getFilterValueForDisplay(undefined)).toBe(''); | ||
expect(getFilterValueForDisplay()).toBe(''); | ||
}); | ||
|
||
test('Should return "string value" when value is string or number', () => { | ||
expect(getFilterValueForDisplay(123)).toBe('123'); | ||
expect(getFilterValueForDisplay('123')).toBe('123'); | ||
}); | ||
|
||
test('Should return a string with values separated by commas', () => { | ||
expect(getFilterValueForDisplay(['a', 'b', 'c'])).toBe('a, b, c'); | ||
}); | ||
|
||
test('Should return a JSON.stringify from objects', () => { | ||
expect(getFilterValueForDisplay({ any: 'value' })).toBe('{"any":"value"}'); | ||
}); | ||
|
||
test('Should return an error message when the type is invalid', () => { | ||
expect(getFilterValueForDisplay(true as any)).toBe('Unknown value'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also check for expected ID length?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if the generated string is the same size. But I believe that this is not so important