Skip to content

Commit

Permalink
Creating tests for table and dist bar
Browse files Browse the repository at this point in the history
  • Loading branch information
michellethomas committed Sep 18, 2018
1 parent ae80a1c commit 0b443d6
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 46 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,18 +34,13 @@ 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) => {
cy.verifyResponseCodes(data);
Expand Down
@@ -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' });
});
});
40 changes: 5 additions & 35 deletions superset/assets/cypress/integration/explore/visualizations/line.js
Expand Up @@ -3,49 +3,40 @@ 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 = [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 @@ -54,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 @@ -72,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 @@ -103,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 @@ -121,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 @@ -139,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
105 changes: 105 additions & 0 deletions superset/assets/cypress/integration/explore/visualizations/table.js
@@ -0,0 +1,105 @@
import { FORM_DATA_DEFAULTS, NUM_METRIC, SIMPLE_FILTER } from './shared.helper';

// Table

describe('Table chart', () => {
const VIZ_DEFAULTS = { ...FORM_DATA_DEFAULTS, viz_type: 'table' };

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

it('Test table with adhoc metric', () => {
const formData = { ...VIZ_DEFAULTS, metrics: NUM_METRIC };

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

it('Test table with groupby', () => {
const formData = { ...VIZ_DEFAULTS, metrics: NUM_METRIC, groupby: ['name'] };

cy.visitChartByParams(JSON.stringify(formData));
cy.verifySliceSuccess({
waitAlias: '@getJson',
querySubstring: formData.groupby[0],
chartSelector: 'table',
});
});

it('Test table with percent metrics and groupby', () => {
const formData = {
...VIZ_DEFAULTS,
percent_metrics: NUM_METRIC,
metrics: [],
groupby: ['name'],
};

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

it('Test table with groupby order desc', () => {
const formData = { ...VIZ_DEFAULTS, metrics: NUM_METRIC, groupby: ['name'], order_desc: true };

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

it('Test table with groupby and limit', () => {
const limit = 10;

const formData = { ...VIZ_DEFAULTS, metrics: NUM_METRIC, groupby: ['name'], row_limit: limit };

cy.visitChartByParams(JSON.stringify(formData));

cy.wait('@getJson').then((data) => {
cy.verifyResponseCodes(data);
cy.verifySliceContainer('table');
expect(data.response.body.data.records.length).to.eq(limit);
});
});

it('Test table with columns and row limit', () => {
const formData = { ...VIZ_DEFAULTS, all_columns: ['name'], metrics: [], row_limit: 10 };

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

it('Test table with columns, ordering, and row limit', () => {
const limit = 10;

const formData = {
...VIZ_DEFAULTS,
all_columns: ['name', 'state', 'ds', 'num'],
metrics: [],
row_limit: limit,
order_by_cols: ['["num",+false]'],
};

cy.visitChartByParams(JSON.stringify(formData));
cy.wait('@getJson').then((data) => {
cy.verifyResponseCodes(data);
cy.verifySliceContainer('table');
const records = data.response.body.data.records;
expect(records[0].num).greaterThan(records[records.length - 1].num);
});
});

it('Test table with simple filter', () => {
const metrics = ['count'];
const filters = [SIMPLE_FILTER];

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

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

0 comments on commit 0b443d6

Please sign in to comment.