utils.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 { interceptGet as interceptDashboardGet } from '../dashboard/utils';
  20. export function interceptFiltering() {
  21. cy.intercept('GET', `**/api/v1/chart/?q=*`).as('filtering');
  22. }
  23. export function interceptBulkDelete() {
  24. cy.intercept('DELETE', `**/api/v1/chart/?q=*`).as('bulkDelete');
  25. }
  26. export function interceptDelete() {
  27. cy.intercept('DELETE', `**/api/v1/chart/*`).as('delete');
  28. }
  29. export function interceptFavoriteStatus() {
  30. cy.intercept('GET', '**/api/v1/chart/favorite_status/*').as('favoriteStatus');
  31. }
  32. export function interceptUpdate() {
  33. cy.intercept('PUT', `**/api/v1/chart/*`).as('update');
  34. }
  35. export const interceptV1ChartData = (alias = 'v1Data') => {
  36. cy.intercept('**/api/v1/chart/data*').as(alias);
  37. };
  38. export function interceptExploreJson(alias = 'getJson') {
  39. cy.intercept('POST', `**/superset/explore_json/**`).as(alias);
  40. }
  41. export const interceptFormDataKey = () => {
  42. cy.intercept('POST', '**/api/v1/explore/form_data').as('formDataKey');
  43. };
  44. export function interceptExploreGet() {
  45. cy.intercept({
  46. method: 'GET',
  47. url: /.*\/api\/v1\/explore\/\?(form_data_key|dashboard_page_id|slice_id)=.*/,
  48. }).as('getExplore');
  49. }
  50. export function setFilter(filter: string, option: string) {
  51. interceptFiltering();
  52. cy.get(`[aria-label^="${filter}"]`).first().click();
  53. cy.get(`.ant-select-item-option[title="${option}"]`).first().click({
  54. force: true,
  55. });
  56. cy.wait('@filtering');
  57. }
  58. export function saveChartToDashboard(chartName: string, dashboardName: string) {
  59. interceptDashboardGet();
  60. interceptUpdate();
  61. interceptExploreGet();
  62. cy.getBySel('query-save-button')
  63. .should('be.enabled')
  64. .should('not.be.disabled')
  65. .click({ force: true });
  66. cy.getBySel('save-modal-body')
  67. .should('be.visible')
  68. .then($modal => {
  69. cy.wait(500);
  70. cy.wrap($modal)
  71. .find(
  72. '.ant-select-selection-search-input[aria-label*="Select a dashboard"]',
  73. )
  74. .type(dashboardName, { force: true });
  75. cy.wrap($modal)
  76. .find(`.ant-select-item-option[title="${dashboardName}"]`)
  77. .click();
  78. cy.getBySel('btn-modal-save').click();
  79. cy.wait('@update');
  80. });
  81. cy.getBySel('save-modal-body').should('not.exist');
  82. cy.getBySel('query-save-button').should('be.disabled');
  83. cy.wait('@get');
  84. cy.wait('@getExplore');
  85. cy.contains(`was added to dashboard [${dashboardName}]`);
  86. cy.contains(`Chart [${chartName}] has been overwritten`);
  87. cy.getBySel('query-save-button').should('be.enabled');
  88. }
  89. export function visitSampleChartFromList(chartName: string) {
  90. cy.getBySel('table-row').contains(chartName).click();
  91. cy.intercept('POST', '**/superset/explore_json/**').as('getJson');
  92. }