AdhocMetrics.test.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. import { interceptChart } from 'cypress/utils';
  20. describe('AdhocMetrics', () => {
  21. beforeEach(() => {
  22. interceptChart({ legacy: false }).as('chartData');
  23. cy.visitChartByName('Num Births Trend');
  24. cy.verifySliceSuccess({ waitAlias: '@chartData' });
  25. });
  26. it('Clear metric and set simple adhoc metric', () => {
  27. const metric = 'sum(num_girls)';
  28. const metricName = 'Sum Girls';
  29. cy.get('[data-test=metrics]')
  30. .find('[data-test="remove-control-button"]')
  31. .click();
  32. cy.get('[data-test=metrics]')
  33. .contains('Drop columns/metrics here or click')
  34. .click();
  35. // Title edit for saved metrics is disabled - switch to Simple
  36. cy.get('[id="adhoc-metric-edit-tabs-tab-SIMPLE"]').click();
  37. cy.get('[data-test="AdhocMetricEditTitle#trigger"]').click();
  38. cy.get('[data-test="AdhocMetricEditTitle#input"]').type(metricName);
  39. cy.get('input[aria-label="Select column"]').click();
  40. cy.get('input[aria-label="Select column"]').type('num_girls{enter}');
  41. cy.get('input[aria-label="Select aggregate options"]').click();
  42. cy.get('input[aria-label="Select aggregate options"]').type('sum{enter}');
  43. cy.get('[data-test="AdhocMetricEdit#save"]').contains('Save').click();
  44. cy.get('[data-test="control-label"]').contains(metricName);
  45. cy.get('button[data-test="run-query-button"]').click();
  46. cy.verifySliceSuccess({
  47. waitAlias: '@chartData',
  48. querySubstring: `${metric} AS "${metricName}"`, // SQL statement
  49. });
  50. });
  51. xit('Switch from simple to custom sql', () => {
  52. cy.get('[data-test=metrics]')
  53. .find('[data-test="metric-option"]')
  54. .should('have.length', 1);
  55. // select column "num"
  56. cy.get('[data-test=metrics]').find('.Select__clear-indicator').click();
  57. cy.get('[data-test=metrics]').find('.Select__control').click();
  58. cy.get('[data-test=metrics]').find('.Select__control input').type('num');
  59. cy.get('[data-test=metrics]')
  60. .find('.option-label')
  61. .first()
  62. .should('have.text', 'num')
  63. .click();
  64. // add custom SQL
  65. cy.get('#adhoc-metric-edit-tabs-tab-SQL').click();
  66. cy.get('[data-test=metrics-edit-popover]').within(() => {
  67. cy.get('.ace_content').click();
  68. cy.get('.ace_text-input').type('/COUNT(DISTINCT name)', { force: true });
  69. cy.get('[data-test="AdhocMetricEdit#save"]').contains('Save').click();
  70. });
  71. cy.get('button[data-test="run-query-button"]').click();
  72. const metric = 'SUM(num)/COUNT(DISTINCT name)';
  73. cy.verifySliceSuccess({
  74. waitAlias: '@chartData',
  75. querySubstring: `${metric} AS "${metric}"`,
  76. });
  77. });
  78. xit('Switch from custom sql tabs to simple', () => {
  79. cy.get('[data-test=metrics]').within(() => {
  80. cy.get('.Select__dropdown-indicator').click();
  81. cy.get('input[type=text]').type('num_girls{enter}');
  82. });
  83. cy.get('[data-test=metrics]')
  84. .find('[data-test="metric-option"]')
  85. .should('have.length', 2);
  86. cy.get('#metrics-edit-popover').within(() => {
  87. cy.get('#adhoc-metric-edit-tabs-tab-SQL').click();
  88. cy.get('.ace_identifier').contains('num_girls');
  89. cy.get('.ace_content').click();
  90. cy.get('.ace_text-input').type('{selectall}{backspace}SUM(num)');
  91. cy.get('#adhoc-metric-edit-tabs-tab-SIMPLE').click();
  92. cy.get('.Select__single-value').contains(/^num$/);
  93. cy.get('button').contains('Save').click();
  94. });
  95. cy.get('button[data-test="run-query-button"]').click();
  96. const metric = 'SUM(num)';
  97. cy.verifySliceSuccess({
  98. waitAlias: '@chartData',
  99. querySubstring: `${metric} AS "${metric}"`,
  100. });
  101. });
  102. });