You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2020/11/24 11:13:25 UTC
[incubator-superset] branch master updated: chore: enabled v1
verification in filter and url_params test files (#11712)
This is an automated email from the ASF dual-hosted git repository.
villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new f49525f chore: enabled v1 verification in filter and url_params test files (#11712)
f49525f is described below
commit f49525f03ede8a73569ade32caedff01b7790b63
Author: adam-stasiak-polidea <ad...@polidea.com>
AuthorDate: Tue Nov 24 12:09:57 2020 +0100
chore: enabled v1 verification in filter and url_params test files (#11712)
* enabled v1 verification in filter test file
* added v1 support in url_params tests
* review fix
---
.../cypress/integration/dashboard/filter.test.ts | 55 ++++++++++++----------
.../integration/dashboard/url_params.test.js | 41 ++++++++--------
.../cypress-base/cypress/utils/vizPlugins.ts | 3 +-
3 files changed, 53 insertions(+), 46 deletions(-)
diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/filter.test.ts b/superset-frontend/cypress-base/cypress/integration/dashboard/filter.test.ts
index ab18557..b40eb08 100644
--- a/superset-frontend/cypress-base/cypress/integration/dashboard/filter.test.ts
+++ b/superset-frontend/cypress-base/cypress/integration/dashboard/filter.test.ts
@@ -17,7 +17,12 @@
* under the License.
*/
import { WORLD_HEALTH_DASHBOARD } from './dashboard.helper';
-import { isLegacyChart } from '../../utils/vizPlugins';
+import {
+ getChartAliases,
+ DASHBOARD_CHART_ALIAS_PREFIX,
+ isLegacyResponse,
+} from '../../utils/vizPlugins';
+import readResponseBlob from '../../utils/readResponseBlob';
interface Slice {
slice_id: number;
@@ -36,7 +41,7 @@ describe('Dashboard filter', () => {
let aliases: string[];
const getAlias = (id: number) => {
- return `@slice_${id}`;
+ return `@${DASHBOARD_CHART_ALIAS_PREFIX}${id}`;
};
beforeEach(() => {
@@ -53,16 +58,8 @@ describe('Dashboard filter', () => {
dashboard.slices.find(
slice => slice.form_data.viz_type === 'filter_box',
)?.slice_id || 0;
- aliases = slices
- // TODO(villebro): enable V1 charts
- .filter(slice => isLegacyChart(slice.form_data.viz_type))
- .map(slice => {
- const id = slice.slice_id;
- const alias = getAlias(id);
- const url = `/superset/explore_json/?*{"slice_id":${id}}*`;
- cy.route('POST', url).as(alias.slice(1));
- return alias;
- });
+
+ aliases = getChartAliases(slices);
// wait the initial page load requests
cy.wait(aliases);
@@ -93,20 +90,28 @@ describe('Dashboard filter', () => {
cy.get('.Select__menu').first().contains('South Asia').click();
cy.get('.filter_box button').click({ force: true });
-
- // wait again after applied filters
cy.wait(aliases.filter(x => x !== getAlias(filterId))).then(requests => {
- requests.forEach(xhr => {
- const requestFormData = xhr.request.body as FormData;
- const requestParams = JSON.parse(
- requestFormData.get('form_data') as string,
- );
- expect(requestParams.extra_filters[0]).deep.eq({
- col: 'region',
- op: '==',
- val: 'South Asia',
- });
- });
+ return Promise.all(
+ requests.map(async xhr => {
+ expect(xhr.status).to.eq(200);
+ const responseBody = await readResponseBlob(xhr.response.body);
+ let requestFilter;
+ if (isLegacyResponse(responseBody)) {
+ const requestFormData = xhr.request.body as FormData;
+ const requestParams = JSON.parse(
+ requestFormData.get('form_data') as string,
+ );
+ requestFilter = requestParams.extra_filters[0];
+ } else {
+ requestFilter = xhr.request.body.queries[0].filters[0];
+ }
+ expect(requestFilter).deep.eq({
+ col: 'region',
+ op: '==',
+ val: 'South Asia',
+ });
+ }),
+ );
});
// TODO add test with South Asia{enter} type action to select filter
diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/url_params.test.js b/superset-frontend/cypress-base/cypress/integration/dashboard/url_params.test.js
index 56bbb06..ae98be1 100644
--- a/superset-frontend/cypress-base/cypress/integration/dashboard/url_params.test.js
+++ b/superset-frontend/cypress-base/cypress/integration/dashboard/url_params.test.js
@@ -17,7 +17,8 @@
* under the License.
*/
import { WORLD_HEALTH_DASHBOARD } from './dashboard.helper';
-import { isLegacyChart } from '../../utils/vizPlugins';
+import { isLegacyResponse, getChartAliases } from '../../utils/vizPlugins';
+import readResponseBlob from '../../utils/readResponseBlob';
describe('Dashboard form data', () => {
const urlParams = { param1: '123', param2: 'abc' };
@@ -36,26 +37,26 @@ describe('Dashboard form data', () => {
});
it('should apply url params and queryFields to slice requests', () => {
- const aliases = [];
- dashboard.slices.forEach(slice => {
- const { slice_id: id } = slice;
- const isLegacy = isLegacyChart(slice.form_data.viz_type);
- const route = `/superset/explore_json/?form_data={"slice_id":${id}}&dashboard_id=${dashboard.id}`;
- const alias = `getJson_${id}`;
- // TODO(villebro): enable V1 charts
- if (isLegacy) {
- aliases.push(`@${alias}`);
- cy.route('POST', route).as(alias);
- }
- });
-
+ const aliases = getChartAliases(dashboard.slices);
+ // wait and verify one-by-one
cy.wait(aliases).then(requests => {
- requests.forEach(xhr => {
- const requestFormData = xhr.request.body;
- const requestParams = JSON.parse(requestFormData.get('form_data'));
- expect(requestParams).to.have.property('queryFields');
- expect(requestParams.url_params).deep.eq(urlParams);
- });
+ return Promise.all(
+ requests.map(async xhr => {
+ expect(xhr.status).to.eq(200);
+ const responseBody = await readResponseBlob(xhr.response.body);
+
+ if (isLegacyResponse(responseBody)) {
+ const requestFormData = xhr.request.body;
+ const requestParams = JSON.parse(requestFormData.get('form_data'));
+ expect(requestParams).to.have.property('queryFields');
+ expect(requestParams.url_params).deep.eq(urlParams);
+ } else {
+ xhr.request.body.queries.forEach(query => {
+ expect(query.url_params).deep.eq(urlParams);
+ });
+ }
+ }),
+ );
});
});
});
diff --git a/superset-frontend/cypress-base/cypress/utils/vizPlugins.ts b/superset-frontend/cypress-base/cypress/utils/vizPlugins.ts
index 78ab56f..e597bb7 100644
--- a/superset-frontend/cypress-base/cypress/utils/vizPlugins.ts
+++ b/superset-frontend/cypress-base/cypress/utils/vizPlugins.ts
@@ -18,6 +18,7 @@
*/
const V1_PLUGINS = ['box_plot', 'echarts_timeseries', 'word_cloud', 'pie'];
+export const DASHBOARD_CHART_ALIAS_PREFIX = 'getJson_';
export function isLegacyChart(vizType: string): boolean {
return !V1_PLUGINS.includes(vizType);
@@ -35,7 +36,7 @@ export function getChartAliases(slices: any[]): string[] {
Array.from(slices).forEach(slice => {
const vizType = slice.form_data.viz_type;
const isLegacy = isLegacyChart(vizType);
- const alias = `getJson_${slice.slice_id}`;
+ const alias = `${DASHBOARD_CHART_ALIAS_PREFIX}${slice.slice_id}`;
const formData = `{"slice_id":${slice.slice_id}}`;
if (isLegacy) {
const route = `/superset/explore_json/?*${formData}*`;