link.test.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. // ***********************************************
  20. // Tests for links in the explore UI
  21. // ***********************************************
  22. import rison from 'rison';
  23. import { nanoid } from 'nanoid';
  24. import { interceptChart } from 'cypress/utils';
  25. import { HEALTH_POP_FORM_DATA_DEFAULTS } from './visualizations/shared.helper';
  26. const apiURL = (endpoint: string, queryObject: Record<string, unknown>) =>
  27. `${endpoint}?q=${rison.encode(queryObject)}`;
  28. describe('Test explore links', () => {
  29. beforeEach(() => {
  30. interceptChart({ legacy: false }).as('chartData');
  31. });
  32. it('Open and close view query modal', () => {
  33. cy.visitChartByName('Growth Rate');
  34. cy.verifySliceSuccess({ waitAlias: '@chartData' });
  35. cy.get('[aria-label="Menu actions trigger"]').click();
  36. cy.get('span').contains('View query').parent().click();
  37. cy.wait('@chartData').then(() => {
  38. cy.get('code');
  39. });
  40. cy.get('.ant-modal-content').within(() => {
  41. cy.get('button.ant-modal-close').first().click({ force: true });
  42. });
  43. });
  44. it('Test iframe link', () => {
  45. cy.visitChartByName('Growth Rate');
  46. cy.verifySliceSuccess({ waitAlias: '@chartData' });
  47. cy.get('[aria-label="Menu actions trigger"]').click();
  48. cy.get('div[role="menuitem"]').within(() => {
  49. cy.contains('Share').parent().click();
  50. });
  51. cy.getBySel('embed-code-button').click();
  52. cy.get('#embed-code-popover').within(() => {
  53. cy.get('textarea[name=embedCode]').contains('iframe');
  54. });
  55. });
  56. it('Test chart save as AND overwrite', () => {
  57. interceptChart({ legacy: false }).as('tableChartData');
  58. const formData = {
  59. ...HEALTH_POP_FORM_DATA_DEFAULTS,
  60. viz_type: 'table',
  61. metrics: ['sum__SP_POP_TOTL'],
  62. groupby: ['country_name'],
  63. };
  64. const newChartName = `Test chart [${nanoid()}]`;
  65. cy.visitChartByParams(formData);
  66. cy.verifySliceSuccess({ waitAlias: '@tableChartData' });
  67. cy.url().then(() => {
  68. cy.get('[data-test="query-save-button"]').click();
  69. cy.get('[data-test="saveas-radio"]').check();
  70. cy.get('[data-test="new-chart-name"]').type(newChartName, {
  71. force: true,
  72. });
  73. cy.get('[data-test="btn-modal-save"]').click();
  74. cy.verifySliceSuccess({ waitAlias: '@tableChartData' });
  75. cy.visitChartByName(newChartName);
  76. // Overwriting!
  77. cy.get('[data-test="query-save-button"]').click();
  78. cy.get('[data-test="save-overwrite-radio"]').check();
  79. cy.get('[data-test="btn-modal-save"]').click();
  80. cy.verifySliceSuccess({ waitAlias: '@tableChartData' });
  81. const query = {
  82. filters: [
  83. {
  84. col: 'slice_name',
  85. opr: 'eq',
  86. value: newChartName,
  87. },
  88. ],
  89. };
  90. cy.request(apiURL('/api/v1/chart/', query)).then(response => {
  91. expect(response.body.count).equals(1);
  92. });
  93. cy.deleteChartByName(newChartName, true);
  94. });
  95. });
  96. it('Test chart save as and add to new dashboard', () => {
  97. const chartName = 'Growth Rate';
  98. const newChartName = `${chartName} [${nanoid()}]`;
  99. const dashboardTitle = `Test dashboard [${nanoid()}]`;
  100. cy.visitChartByName(chartName);
  101. cy.verifySliceSuccess({ waitAlias: '@chartData' });
  102. cy.get('[data-test="query-save-button"]').click();
  103. cy.get('[data-test="saveas-radio"]').check();
  104. cy.get('[data-test="new-chart-name"]').click();
  105. cy.get('[data-test="new-chart-name"]').clear();
  106. cy.get('[data-test="new-chart-name"]').type(newChartName);
  107. // Add a new option using the "CreatableSelect" feature
  108. cy.get('[data-test="save-chart-modal-select-dashboard-form"]')
  109. .find('input[aria-label="Select a dashboard"]')
  110. .type(`${dashboardTitle}`, { force: true });
  111. cy.get(`.ant-select-item[title="${dashboardTitle}"]`).click({
  112. force: true,
  113. });
  114. cy.get('[data-test="btn-modal-save"]').click();
  115. cy.verifySliceSuccess({ waitAlias: '@chartData' });
  116. let query = {
  117. filters: [
  118. {
  119. col: 'dashboard_title',
  120. opr: 'eq',
  121. value: dashboardTitle,
  122. },
  123. ],
  124. };
  125. cy.request(apiURL('/api/v1/dashboard/', query)).then(response => {
  126. expect(response.body.count).equals(1);
  127. });
  128. cy.visitChartByName(newChartName);
  129. cy.verifySliceSuccess({ waitAlias: '@chartData' });
  130. cy.get('[data-test="query-save-button"]').click();
  131. cy.get('[data-test="save-overwrite-radio"]').check();
  132. cy.get('[data-test="new-chart-name"]').click();
  133. cy.get('[data-test="new-chart-name"]').clear();
  134. cy.get('[data-test="new-chart-name"]').type(newChartName);
  135. // This time around, typing the same dashboard name
  136. // will select the existing one
  137. cy.get('[data-test="save-chart-modal-select-dashboard-form"]')
  138. .find('input[aria-label^="Select a dashboard"]')
  139. .type(`${dashboardTitle}{enter}`, { force: true });
  140. cy.get(`.ant-select-item[title="${dashboardTitle}"]`).click({
  141. force: true,
  142. });
  143. cy.get('[data-test="btn-modal-save"]').click();
  144. cy.verifySliceSuccess({ waitAlias: '@chartData' });
  145. query = {
  146. filters: [
  147. {
  148. col: 'slice_name',
  149. opr: 'eq',
  150. value: chartName,
  151. },
  152. ],
  153. };
  154. cy.request(apiURL('/api/v1/chart/', query)).then(response => {
  155. expect(response.body.count).equals(1);
  156. });
  157. query = {
  158. filters: [
  159. {
  160. col: 'dashboard_title',
  161. opr: 'eq',
  162. value: dashboardTitle,
  163. },
  164. ],
  165. };
  166. cy.request(apiURL('/api/v1/dashboard/', query)).then(response => {
  167. expect(response.body.count).equals(1);
  168. });
  169. cy.deleteDashboardByName(dashboardTitle, true);
  170. });
  171. });