suddjian commented on a change in pull request #13784:
URL: https://github.com/apache/superset/pull/13784#discussion_r601202246



##########
File path: 
superset-frontend/cypress-base/cypress/integration/dashboard/dashboard.helper.ts
##########
@@ -22,6 +24,79 @@ export const TABBED_DASHBOARD = 
'/superset/dashboard/tabbed_dash/';
 export const CHECK_DASHBOARD_FAVORITE_ENDPOINT =
   '/superset/favstar/Dashboard/*/count';
 
+export const WORLD_HEALTH_CHARTS = [
+  { name: '% Rural', viz: 'world_map' },
+  { name: 'Most Populated Countries', viz: 'table' },
+  { name: 'Region Filter', viz: 'filter_box' },
+  { name: "World's Population", viz: 'big_number' },
+  { name: 'Growth Rate', viz: 'line' },
+  { name: 'Rural Breakdown', viz: 'sunburst' },
+  { name: "World's Pop Growth", viz: 'area' },
+  { name: 'Life Expectancy VS Rural %', viz: 'bubble' },
+  { name: 'Treemap', viz: 'treemap' },
+  { name: 'Box plot', viz: 'box_plot' },
+] as const;
+
+/** Used to specify charts expected by the test suite */
+export interface ChartSpec {
+  name: string;
+  viz: string;
+}
+
+export function getChartGridComponent({ name, viz }: ChartSpec) {
+  return (
+    cy
+      .get('[data-test="grid-content"] [data-test="editable-title"]')
+      .contains(name)
+      // parentsUntil returns the child of the element matching the selector
+      .parentsUntil('[data-test="chart-grid-component"]')
+      .parent()
+      .should('have.attr', 'data-test-viz-type', viz)
+  );
+}
+
+export function waitForChartLoad(chart: ChartSpec) {
+  return getChartGridComponent(chart).then(gridComponent => {
+    const chartId = gridComponent.attr('data-test-chart-id');
+    // the chart should load in under half a minute
+    return (
+      cy
+        // this id only becomes visible when the chart is loaded
+        .wrap(gridComponent)
+        .find(`#chart-id-${chartId}`, { timeout: 30000 })
+        .should('be.visible')
+        // return the chart grid component
+        .then(() => gridComponent)
+    );
+  });
+}
+
+const toSlicelike = ($chart: JQuery<HTMLElement>): Slice => ({
+  slice_id: parseInt($chart.attr('data-test-chart-id')!, 10),
+  form_data: {
+    viz_type: $chart.attr('data-test-viz-type')!,
+  },
+});
+
+export function getChartAliasBySpec(chart: ChartSpec) {
+  return getChartGridComponent(chart).then($chart =>
+    cy.wrap(getChartAlias(toSlicelike($chart))),
+  );
+}
+
+export function getChartAliasesBySpec(charts: readonly ChartSpec[]) {
+  const aliases: string[] = [];
+  charts.forEach(chart =>
+    getChartAliasBySpec(chart).then(alias => {
+      aliases.push(alias);
+    }),
+  );
+  // Wrapping the aliases is key.
+  // That way callers can chain off this function
+  // and actually get the list of aliases.
+  return cy.wrap(aliases);
+}

Review comment:
       Nope. Cypress `.then()` is not the same as promises. It has a queue of 
actions, and you have to `.wrap` anything that you want to be passed to the 
next action in the queue. It makes sense when chaining things like `.get()` and 
`.click()` but when you start using `then` it can be very confusing. I wish 
they had chosen a different name for the function than "then".




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to