superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From michel...@apache.org
Subject [incubator-superset] branch master updated: Adding tests for time table, formatting, and annotations (#6498)
Date Mon, 10 Dec 2018 20:16:17 GMT
This is an automated email from the ASF dual-hosted git repository.

michellet 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 23a2ab1  Adding tests for time table, formatting, and annotations (#6498)
23a2ab1 is described below

commit 23a2ab10771f1a4a97a06a31e2853e3f7f4375ed
Author: michellethomas <michelle.q.thomas@gmail.com>
AuthorDate: Mon Dec 10 12:16:11 2018 -0800

    Adding tests for time table, formatting, and annotations (#6498)
---
 .../explore/visualizations/index.test.js           |  2 +
 .../integration/explore/visualizations/line.js     | 65 ++++++++++++++++
 .../integration/explore/visualizations/table.js    | 22 ++++++
 .../explore/visualizations/time_table.js           | 88 ++++++++++++++++++++++
 superset/data/birth_names.py                       | 16 +++-
 5 files changed, 192 insertions(+), 1 deletion(-)

diff --git a/superset/assets/cypress/integration/explore/visualizations/index.test.js b/superset/assets/cypress/integration/explore/visualizations/index.test.js
index 7e140b1..1623c51 100644
--- a/superset/assets/cypress/integration/explore/visualizations/index.test.js
+++ b/superset/assets/cypress/integration/explore/visualizations/index.test.js
@@ -13,6 +13,7 @@ import PivotTableTest from './pivot_table';
 import SankeyTest from './sankey';
 import SunburstTest from './sunburst';
 import TableTest from './table';
+import TimeTableTest from './time_table';
 import TreemapTest from './treemap';
 import WorldMapTest from './world_map';
 
@@ -32,6 +33,7 @@ describe('All Visualizations', () => {
   SankeyTest();
   SunburstTest();
   TableTest();
+  TimeTableTest();
   TreemapTest();
   WorldMapTest();
 });
diff --git a/superset/assets/cypress/integration/explore/visualizations/line.js b/superset/assets/cypress/integration/explore/visualizations/line.js
index ca7e048..d17f839 100644
--- a/superset/assets/cypress/integration/explore/visualizations/line.js
+++ b/superset/assets/cypress/integration/explore/visualizations/line.js
@@ -124,4 +124,69 @@ export default () => describe('Line', () => {
     cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
     cy.get('text.nv-legend-text').contains('COUNT(*)');
   });
+
+  it('Test hidden annotation', () => {
+    const formData = {
+      ...LINE_CHART_DEFAULTS,
+      metrics: ['count'],
+      annotation_layers: [{
+        name: 'Goal+line',
+        annotationType: 'FORMULA',
+        sourceType: '',
+        value: 'y=140000',
+        overrides: { time_range: null },
+        show: false,
+        titleColumn: '',
+        descriptionColumns: [],
+        timeColumn: '',
+        intervalEndColumn: '',
+        color: null,
+        opacity: '',
+        style: 'solid',
+        width: 1,
+        showMarkers: false,
+        hideLine: false,
+      }],
+    };
+
+    cy.visitChartByParams(JSON.stringify(formData));
+    cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
+    cy.get('.slice_container').within(() => {
+      // Goal line annotation doesn't show up in legend
+      cy.get('.nv-legend-text').should('have.length', 1);
+    });
+  });
+
+  it('Test event annotation time override', () => {
+    cy.request('/chart/api/read?_flt_3_slice_name=Daily+Totals').then((response) => {
+      const value = response.body.pks[0];
+      const formData = {
+        ...LINE_CHART_DEFAULTS,
+        metrics: ['count'],
+        annotation_layers: [{
+          name: 'Yearly date',
+          annotationType: 'EVENT',
+          sourceType: 'table',
+          value,
+          overrides: { time_range: null },
+          show: true,
+          titleColumn: 'ds',
+          descriptionColumns: ['ds'],
+          timeColumn: 'ds',
+          color: null,
+          opacity: '',
+          style: 'solid',
+          width: 1,
+          showMarkers: false,
+          hideLine: false,
+        }],
+      };
+      cy.visitChartByParams(JSON.stringify(formData));
+    });
+
+    cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
+    cy.get('.slice_container').within(() => {
+      cy.get('.nv-event-annotation-layer-0').children().should('have.length', 44);
+    });
+  });
 });
diff --git a/superset/assets/cypress/integration/explore/visualizations/table.js b/superset/assets/cypress/integration/explore/visualizations/table.js
index f9a62a0..bc1b0aa 100644
--- a/superset/assets/cypress/integration/explore/visualizations/table.js
+++ b/superset/assets/cypress/integration/explore/visualizations/table.js
@@ -106,4 +106,26 @@ export default () => describe('Table chart', () => {
     cy.visitChartByParams(JSON.stringify(formData));
     cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'table' });
   });
+
+  it('Tests table number formatting with % in metric name', () => {
+    const PERCENT_METRIC = {
+      expressionType: 'SQL',
+      sqlExpression: 'CAST(SUM(sum_girls)+AS+FLOAT)/SUM(num)',
+      column: null,
+      aggregate: null,
+      hasCustomLabel: true,
+      fromFormData: true,
+      label: '%+Girls',
+      optionName: 'metric_6qwzgc8bh2v_zox7hil1mzs',
+    };
+    const formData = { ...VIZ_DEFAULTS, metrics: PERCENT_METRIC, groupby: ['state'] };
+
+    cy.visitChartByParams(JSON.stringify(formData));
+    cy.verifySliceSuccess({
+      waitAlias: '@getJson',
+      querySubstring: formData.groupby[0],
+      chartSelector: 'table',
+    });
+    cy.get('td').contains(/\d*%/);
+  });
 });
