superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grace...@apache.org
Subject [incubator-superset] branch master updated: Adding line and big number total integration tests (#5846)
Date Tue, 11 Sep 2018 18:03:50 GMT
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 6ae285b  Adding line and big number total integration tests (#5846)
6ae285b is described below

commit 6ae285b6f7a46a1150440fd0463df86821c0cf9d
Author: michellethomas <michelle.q.thomas@gmail.com>
AuthorDate: Tue Sep 11 11:03:46 2018 -0700

    Adding line and big number total integration tests (#5846)
    
    * Adding line and big number total integration tests
    
    * Breakout visualization tests into multiple files
---
 superset/assets/cypress.json                       |   4 +-
 .../cypress/integration/explore/control_tests.js   |   6 +-
 .../integration/explore/visualization_tests.js     |  54 --------
 .../explore/visualizations/big_number.js           |  58 +++++++++
 .../integration/explore/visualizations/line.js     | 140 +++++++++++++++++++++
 .../explore/visualizations/shared.helper.js        |  40 ++++++
 superset/assets/cypress/support/commands.js        |  22 +++-
 7 files changed, 262 insertions(+), 62 deletions(-)

diff --git a/superset/assets/cypress.json b/superset/assets/cypress.json
index c84e05d..7ede593 100644
--- a/superset/assets/cypress.json
+++ b/superset/assets/cypress.json
@@ -1,3 +1,5 @@
 {
-	"baseUrl": "http://localhost:8081"
+	"baseUrl": "http://localhost:8081",
+	"videoUploadOnPasses": false,
+	"ignoreTestFiles": "*.helper.js"
 }
diff --git a/superset/assets/cypress/integration/explore/control_tests.js b/superset/assets/cypress/integration/explore/control_tests.js
index d4c5e4c..1c95f04 100644
--- a/superset/assets/cypress/integration/explore/control_tests.js
+++ b/superset/assets/cypress/integration/explore/control_tests.js
@@ -9,7 +9,7 @@ describe('Groupby', function () {
 
     cy.route('POST', '/superset/explore_json/**').as('getJson');
     cy.visitChartByName('Num Births Trend');
-    cy.verifySliceSuccess('@getJson');
+    cy.verifySliceSuccess({ waitAlias: '@getJson' });
 
     cy.get('[data-test=groupby]').within(() => {
       cy.get('.Select-control').click();
@@ -17,7 +17,7 @@ describe('Groupby', function () {
       cy.get('.VirtualizedSelectFocusedOption').click();
     });
     cy.get('button.query').click();
-    cy.verifySliceSuccess('@getJson');
+    cy.verifySliceSuccess({ waitAlias: '@getJson' });
   });
 });
 
@@ -30,7 +30,7 @@ describe('SimpleAdhocMetric', function () {
 
     cy.route('POST', '/superset/explore_json/**').as('getJson');
     cy.visitChartByName('Num Births Trend');
-    cy.verifySliceSuccess('@getJson');
+    cy.verifySliceSuccess({ waitAlias: '@getJson' });
 
     cy.get('[data-test=metrics]').within(() => {
       cy.get('.select-clear').click();
diff --git a/superset/assets/cypress/integration/explore/visualization_tests.js b/superset/assets/cypress/integration/explore/visualization_tests.js
deleted file mode 100644
index 50c331d..0000000
--- a/superset/assets/cypress/integration/explore/visualization_tests.js
+++ /dev/null
@@ -1,54 +0,0 @@
-// ***********************************************
-// Tests for visualization types
-// ***********************************************
-
-const FORM_DATA_DEFAULTS = {
-  datasource: '3__table',
-  viz_type: 'line',
-  granularity_sqla: 'ds',
-  time_grain_sqla: null,
-  time_range: '100+years+ago+:+now',
-  adhoc_filters: [],
-  groupby: [],
-  limit: null,
-  timeseries_limit_metric: null,
-  order_desc: false,
-  contribution: false,
-};
-
-describe('Line', function () {
-  it('Test line chart with adhoc metric', function () {
-    cy.server();
-    cy.login();
-
-    const metrics = [{
-      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',
-    }];
-
-    const formData = { ...FORM_DATA_DEFAULTS, metrics };
-
-    cy.route('POST', '/superset/explore_json/**').as('getJson');
-    cy.visitChartByParams(JSON.stringify(formData));
-    cy.verifySliceSuccess('@getJson');
-  });
-});
diff --git a/superset/assets/cypress/integration/explore/visualizations/big_number.js b/superset/assets/cypress/integration/explore/visualizations/big_number.js
new file mode 100644
index 0000000..1ee49eb
--- /dev/null
+++ b/superset/assets/cypress/integration/explore/visualizations/big_number.js
@@ -0,0 +1,58 @@
+import { FORM_DATA_DEFAULTS, NUM_METRIC } from './shared.helper';
+
+// Big Number Total
+
+describe('Big Number Total', function () {
+  const BIG_NUMBER_DEFAULTS = { ...FORM_DATA_DEFAULTS, viz_type: 'big_number_total' };
+
+  it('Test big number chart with adhoc metric', function () {
+    cy.server();
+    cy.login();
+
+    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', function () {
+    cy.server();
+    cy.login();
+
+    const filters = [{
+      expressionType: 'SIMPLE',
+      subject: 'name',
+      operator: 'in',
+      comparator: ['Aaron', 'Amy', 'Andrea'],
+      clause: 'WHERE',
+      sqlExpression: null,
+      fromFormData: true,
+      filterOptionName: 'filter_4y6teao56zs_ebjsvwy48c',
+    }];
+
+    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', function () {
+    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);
+      }
+      expect(data.response.body.query).not.contains(formData.groupby[0]);
+      cy.get('.slice_container');
+    });
+  });
+});
diff --git a/superset/assets/cypress/integration/explore/visualizations/line.js b/superset/assets/cypress/integration/explore/visualizations/line.js
new file mode 100644
index 0000000..7bac091
--- /dev/null
+++ b/superset/assets/cypress/integration/explore/visualizations/line.js
@@ -0,0 +1,140 @@
+import { FORM_DATA_DEFAULTS, NUM_METRIC } from './shared.helper';
+
+describe('Line', function () {
+  const LINE_CHART_DEFAULTS = { ...FORM_DATA_DEFAULTS, viz_type: 'line' };
+
+  it('Test line chart with adhoc metric', function () {
+    cy.server();
+    cy.login();
+
+    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', function () {
+    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', function () {
+    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 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', function () {
+    cy.server();
+    cy.login();
+
+    const formData = {
+      ...LINE_CHART_DEFAULTS,
+      metrics: [NUM_METRIC],
+      limit: 10,
+      groupby: ['name'],
+      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', function () {
+    cy.server();
+    cy.login();
+
+    const formData = {
+      ...LINE_CHART_DEFAULTS,
+      metrics: [NUM_METRIC],
+      limit: 10,
+      groupby: ['name'],
+      timeseries_limit_metric: NUM_METRIC,
+      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', function () {
+    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', function () {
+    cy.server();
+    cy.login();
+
+    const metrics = [NUM_METRIC];
+
+    const formData = { ...LINE_CHART_DEFAULTS, metrics, time_compare: ['1+year'], 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', function () {
+    cy.server();
+    cy.login();
+
+    const metrics = [NUM_METRIC];
+
+    const formData = { ...LINE_CHART_DEFAULTS, metrics, time_compare: ['1+year'], 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', function () {
+    cy.server();
+    cy.login();
+
+    const metrics = [NUM_METRIC];
+
+    const formData = { ...LINE_CHART_DEFAULTS, metrics, time_compare: ['1+year'], 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
new file mode 100644
index 0000000..7a1e519
--- /dev/null
+++ b/superset/assets/cypress/integration/explore/visualizations/shared.helper.js
@@ -0,0 +1,40 @@
+// ***********************************************
+// Constants for visualization tests
+// ***********************************************
+
+export const FORM_DATA_DEFAULTS = {
+  datasource: '3__table',
+  granularity_sqla: 'ds',
+  time_grain_sqla: null,
+  time_range: '100+years+ago+:+now',
+  adhoc_filters: [],
+  groupby: [],
+  limit: null,
+  timeseries_limit_metric: null,
+  order_desc: false,
+  contribution: false,
+};
+
+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',
+  };
diff --git a/superset/assets/cypress/support/commands.js b/superset/assets/cypress/support/commands.js
index 41c64a7..28e02a5 100644
--- a/superset/assets/cypress/support/commands.js
+++ b/superset/assets/cypress/support/commands.js
@@ -50,10 +50,24 @@ Cypress.Commands.add('visitChartByParams', (params) => {
   cy.visit(`${BASE_EXPLORE_URL}${params}`);
 });
 
-Cypress.Commands.add('verifySliceSuccess', (waitAlias) => {
-  cy.wait([waitAlias]).then((data) => {
+Cypress.Commands.add('verifySliceSuccess', ({ waitAlias, querySubstring, chartSelector })
=> {
+  cy.wait(waitAlias).then((data) => {
     expect(data.status).to.eq(200);
-    expect(data.response.body).to.have.property('error', null);
-    cy.get('.slice_container');
+    if (data.response.body.error) {
+      expect(data.response.body.error).to.eq(null);
+    }
+    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);
+        });
+      }
+    });
   });
 });


Mime
View raw message