compare.test.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 > Compare', () => {
  20. beforeEach(() => {
  21. cy.intercept('POST', '**/superset/explore_json/**').as('getJson');
  22. });
  23. const COMPARE_FORM_DATA = {
  24. datasource: '3__table',
  25. viz_type: 'compare',
  26. slice_id: 60,
  27. granularity_sqla: 'ds',
  28. time_grain_sqla: 'P1D',
  29. time_range: '100 years ago : now',
  30. metrics: ['count'],
  31. adhoc_filters: [],
  32. groupby: [],
  33. order_desc: true,
  34. contribution: false,
  35. row_limit: 50000,
  36. color_scheme: 'bnbColors',
  37. x_axis_label: 'Frequency',
  38. bottom_margin: 'auto',
  39. x_ticks_layout: 'auto',
  40. x_axis_format: 'smart_date',
  41. x_axis_showminmax: false,
  42. y_axis_label: 'Num',
  43. left_margin: 'auto',
  44. y_axis_showminmax: false,
  45. y_log_scale: false,
  46. y_axis_format: '.3s',
  47. rolling_type: 'None',
  48. comparison_type: 'values',
  49. annotation_layers: [],
  50. };
  51. function verify(formData) {
  52. cy.visitChartByParams(formData);
  53. cy.verifySliceSuccess({ waitAlias: '@getJson', chartSelector: 'svg' });
  54. }
  55. it('should work without groupby', () => {
  56. verify(COMPARE_FORM_DATA);
  57. cy.get('.chart-container .nvd3 path.nv-line').should('have.length', 1);
  58. });
  59. it('should with group by', () => {
  60. verify({
  61. ...COMPARE_FORM_DATA,
  62. groupby: ['gender'],
  63. });
  64. cy.get('.chart-container .nvd3 path.nv-line').should('have.length', 2);
  65. });
  66. it('should work with filter', () => {
  67. verify({
  68. ...COMPARE_FORM_DATA,
  69. adhoc_filters: [
  70. {
  71. expressionType: 'SIMPLE',
  72. subject: 'gender',
  73. operator: '==',
  74. comparator: 'boy',
  75. clause: 'WHERE',
  76. sqlExpression: null,
  77. filterOptionName: 'filter_tqx1en70hh_7nksse7nqic',
  78. },
  79. ],
  80. });
  81. cy.get('.chart-container .nvd3 path.nv-line').should('have.length', 1);
  82. });
  83. it('should allow type to search color schemes and apply the scheme', () => {
  84. verify(COMPARE_FORM_DATA);
  85. cy.get('#controlSections-tab-CUSTOMIZE').click();
  86. cy.get('.Control[data-test="color_scheme"]').scrollIntoView();
  87. cy.get('.Control[data-test="color_scheme"] input[type="search"]').focus();
  88. cy.focused().type('supersetColors{enter}');
  89. cy.get(
  90. '.Control[data-test="color_scheme"] .ant-select-selection-item [data-test="supersetColors"]',
  91. ).should('exist');
  92. });
  93. });