pivot_table.test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. describe('Visualization > Pivot Table', () => {
  20. beforeEach(() => {
  21. cy.intercept('POST', '**/api/v1/chart/data**').as('chartData');
  22. });
  23. const PIVOT_TABLE_FORM_DATA = {
  24. datasource: '3__table',
  25. viz_type: 'pivot_table_v2',
  26. slice_id: 61,
  27. granularity_sqla: 'ds',
  28. time_grain_sqla: 'P1D',
  29. time_range: '100 years ago : now',
  30. metrics: ['sum__num'],
  31. adhoc_filters: [],
  32. groupbyRows: ['name'],
  33. groupbyColumns: ['state'],
  34. series_limit: 5000,
  35. aggregateFunction: 'Sum',
  36. rowTotals: true,
  37. colTotals: true,
  38. valueFormat: '.3s',
  39. combineMetric: false,
  40. };
  41. const TEST_METRIC = {
  42. expressionType: 'SIMPLE',
  43. column: {
  44. id: 338,
  45. column_name: 'num_boys',
  46. expression: '',
  47. filterable: false,
  48. groupby: false,
  49. is_dttm: false,
  50. type: 'BIGINT',
  51. optionName: '_col_num_boys',
  52. },
  53. aggregate: 'SUM',
  54. hasCustomLabel: false,
  55. label: 'SUM(num_boys)',
  56. optionName: 'metric_gvpdjt0v2qf_6hkf56o012',
  57. };
  58. function verify(formData) {
  59. cy.visitChartByParams(formData);
  60. cy.verifySliceSuccess({ waitAlias: '@chartData', chartSelector: 'table' });
  61. }
  62. it('should work with single groupby', () => {
  63. verify(PIVOT_TABLE_FORM_DATA);
  64. cy.get('.chart-container tr:eq(0) th:eq(2)').contains('sum__num');
  65. cy.get('.chart-container tr:eq(1) th:eq(0)').contains('state');
  66. cy.get('.chart-container tr:eq(2) th:eq(0)').contains('name');
  67. });
  68. it('should work with more than one groupby', () => {
  69. verify({
  70. ...PIVOT_TABLE_FORM_DATA,
  71. groupbyRows: ['name', 'gender'],
  72. });
  73. cy.get('.chart-container tr:eq(0) th:eq(2)').contains('sum__num');
  74. cy.get('.chart-container tr:eq(1) th:eq(0)').contains('state');
  75. cy.get('.chart-container tr:eq(2) th:eq(0)').contains('name');
  76. cy.get('.chart-container tr:eq(2) th:eq(1)').contains('gender');
  77. });
  78. it('should work with multiple metrics', () => {
  79. verify({
  80. ...PIVOT_TABLE_FORM_DATA,
  81. metrics: ['sum__num', TEST_METRIC],
  82. });
  83. cy.get('.chart-container tr:eq(0) th:eq(2)').contains('sum__num');
  84. cy.get('.chart-container tr:eq(0) th:eq(3)').contains('SUM(num_boys)');
  85. cy.get('.chart-container tr:eq(1) th:eq(0)').contains('state');
  86. cy.get('.chart-container tr:eq(2) th:eq(0)').contains('name');
  87. });
  88. it('should work with multiple groupby and multiple metrics', () => {
  89. verify({
  90. ...PIVOT_TABLE_FORM_DATA,
  91. groupbyRows: ['name', 'gender'],
  92. metrics: ['sum__num', TEST_METRIC],
  93. });
  94. cy.get('.chart-container tr:eq(0) th:eq(2)').contains('sum__num');
  95. cy.get('.chart-container tr:eq(0) th:eq(3)').contains('SUM(num_boys)');
  96. cy.get('.chart-container tr:eq(2) th:eq(0)').contains('name');
  97. cy.get('.chart-container tr:eq(2) th:eq(1)').contains('gender');
  98. });
  99. });