Skip to content
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

refactor: migrate table chart to new API #10270

Merged
merged 6 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ ignored-argument-names=_.*
max-locals=15

# Maximum number of return / yield for function / method body
max-returns=6
max-returns=10

# Maximum number of branch for function / method body
max-branches=12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ import {
getChartAliases,
isLegacyResponse,
getSliceIdFromRequestUrl,
JsonObject,
} from '../../utils/vizPlugins';
import { WORLD_HEALTH_DASHBOARD } from './dashboard.helper';

describe('Dashboard load', () => {
let dashboard;
let aliases;
let aliases: string[];
beforeEach(() => {
cy.login();

cy.visit(WORLD_HEALTH_DASHBOARD);

cy.get('#app').then(data => {
const bootstrapData = JSON.parse(data[0].dataset.bootstrap);
cy.get('#app').then(nodes => {
const bootstrapData = JSON.parse(nodes[0].dataset.bootstrap || '');
dashboard = bootstrapData.dashboard_data;
const { slices } = dashboard;
// then define routes and create alias for each requests
Expand All @@ -53,7 +54,7 @@ describe('Dashboard load', () => {
sliceId = responseBody.form_data.slice_id;
} else {
sliceId = getSliceIdFromRequestUrl(request.url);
responseBody.result.forEach(element => {
responseBody.result.forEach((element: JsonObject) => {
expect(element).to.have.property('error', null);
expect(element).to.have.property('status', 'success');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { interceptChart, parsePostForm } from 'cypress/utils';
import { interceptChart, parsePostForm, Slice } from 'cypress/utils';
import { TABBED_DASHBOARD } from './dashboard.helper';

describe('Dashboard tabs', () => {
Expand All @@ -40,24 +40,28 @@ describe('Dashboard tabs', () => {
cy.visit(TABBED_DASHBOARD);

cy.get('#app').then(data => {
const bootstrapData = JSON.parse(data[0].dataset.bootstrap);
const dashboard = bootstrapData.dashboard_data;
const bootstrapData = JSON.parse(data[0].dataset.bootstrap || '');
const dashboard = bootstrapData.dashboard_data as { slices: Slice[] };
filterId = dashboard.slices.find(
slice => slice.form_data.viz_type === 'filter_box',
).slice_id;
)?.slice_id;
boxplotId = dashboard.slices.find(
slice => slice.form_data.viz_type === 'box_plot',
).slice_id;
)?.slice_id;
treemapId = dashboard.slices.find(
slice => slice.form_data.viz_type === 'treemap',
).slice_id;
)?.slice_id;
linechartId = dashboard.slices.find(
slice => slice.form_data.viz_type === 'line',
).slice_id;
interceptChart(filterId).as('filterRequest');
interceptChart(treemapId).as('treemapRequest');
interceptChart(linechartId).as('linechartRequest');
interceptChart(boxplotId, false).as('boxplotRequest');
)?.slice_id;
interceptChart({ sliceId: filterId, legacy: true }).as('filterRequest');
interceptChart({ sliceId: treemapId, legacy: true }).as('treemapRequest');
interceptChart({ sliceId: linechartId, legacy: true }).as(
'linechartRequest',
);
interceptChart({ sliceId: boxplotId, legacy: false }).as(
'boxplotRequest',
);
});
});

Expand Down Expand Up @@ -140,7 +144,7 @@ describe('Dashboard tabs', () => {
// send new query from same tab
cy.wait('@treemapRequest').then(({ request }) => {
const requestBody = parsePostForm(request.body);
const requestParams = JSON.parse(requestBody.form_data);
const requestParams = JSON.parse(requestBody.form_data as string);
expect(requestParams.extra_filters[0]).deep.eq({
col: 'region',
op: '==',
Expand All @@ -153,7 +157,7 @@ describe('Dashboard tabs', () => {

cy.wait('@linechartRequest').then(({ request }) => {
const requestBody = parsePostForm(request.body);
const requestParams = JSON.parse(requestBody.form_data);
const requestParams = JSON.parse(requestBody.form_data as string);
expect(requestParams.extra_filters[0]).deep.eq({
col: 'region',
op: '==',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ import {
isLegacyResponse,
getChartAliases,
parsePostForm,
Dashboard,
JsonObject,
} from 'cypress/utils';
import { WORLD_HEALTH_DASHBOARD } from './dashboard.helper';

describe('Dashboard form data', () => {
const urlParams = { param1: '123', param2: 'abc' };
let dashboard;
let dashboard: Dashboard;

beforeEach(() => {
cy.login();

cy.visit(WORLD_HEALTH_DASHBOARD, { qs: urlParams });

cy.get('#app').then(data => {
const bootstrapData = JSON.parse(data[0].dataset.bootstrap);
const bootstrapData = JSON.parse(data[0].dataset.bootstrap || '');
dashboard = bootstrapData.dashboard_data;
});
});
Expand All @@ -47,13 +49,16 @@ describe('Dashboard form data', () => {
const responseBody = response?.body;
if (isLegacyResponse(responseBody)) {
const requestParams = JSON.parse(
parsePostForm(request.body).form_data,
parsePostForm(request.body).form_data as string,
);
expect(requestParams.url_params).deep.eq(urlParams);
} else {
request.body.queries.forEach(query => {
expect(query.url_params).deep.eq(urlParams);
});
// TODO: export url params to chart data API
request.body.queries.forEach(
(query: { url_params: JsonObject }) => {
expect(query.url_params).deep.eq(urlParams);
},
);
}
}),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// ***********************************************
// Tests for setting controls in the UI
// ***********************************************
import { interceptChart } from 'cypress/utils';
import { FORM_DATA_DEFAULTS, NUM_METRIC } from './visualizations/shared.helper';

describe('Datasource control', () => {
Expand All @@ -29,10 +30,10 @@ describe('Datasource control', () => {
let numScripts = 0;

cy.login();
cy.intercept('GET', '/superset/explore_json/**').as('getJson');
cy.intercept('POST', '/superset/explore_json/**').as('postJson');
interceptChart({ legacy: false }).as('chartData');

cy.visitChartByName('Num Births Trend');
cy.verifySliceSuccess({ waitAlias: '@postJson' });
cy.verifySliceSuccess({ waitAlias: '@chartData' });

cy.get('[data-test="open-datasource-tab').click({ force: true });
cy.get('[data-test="datasource-menu-trigger"]').click();
Expand Down Expand Up @@ -90,13 +91,13 @@ describe('Datasource control', () => {
describe('VizType control', () => {
beforeEach(() => {
cy.login();
cy.intercept('GET', '/superset/explore_json/**').as('getJson');
cy.intercept('POST', '/superset/explore_json/**').as('postJson');
interceptChart({ legacy: false }).as('tableChartData');
interceptChart({ legacy: true }).as('lineChartData');
});

it('Can change vizType', () => {
cy.visitChartByName('Daily Totals');
cy.verifySliceSuccess({ waitAlias: '@postJson' });
cy.verifySliceSuccess({ waitAlias: '@tableChartData' });

let numScripts = 0;
cy.get('script').then(nodes => {
Expand All @@ -114,27 +115,29 @@ describe('VizType control', () => {
});

cy.get('button[data-test="run-query-button"]').click();
cy.verifySliceSuccess({ waitAlias: '@postJson', chartSelector: 'svg' });
cy.verifySliceSuccess({
waitAlias: '@lineChartData',
chartSelector: 'svg',
});
});
});

describe('Time range filter', () => {
beforeEach(() => {
cy.login();
cy.intercept('GET', '/superset/explore_json/**').as('getJson');
cy.intercept('POST', '/superset/explore_json/**').as('postJson');
interceptChart({ legacy: true }).as('chartData');
});

it('Advanced time_range params', () => {
const formData = {
...FORM_DATA_DEFAULTS,
metrics: [NUM_METRIC],
viz_type: 'line',
time_range: '100 years ago : now',
metrics: [NUM_METRIC],
};

cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@postJson' });
cy.verifySliceSuccess({ waitAlias: '@chartData' });

cy.get('[data-test=time-range-trigger]')
.click()
Expand All @@ -152,13 +155,13 @@ describe('Time range filter', () => {
it('Common time_range params', () => {
const formData = {
...FORM_DATA_DEFAULTS,
metrics: [NUM_METRIC],
viz_type: 'line',
metrics: [NUM_METRIC],
time_range: 'Last year',
};

cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@postJson' });
cy.verifySliceSuccess({ waitAlias: '@chartData' });

cy.get('[data-test=time-range-trigger]')
.click()
Expand All @@ -172,13 +175,13 @@ describe('Time range filter', () => {
it('Previous time_range params', () => {
const formData = {
...FORM_DATA_DEFAULTS,
metrics: [NUM_METRIC],
viz_type: 'line',
metrics: [NUM_METRIC],
time_range: 'previous calendar month',
};

cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@postJson' });
cy.verifySliceSuccess({ waitAlias: '@chartData' });

cy.get('[data-test=time-range-trigger]')
.click()
Expand All @@ -192,13 +195,13 @@ describe('Time range filter', () => {
it('Custom time_range params', () => {
const formData = {
...FORM_DATA_DEFAULTS,
metrics: [NUM_METRIC],
viz_type: 'line',
metrics: [NUM_METRIC],
time_range: 'DATEADD(DATETIME("today"), -7, day) : today',
};

cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@postJson' });
cy.verifySliceSuccess({ waitAlias: '@chartData' });

cy.get('[data-test=time-range-trigger]')
.click()
Expand All @@ -215,13 +218,13 @@ describe('Time range filter', () => {
it('No filter time_range params', () => {
const formData = {
...FORM_DATA_DEFAULTS,
metrics: [NUM_METRIC],
viz_type: 'line',
metrics: [NUM_METRIC],
time_range: 'No filter',
};

cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@postJson' });
cy.verifySliceSuccess({ waitAlias: '@chartData' });

cy.get('[data-test=time-range-trigger]')
.click()
Expand All @@ -235,16 +238,16 @@ describe('Time range filter', () => {
describe('Groupby control', () => {
it('Set groupby', () => {
cy.login();
cy.intercept('GET', '/superset/explore_json/**').as('getJson');
cy.intercept('POST', '/superset/explore_json/**').as('postJson');
interceptChart({ legacy: true }).as('chartData');

cy.visitChartByName('Num Births Trend');
cy.verifySliceSuccess({ waitAlias: '@postJson' });
cy.verifySliceSuccess({ waitAlias: '@chartData' });

cy.get('[data-test=groupby]').within(() => {
cy.get('.Select__control').click();
cy.get('input[type=text]').type('state{enter}');
});
cy.get('button[data-test="run-query-button"]').click();
cy.verifySliceSuccess({ waitAlias: '@postJson', chartSelector: 'svg' });
cy.verifySliceSuccess({ waitAlias: '@chartData', chartSelector: 'svg' });
});
});
Loading