You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by di...@apache.org on 2022/09/05 15:06:33 UTC

[superset] 07/08: Refactor fav/unfav

This is an automated email from the ASF dual-hosted git repository.

diegopucci pushed a commit to branch chore/cypress-runtime-enhancements
in repository https://gitbox.apache.org/repos/asf/superset.git

commit a9eb065a1f7a090298eb2b0bc525b77a5ae5350b
Author: geido <di...@gmail.com>
AuthorDate: Mon Sep 5 17:50:15 2022 +0300

    Refactor fav/unfav
---
 .../cypress/integration/dashboard/actions.test.js  | 44 +++++++++++++++
 .../integration/dashboard/dashboard.helper.ts      |  3 -
 .../cypress/integration/dashboard/editmode.test.ts |  3 +-
 .../cypress/integration/dashboard/fav_star.test.js | 64 ----------------------
 .../cypress/integration/dashboard/utils.ts         |  8 +++
 .../integration/dashboard_list/list.test.ts        |  6 +-
 6 files changed, 57 insertions(+), 71 deletions(-)

diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/actions.test.js b/superset-frontend/cypress-base/cypress/integration/dashboard/actions.test.js
new file mode 100644
index 0000000000..32eca632ba
--- /dev/null
+++ b/superset-frontend/cypress-base/cypress/integration/dashboard/actions.test.js
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { SAMPLE_DASHBOARD_1 } from 'cypress/utils/urls';
+import { interceptFav, interceptUnfav } from './utils';
+
+describe('Dashboard actions', () => {
+  beforeEach(() => {
+    cy.createSampleDashboards();
+    cy.visit(SAMPLE_DASHBOARD_1);
+  });
+
+  it('should allow to favorite/unfavorite dashboard', () => {
+    interceptFav();
+    interceptUnfav();
+
+    cy.getBySel('dashboard-header-container')
+      .find("[aria-label='favorite-unselected']")
+      .click();
+    cy.wait('@select');
+    cy.getBySel('dashboard-header-container')
+      .find("[aria-label='favorite-selected']")
+      .click();
+    cy.wait('@unselect');
+    cy.getBySel('dashboard-header-container')
+      .find("[aria-label='favorite-selected']")
+      .should('not.exist');
+  });
+})
diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/dashboard.helper.ts b/superset-frontend/cypress-base/cypress/integration/dashboard/dashboard.helper.ts
index b693097d0f..7201cc203c 100644
--- a/superset-frontend/cypress-base/cypress/integration/dashboard/dashboard.helper.ts
+++ b/superset-frontend/cypress-base/cypress/integration/dashboard/dashboard.helper.ts
@@ -55,9 +55,6 @@ export const testItems = {
   filterNumericalColumn: 'SP_RUR_TOTL_ZS',
 };
 
-export const CHECK_DASHBOARD_FAVORITE_ENDPOINT =
-  '/superset/favstar/Dashboard/*/count';
-
 export function cleanUp() {
   cy.deleteDashboardByName(testItems.dashboard);
   cy.deleteDashboardByName(testItems.defaultNameDashboard);
diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts b/superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts
index b926f02b3f..90b06d408f 100644
--- a/superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts
+++ b/superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts
@@ -103,8 +103,7 @@ function assertMetadata(text: string) {
 }
 function clearMetadata() {
     cy.get('#json_metadata').then(($jsonmetadata) => {
-      cy.wait(1000);
-      cy.wrap($jsonmetadata).type('{selectall}{backspace}');
+      cy.wrap($jsonmetadata).type('{selectall} {backspace}');
     });
 }
 
diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/fav_star.test.js b/superset-frontend/cypress-base/cypress/integration/dashboard/fav_star.test.js
deleted file mode 100644
index 9b527a4c7a..0000000000
--- a/superset-frontend/cypress-base/cypress/integration/dashboard/fav_star.test.js
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-import {
-  CHECK_DASHBOARD_FAVORITE_ENDPOINT,
-} from './dashboard.helper';
-
-import { WORLD_HEALTH_DASHBOARD } from 'cypress/utils/urls';
-
-describe('Dashboard add to favorite', () => {
-  let isFavoriteDashboard = false;
-
-  beforeEach(() => {
-    cy.login();
-
-    cy.intercept(CHECK_DASHBOARD_FAVORITE_ENDPOINT).as('countFavStar');
-    cy.visit(WORLD_HEALTH_DASHBOARD);
-
-    cy.wait('@countFavStar').then(xhr => {
-      isFavoriteDashboard = xhr.response.body.count === 1;
-    });
-  });
-
-  it('should allow favor/unfavor', () => {
-    if (!isFavoriteDashboard) {
-      cy.get('[data-test="fave-unfave-icon"]')
-        .find('span')
-        .should('have.attr', 'aria-label', 'favorite-unselected');
-      cy.get('[data-test="fave-unfave-icon"]').trigger('click');
-      cy.get('[data-test="fave-unfave-icon"]')
-        .find('span')
-        .should('have.attr', 'aria-label', 'favorite-selected')
-        .and('not.have.attr', 'aria-label', 'favorite-unselected');
-    } else {
-      cy.get('[data-test="fave-unfave-icon"]')
-        .find('span')
-        .should('have.attr', 'aria-label', 'favorite-unselected')
-        .and('not.have.attr', 'aria-label', 'favorite-selected');
-      cy.get('[data-test="fave-unfave-icon"]').trigger('click');
-      cy.get('[data-test="fave-unfave-icon"]')
-        .find('span')
-        .should('have.attr', 'aria-label', 'favorite-unselected')
-        .and('not.have.attr', 'aria-label', 'favorite-selected');
-    }
-
-    // reset to original fav state
-    cy.get('[data-test="fave-unfave-icon"]').trigger('click');
-  });
-});
diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/utils.ts b/superset-frontend/cypress-base/cypress/integration/dashboard/utils.ts
index 6e562f5a7e..36dc54b89f 100644
--- a/superset-frontend/cypress-base/cypress/integration/dashboard/utils.ts
+++ b/superset-frontend/cypress-base/cypress/integration/dashboard/utils.ts
@@ -66,6 +66,14 @@ export function interceptLog() {
   cy.intercept('/superset/log/?explode=events&dashboard_id=*').as('logs');
 }
 
+export function interceptFav() {
+    cy.intercept(`/superset/favstar/Dashboard/*/select/`).as('select');
+}
+
+export function interceptUnfav() {
+    cy.intercept(`/superset/favstar/Dashboard/*/unselect/`).as('unselect');
+}
+
 export function setFilter(filter: string, option: string) {
   interceptFiltering();
 
diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard_list/list.test.ts b/superset-frontend/cypress-base/cypress/integration/dashboard_list/list.test.ts
index da9d7a4bfc..28caab8753 100644
--- a/superset-frontend/cypress-base/cypress/integration/dashboard_list/list.test.ts
+++ b/superset-frontend/cypress-base/cypress/integration/dashboard_list/list.test.ts
@@ -23,6 +23,8 @@ import {
   interceptBulkDelete,
   interceptUpdate,
   interceptDelete,
+  interceptFav,
+  interceptUnfav,
 } from '../dashboard/utils';
 
 function orderAlphabetical() {
@@ -130,8 +132,8 @@ describe('Dashboards list', () => {
     });
 
     it('should allow to favorite/unfavorite dashboard', () => {
-      cy.intercept(`/superset/favstar/Dashboard/*/select/`).as('select');
-      cy.intercept(`/superset/favstar/Dashboard/*/unselect/`).as('unselect');
+      interceptFav();
+      interceptUnfav();
 
       setGridMode('card');
       orderAlphabetical();