-
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: exploreUtils #13719
Merged
Merged
test: exploreUtils #13719
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c9985ef
Tests for exploreUtils
yardz 7c80c6c
removing eslint-disable
yardz 87a1bf1
applying factory
yardz d2159da
Removing skip tests and code comments.
yardz 6f6d087
Improving test name
yardz 77ab0ce
remove comments
yardz fa8a466
Improving "shouldUseLegacyApi" tests
yardz 4c3e29f
fixing typo
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
44 changes: 44 additions & 0 deletions
44
superset-frontend/src/explore/exploreUtils/exploreChart.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,44 @@ | ||
/** | ||
* 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 { exploreChart } from '.'; | ||
|
||
/** | ||
* I'm leaving this comment here to show one of the approaches I tried and it didn't work. | ||
* | ||
* The same problem occurred with: "exploreChart" | ||
*/ | ||
// import * as index from './index'; | ||
// const spy = jest.spyOn(index, 'postForm'); | ||
|
||
const params = { | ||
formData: { data: 'same-string' }, | ||
resultFormat: 'json', | ||
resultType: 'full', | ||
force: false, | ||
}; | ||
|
||
/** | ||
* For some reason the spy is not working properly and I also did not find a way to mock only the "postForm" | ||
* I believe that if this file is divided the problem will be solved. | ||
*/ | ||
test.skip('Should call postForm correctly', () => { | ||
exploreChart(params); | ||
// expect(spy).toBeCalledTimes(1); | ||
}); |
51 changes: 51 additions & 0 deletions
51
superset-frontend/src/explore/exploreUtils/getAnnotationJsonUrl.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,51 @@ | ||
/** | ||
* 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 { getAnnotationJsonUrl } from '.'; | ||
|
||
let windowLocation: any; | ||
|
||
beforeAll(() => { | ||
windowLocation = window.location; | ||
// @ts-expect-error | ||
delete window.location; | ||
}); | ||
|
||
beforeEach(() => { | ||
window.location = { | ||
search: '?testA=0&testB=1', | ||
} as any; | ||
}); | ||
|
||
afterAll(() => { | ||
window.location = windowLocation; | ||
}); | ||
|
||
test('get correct annotation when isNative:true', () => { | ||
const response = getAnnotationJsonUrl('slice_id', 'form_data', true); | ||
expect(response).toBe( | ||
'/superset/annotation_json/slice_id?form_data=%22form_data%22', | ||
); | ||
}); | ||
|
||
test('get correct annotation when isNative:false', () => { | ||
const response = getAnnotationJsonUrl('slice_id', { json: 'my-data' }, false); | ||
expect(response).toBe( | ||
'/superset/slice_json/slice_id?form_data=%7B%22json%22%3A%22my-data%22%7D', | ||
); | ||
}); |
73 changes: 73 additions & 0 deletions
73
superset-frontend/src/explore/exploreUtils/getChartDataUri.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,73 @@ | ||
/** | ||
* 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 { getChartDataUri } from '.'; | ||
|
||
test('Get ChartUri when allowDomainSharding:false', () => { | ||
expect( | ||
getChartDataUri({ | ||
path: '/path', | ||
qs: 'same-string', | ||
allowDomainSharding: false, | ||
}), | ||
).toEqual({ | ||
_deferred_build: true, | ||
_parts: { | ||
duplicateQueryParameters: false, | ||
escapeQuerySpace: true, | ||
fragment: null, | ||
hostname: undefined, | ||
password: null, | ||
path: '/path', | ||
port: '', | ||
preventInvalidHostname: false, | ||
protocol: 'http', | ||
query: 'same-string', | ||
urn: null, | ||
username: null, | ||
}, | ||
_string: '', | ||
}); | ||
}); | ||
|
||
test('Get ChartUri when allowDomainSharding:true', () => { | ||
expect( | ||
getChartDataUri({ | ||
path: '/path-allowDomainSharding-true', | ||
qs: 'same-string-allowDomainSharding-true', | ||
allowDomainSharding: true, | ||
}), | ||
).toEqual({ | ||
_deferred_build: true, | ||
_parts: { | ||
duplicateQueryParameters: false, | ||
escapeQuerySpace: true, | ||
fragment: null, | ||
hostname: undefined, | ||
password: null, | ||
path: '/path-allowDomainSharding-true', | ||
port: '', | ||
preventInvalidHostname: false, | ||
protocol: 'http', | ||
query: 'same-string-allowDomainSharding-true', | ||
urn: null, | ||
username: null, | ||
}, | ||
_string: '', | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
superset-frontend/src/explore/exploreUtils/getChartKey.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,37 @@ | ||
/** | ||
* 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 { getChartKey } from '.'; | ||
|
||
// This validation has not been implemented | ||
test.skip('Should return 0 when called without arguments', () => { | ||
expect(getChartKey()).toBe(0); | ||
}); | ||
|
||
test('should return 0 when called with empty object', () => { | ||
expect(getChartKey({})).toBe(0); | ||
}); | ||
|
||
// The function does not yet have this behavior | ||
test.skip('should return 0 when called with incomplete object', () => { | ||
expect(getChartKey({ slice: {} })).toBe(0); | ||
}); | ||
|
||
test('should return 0 when called with complete object', () => { | ||
yardz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(getChartKey({ slice: { slice_id: 100 } })).toBe(100); | ||
}); |
99 changes: 99 additions & 0 deletions
99
superset-frontend/src/explore/exploreUtils/getExploreLongUrl.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,99 @@ | ||
/** | ||
* 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 { getExploreLongUrl } from '.'; | ||
|
||
let params = { | ||
formData: { | ||
datasource: 'datasource', | ||
viz_type: 'viz_type', | ||
}, | ||
endpointType: 'standalone', | ||
allowOverflow: true, | ||
extraSearch: { same: 'any-string' }, | ||
}; | ||
|
||
beforeEach(() => { | ||
yardz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
params = { | ||
formData: { | ||
datasource: 'datasource', | ||
viz_type: 'viz_type', | ||
}, | ||
endpointType: 'endpointType', | ||
allowOverflow: true, | ||
extraSearch: { same: 'any-string' }, | ||
}; | ||
}); | ||
|
||
test('Should return null if formData.datasource is falsy', () => { | ||
expect( | ||
getExploreLongUrl( | ||
{}, | ||
params.endpointType, | ||
params.allowOverflow, | ||
params.extraSearch, | ||
), | ||
).toBeNull(); | ||
}); | ||
|
||
test('Get url when endpointType:standalone', () => { | ||
expect( | ||
getExploreLongUrl( | ||
params.formData, | ||
params.endpointType, | ||
params.allowOverflow, | ||
params.extraSearch, | ||
), | ||
).toBe( | ||
'/superset/explore/?same=any-string&form_data=%7B%22datasource%22%3A%22datasource%22%2C%22viz_type%22%3A%22viz_type%22%7D', | ||
); | ||
}); | ||
|
||
test('Get url when endpointType:standalone and allowOverflow:false', () => { | ||
expect( | ||
getExploreLongUrl( | ||
params.formData, | ||
params.endpointType, | ||
false, | ||
params.extraSearch, | ||
), | ||
).toBe( | ||
'/superset/explore/?same=any-string&form_data=%7B%22datasource%22%3A%22datasource%22%2C%22viz_type%22%3A%22viz_type%22%7D', | ||
); | ||
}); | ||
|
||
test('Get url when endpointType:results', () => { | ||
expect( | ||
getExploreLongUrl( | ||
params.formData, | ||
'results', | ||
params.allowOverflow, | ||
params.extraSearch, | ||
), | ||
).toBe( | ||
'/superset/explore_json/?same=any-string&form_data=%7B%22datasource%22%3A%22datasource%22%2C%22viz_type%22%3A%22viz_type%22%7D', | ||
); | ||
}); | ||
|
||
test('Get url when endpointType:results and allowOverflow:false', () => { | ||
expect( | ||
getExploreLongUrl(params.formData, 'results', false, params.extraSearch), | ||
).toBe( | ||
'/superset/explore_json/?same=any-string&form_data=%7B%22datasource%22%3A%22datasource%22%2C%22viz_type%22%3A%22viz_type%22%7D', | ||
); | ||
}); |
63 changes: 63 additions & 0 deletions
63
superset-frontend/src/explore/exploreUtils/getExploreUrl.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,63 @@ | ||
/** | ||
* 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 { getExploreUrl } from '.'; | ||
|
||
let params = { | ||
formData: { | ||
datasource: 'datasource', | ||
viz_type: 'viz_type', | ||
}, | ||
endpointType: 'base', | ||
force: false, | ||
curUrl: null, | ||
requestParams: {}, | ||
allowDomainSharding: false, | ||
method: 'POST', | ||
}; | ||
|
||
beforeEach(() => { | ||
yardz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
params = { | ||
formData: { | ||
datasource: 'datasource', | ||
viz_type: 'viz_type', | ||
}, | ||
endpointType: 'base', | ||
force: false, | ||
curUrl: null, | ||
requestParams: {}, | ||
allowDomainSharding: false, | ||
method: 'POST', | ||
}; | ||
}); | ||
|
||
test('Get ExploreUrl whit default params', () => { | ||
rusackas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(getExploreUrl(params)).toBe('http:///superset/explore/'); | ||
}); | ||
|
||
test('Get ExploreUrl whit endpointType:full', () => { | ||
expect(getExploreUrl({ ...params, endpointType: 'full' })).toBe( | ||
'http:///superset/explore_json/', | ||
); | ||
}); | ||
|
||
test('Get ExploreUrl whit endpointType:full and method:GET', () => { | ||
expect( | ||
getExploreUrl({ ...params, endpointType: 'full', method: 'GET' }), | ||
).toBe('http:///superset/explore_json/'); | ||
}); |
Oops, something went wrong.
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.
exploreChart
is just callinggetExploreUrl
andpostForm
. I don't think is necessary to create a test forexploreChart
. Just testinggetExploreUrl
andpostForm
is enough.