diff --git a/superset/assets/cypress/integration/explore/visualizations/time_table.js b/superset/assets/cypress/integration/explore/visualizations/time_table.js
new file mode 100644
index 0000000..d9966b4
--- /dev/null
+++ b/superset/assets/cypress/integration/explore/visualizations/time_table.js
@@ -0,0 +1,88 @@
+import { FORM_DATA_DEFAULTS, NUM_METRIC } from './shared.helper';
+
+// time table viz
+
+export default () => describe('Time Table Viz', () => {
+  const VIZ_DEFAULTS = { ...FORM_DATA_DEFAULTS, viz_type: 'time_table' };
+
+  beforeEach(() => {
+    cy.login();
+    cy.server();
+    cy.route('POST', '/superset/explore_json/**').as('getJson');
+  });
+
+  it('Test time series table multiple metrics last year total', () => {
+    const formData = {
+      ...VIZ_DEFAULTS,
+      metrics: [NUM_METRIC, 'count'],
+      column_collection: [{
+        key: '9g4K-B-YL',
+        label: 'Last+Year',
+        colType: 'time',
+        timeLag: '1',
+        comparisonType: 'value',
+      }],
+      url: '',
+    };
+
+    cy.visitChartByParams(JSON.stringify(formData));
+    cy.verifySliceSuccess({ waitAlias: '@getJson', querySubstring: NUM_METRIC.label });
+    cy.get('.time-table').within(() => {
+      cy.get('span').contains('Sum(num)');
+      cy.get('span').contains('COUNT(*)');
+    });
+  });
+
+  it('Test time series table metric and group by last year total', () => {
+    const formData = {
+      ...VIZ_DEFAULTS,
+      metrics: [NUM_METRIC],
+      groupby: ['gender'],
+      column_collection: [{
+        key: '9g4K-B-YL',
+        label: 'Last+Year',
+        colType: 'time',
+        timeLag: '1',
+        comparisonType: 'value',
+      }],
+      url: '',
+    };
+
+    cy.visitChartByParams(JSON.stringify(formData));
+    cy.verifySliceSuccess({ waitAlias: '@getJson', querySubstring: NUM_METRIC.label });
+    cy.get('.time-table').within(() => {
+      cy.get('td').contains('boy');
+      cy.get('td').contains('girl');
+    });
+  });
+
+  it('Test time series various time columns', () => {
+    const formData = {
+      ...VIZ_DEFAULTS,
+      metrics: [NUM_METRIC, 'count'],
+      column_collection: [
+        { key: 'LHHNPhamU', label: 'Current', colType: 'time', timeLag: 0 },
+        { key: '9g4K-B-YL', label: 'Last Year', colType: 'time', timeLag: '1', comparisonType:
'value' },
+        { key: 'JVZXtNu7_', label: 'YoY', colType: 'time', timeLag: 1, comparisonType: 'perc',
d3format: '%' },
+        { key: 'tN5Gba36u', label: 'Trend', colType: 'spark' },
+      ],
+      url: '',
+    };
+
+    cy.visitChartByParams(JSON.stringify(formData));
+    cy.verifySliceSuccess({ waitAlias: '@getJson', querySubstring: NUM_METRIC.label });
+    cy.get('.time-table').within(() => {
+      cy.get('th').contains('Current');
+      cy.get('th').contains('Last Year');
+      cy.get('th').contains('YoY');
+      cy.get('th').contains('Trend');
+
+      cy.get('span').contains('%');
+      cy.get('svg').first().then((charts) => {
+        const firstChart = charts[0];
+        expect(firstChart.clientWidth).greaterThan(0);
+        expect(firstChart.clientHeight).greaterThan(0);
+      });
+    });
+  });
+});
diff --git a/superset/data/birth_names.py b/superset/data/birth_names.py
index b697c31..e17316d 100644
--- a/superset/data/birth_names.py
+++ b/superset/data/birth_names.py
@@ -6,7 +6,7 @@ import textwrap
 import pandas as pd
 from sqlalchemy import DateTime, String
 
-from superset import db
+from superset import db, security_manager
 from superset.connectors.sqla.models import TableColumn
 from superset.utils.core import get_or_create_main_db
 from .helpers import (
@@ -76,6 +76,8 @@ def load_birth_names():
         'markup_type': 'markdown',
     }
 
+    admin = security_manager.find_user('admin')
+
     print('Creating some slices')
     slices = [
         Slice(
@@ -318,6 +320,18 @@ def load_birth_names():
             params=get_slice_json(
                 defaults,
                 viz_type='line')),
+        Slice(
+            slice_name='Daily Totals',
+            viz_type='table',
+            datasource_type='table',
+            datasource_id=tbl.id,
+            created_by=admin,
+            params=get_slice_json(
+                defaults,
+                groupby=['ds'],
+                since='40 years ago',
+                until='now',
+                viz_type='table')),
     ]
     for slc in slices:
         merge_slice(slc)


Mime
View raw message