Skip to content

Commit

Permalink
Table and dist bar tests (#5901)
Browse files Browse the repository at this point in the history
* Creating commands to verify codes and slices

* Creating tests for table and dist bar
  • Loading branch information
michellethomas authored and Grace Guo committed Sep 18, 2018
1 parent 42ab175 commit 8cb734d
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 99 deletions.
Expand Up @@ -5,21 +5,20 @@ import { FORM_DATA_DEFAULTS, NUM_METRIC } from './shared.helper';
describe('Big Number Total', () => {
const BIG_NUMBER_DEFAULTS = { ...FORM_DATA_DEFAULTS, viz_type: 'big_number_total' };

it('Test big number chart with adhoc metric', () => {
cy.server();
beforeEach(() => {
cy.login();
cy.server();
cy.route('POST', '/superset/explore_json/**').as('getJson');
});

it('Test big number chart with adhoc metric', () => {
const formData = { ...BIG_NUMBER_DEFAULTS, metric: NUM_METRIC };

cy.route('POST', '/superset/explore_json/**').as('getJson');
cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', querySubstring: NUM_METRIC.label });
});

it('Test big number chart with simple filter', () => {
cy.server();
cy.login();

const filters = [
{
expressionType: 'SIMPLE',
Expand All @@ -35,26 +34,18 @@ describe('Big Number Total', () => {

const formData = { ...BIG_NUMBER_DEFAULTS, metric: 'count', adhoc_filters: filters };

cy.route('POST', '/superset/explore_json/**').as('getJson');
cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson' });
});

it('Test big number chart ignores groupby', () => {
cy.server();
cy.login();

const formData = { ...BIG_NUMBER_DEFAULTS, metric: NUM_METRIC, groupby: ['state'] };

cy.route('POST', '/superset/explore_json/**').as('getJson');
cy.visitChartByParams(JSON.stringify(formData));
cy.wait(['@getJson']).then((data) => {
expect(data.status).to.eq(200);
if (data.response.body.error) {
expect(data.response.body.error).to.eq(null);
}
cy.verifyResponseCodes(data);
cy.verifySliceContainer();
expect(data.response.body.query).not.contains(formData.groupby[0]);
cy.get('.slice_container');
});
});
});
@@ -0,0 +1,61 @@
import { FORM_DATA_DEFAULTS, NUM_METRIC } from './shared.helper';

// Dist bar

describe('Distribution bar chart', () => {
const VIZ_DEFAULTS = { ...FORM_DATA_DEFAULTS, viz_type: 'dist_bar' };

beforeEach(() => {
cy.login();
cy.server();
cy.route('POST', '/superset/explore_json/**').as('getJson');
});

it('Test dist bar with adhoc metric', () => {
const formData = { ...VIZ_DEFAULTS, metrics: NUM_METRIC, groupby: ['state'] };

cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({
waitAlias: '@getJson',
querySubstring: NUM_METRIC.label,
chartSelector: 'svg',
});
});

it('Test dist bar with series', () => {
const formData = {
...VIZ_DEFAULTS,
metrics: NUM_METRIC,
groupby: ['state'],
columns: ['gender'],
};

cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
});

it('Test dist bar with row limit', () => {
const formData = {
...VIZ_DEFAULTS,
metrics: NUM_METRIC,
groupby: ['state'],
row_limit: 10,
};

cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
});

it('Test dist bar with contribution', () => {
const formData = {
...VIZ_DEFAULTS,
metrics: NUM_METRIC,
groupby: ['state'],
columns: ['gender'],
contribution: true,
};

cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
});
});
55 changes: 7 additions & 48 deletions superset/assets/cypress/integration/explore/visualizations/line.js
@@ -1,62 +1,42 @@
import { FORM_DATA_DEFAULTS, NUM_METRIC } from './shared.helper';
import { FORM_DATA_DEFAULTS, NUM_METRIC, SIMPLE_FILTER } from './shared.helper';

describe('Line', () => {
const LINE_CHART_DEFAULTS = { ...FORM_DATA_DEFAULTS, viz_type: 'line' };

it('Test line chart with adhoc metric', () => {
cy.server();
beforeEach(() => {
cy.login();
cy.server();
cy.route('POST', '/superset/explore_json/**').as('getJson');
});

it('Test line chart with adhoc metric', () => {
const formData = { ...LINE_CHART_DEFAULTS, metrics: [NUM_METRIC] };

cy.route('POST', '/superset/explore_json/**').as('getJson');
cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
});

it('Test line chart with groupby', () => {
cy.server();
cy.login();

const metrics = ['count'];
const groupby = ['gender'];

const formData = { ...LINE_CHART_DEFAULTS, metrics, groupby };

cy.route('POST', '/superset/explore_json/**').as('getJson');
cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
});

it('Test line chart with simple filter', () => {
cy.server();
cy.login();

const metrics = ['count'];
const filters = [
{
expressionType: 'SIMPLE',
subject: 'name',
operator: 'in',
comparator: ['Aaron', 'Amy', 'Andrea'],
clause: 'WHERE',
sqlExpression: null,
fromFormData: true,
filterOptionName: 'filter_4y6teao56zs_ebjsvwy48c',
},
];
const filters = [SIMPLE_FILTER];

const formData = { ...LINE_CHART_DEFAULTS, metrics, adhoc_filters: filters };

cy.route('POST', '/superset/explore_json/**').as('getJson');
cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
});

it('Test line chart with series limit sort asc', () => {
cy.server();
cy.login();

const formData = {
...LINE_CHART_DEFAULTS,
metrics: [NUM_METRIC],
Expand All @@ -65,15 +45,11 @@ describe('Line', () => {
timeseries_limit_metric: NUM_METRIC,
};

cy.route('POST', '/superset/explore_json/**').as('getJson');
cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
});

it('Test line chart with series limit sort desc', () => {
cy.server();
cy.login();

const formData = {
...LINE_CHART_DEFAULTS,
metrics: [NUM_METRIC],
Expand All @@ -83,28 +59,20 @@ describe('Line', () => {
order_desc: true,
};

cy.route('POST', '/superset/explore_json/**').as('getJson');
cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
});

it('Test line chart with rolling avg', () => {
cy.server();
cy.login();

const metrics = [NUM_METRIC];

const formData = { ...LINE_CHART_DEFAULTS, metrics, rolling_type: 'mean', rolling_periods: 10 };

cy.route('POST', '/superset/explore_json/**').as('getJson');
cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
});

it('Test line chart with time shift 1 year', () => {
cy.server();
cy.login();

const metrics = [NUM_METRIC];

const formData = {
Expand All @@ -114,15 +82,11 @@ describe('Line', () => {
comparison_type: 'values',
};

cy.route('POST', '/superset/explore_json/**').as('getJson');
cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
});

it('Test line chart with time shift yoy', () => {
cy.server();
cy.login();

const metrics = [NUM_METRIC];

const formData = {
Expand All @@ -132,15 +96,11 @@ describe('Line', () => {
comparison_type: 'ratio',
};

cy.route('POST', '/superset/explore_json/**').as('getJson');
cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
});

it('Test line chart with time shift percentage change', () => {
cy.server();
cy.login();

const metrics = [NUM_METRIC];

const formData = {
Expand All @@ -150,7 +110,6 @@ describe('Line', () => {
comparison_type: 'percentage',
};

cy.route('POST', '/superset/explore_json/**').as('getJson');
cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
});
Expand Down
Expand Up @@ -16,25 +16,36 @@ export const FORM_DATA_DEFAULTS = {
};

export const NUM_METRIC = {
expressionType: 'SIMPLE',
column: {
id: 336,
column_name: 'num',
verbose_name: null,
description: null,
expression: '',
filterable: false,
groupby: false,
is_dttm: false,
type: 'BIGINT',
database_expression: null,
python_date_format: null,
optionName: '_col_num',
},
aggregate: 'SUM',
sqlExpression: null,
hasCustomLabel: false,
fromFormData: false,
label: 'Sum(num)',
optionName: 'metric_1de0s4viy5d_ly7y8k6ghvk',
};
expressionType: 'SIMPLE',
column: {
id: 336,
column_name: 'num',
verbose_name: null,
description: null,
expression: '',
filterable: false,
groupby: false,
is_dttm: false,
type: 'BIGINT',
database_expression: null,
python_date_format: null,
optionName: '_col_num',
},
aggregate: 'SUM',
sqlExpression: null,
hasCustomLabel: false,
fromFormData: false,
label: 'Sum(num)',
optionName: 'metric_1de0s4viy5d_ly7y8k6ghvk',
};

export const SIMPLE_FILTER = {
expressionType: 'SIMPLE',
subject: 'name',
operator: 'in',
comparator: ['Aaron', 'Amy', 'Andrea'],
clause: 'WHERE',
sqlExpression: null,
fromFormData: true,
filterOptionName: 'filter_4y6teao56zs_ebjsvwy48c',
};

0 comments on commit 8cb734d

Please sign in to comment.