You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by gr...@apache.org on 2018/09/18 23:27:50 UTC

[incubator-superset] branch master updated: Table and dist bar tests (#5901)

This is an automated email from the ASF dual-hosted git repository.

graceguo 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 8cb734d  Table and dist bar tests (#5901)
8cb734d is described below

commit 8cb734d7e0279be7cb02515d2088d8bd21851594
Author: michellethomas <mi...@gmail.com>
AuthorDate: Tue Sep 18 16:27:45 2018 -0700

    Table and dist bar tests (#5901)
    
    * Creating commands to verify codes and slices
    
    * Creating tests for table and dist bar
---
 .../{big_number.js => big_number_total.js}         |  23 ++---
 .../integration/explore/visualizations/dist_bar.js |  61 ++++++++++++
 .../integration/explore/visualizations/line.js     |  55 ++---------
 .../explore/visualizations/shared.helper.js        |  55 ++++++-----
 .../integration/explore/visualizations/table.js    | 105 +++++++++++++++++++++
 superset/assets/cypress/support/commands.js        |  37 +++++---
 6 files changed, 237 insertions(+), 99 deletions(-)

diff --git a/superset/assets/cypress/integration/explore/visualizations/big_number.js b/superset/assets/cypress/integration/explore/visualizations/big_number_total.js
similarity index 80%
rename from superset/assets/cypress/integration/explore/visualizations/big_number.js
rename to superset/assets/cypress/integration/explore/visualizations/big_number_total.js
index c6bca9e..7651c1b 100644
--- a/superset/assets/cypress/integration/explore/visualizations/big_number.js
+++ b/superset/assets/cypress/integration/explore/visualizations/big_number_total.js
@@ -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',
@@ -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');
     });
   });
 });
diff --git a/superset/assets/cypress/integration/explore/visualizations/dist_bar.js b/superset/assets/cypress/integration/explore/visualizations/dist_bar.js
new file mode 100644
index 0000000..c285f5a
--- /dev/null
+++ b/superset/assets/cypress/integration/explore/visualizations/dist_bar.js
@@ -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' });
+  });
+});
diff --git a/superset/assets/cypress/integration/explore/visualizations/line.js b/superset/assets/cypress/integration/explore/visualizations/line.js
index dc4e7d4..525cc3c 100644
--- a/superset/assets/cypress/integration/explore/visualizations/line.js
+++ b/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],
@@ -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],
@@ -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 = {
@@ -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 = {
@@ -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 = {
@@ -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' });
   });
diff --git a/superset/assets/cypress/integration/explore/visualizations/shared.helper.js b/superset/assets/cypress/integration/explore/visualizations/shared.helper.js
index 7a1e519..796173a 100644
--- a/superset/assets/cypress/integration/explore/visualizations/shared.helper.js
+++ b/superset/assets/cypress/integration/explore/visualizations/shared.helper.js
@@ -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',
+};
diff --git a/superset/assets/cypress/integration/explore/visualizations/table.js b/superset/assets/cypress/integration/explore/visualizations/table.js
new file mode 100644
index 0000000..90a26d1
--- /dev/null
+++ b/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' });
+  });
+});
diff --git a/superset/assets/cypress/support/commands.js b/superset/assets/cypress/support/commands.js
index 28e02a5..a6c6dae 100644
--- a/superset/assets/cypress/support/commands.js
+++ b/superset/assets/cypress/support/commands.js
@@ -50,24 +50,35 @@ Cypress.Commands.add('visitChartByParams', (params) => {
   cy.visit(`${BASE_EXPLORE_URL}${params}`);
 });
 
+Cypress.Commands.add('verifyResponseCodes', (data) => {
+  // After a wait response check for valid response
+  expect(data.status).to.eq(200);
+  if (data.response.body.error) {
+    expect(data.response.body.error).to.eq(null);
+  }
+});
+
+Cypress.Commands.add('verifySliceContainer', (chartSelector) => {
+  // After a wait response check for valid slice container
+  cy.get('.slice_container').within(() => {
+    if (chartSelector) {
+      cy.get(chartSelector).then((charts) => {
+        const firstChart = charts[0];
+        expect(firstChart.clientWidth).greaterThan(0);
+        expect(firstChart.clientHeight).greaterThan(0);
+      });
+    }
+  });
+});
+
 Cypress.Commands.add('verifySliceSuccess', ({ waitAlias, querySubstring, chartSelector }) => {
   cy.wait(waitAlias).then((data) => {
-    expect(data.status).to.eq(200);
-    if (data.response.body.error) {
-      expect(data.response.body.error).to.eq(null);
-    }
+    cy.verifyResponseCodes(data);
+
     if (querySubstring) {
       expect(data.response.body.query).contains(querySubstring);
     }
 
-    cy.get('.slice_container').within(() => {
-      if (chartSelector) {
-        cy.get(chartSelector).then((charts) => {
-          const firstChart = charts[0];
-          expect(firstChart.clientWidth).greaterThan(0);
-          expect(firstChart.clientHeight).greaterThan(0);
-        });
-      }
-    });
+    cy.verifySliceContainer(chartSelector);
   });
 });