You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by su...@apache.org on 2021/05/17 02:08:35 UTC

[apisix-dashboard] branch master updated: chore: refactored test create-route-with-cors-form.spec.js (#1863)

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

sunyi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 019b30d  chore: refactored test create-route-with-cors-form.spec.js (#1863)
019b30d is described below

commit 019b30db83827d720e0cc3e57051b949ad51f49b
Author: Ayush das <ay...@gmail.com>
AuthorDate: Mon May 17 07:38:28 2021 +0530

    chore: refactored test create-route-with-cors-form.spec.js (#1863)
---
 .../route/create-route-with-cors-form.spec.js      | 80 +++++++++++++---------
 1 file changed, 47 insertions(+), 33 deletions(-)

diff --git a/web/cypress/integration/route/create-route-with-cors-form.spec.js b/web/cypress/integration/route/create-route-with-cors-form.spec.js
index 2630933..3c94711 100644
--- a/web/cypress/integration/route/create-route-with-cors-form.spec.js
+++ b/web/cypress/integration/route/create-route-with-cors-form.spec.js
@@ -18,65 +18,83 @@
 
 context('Create and delete route with cors form', () => {
   const selector = {
+    empty: '.ant-empty-normal',
+    name: '#name',
+    description: '#desc',
+    pluginCardBordered: '.ant-card-bordered',
+    disabledSwitcher: '#disable',
+    checkedSwitcher: '.ant-switch-checked',
+    drawer: '.ant-drawer-content',
+    nodes_0_host: '#nodes_0_host',
+    nodes_0_port: '#nodes_0_port',
+    nodes_0_weight: '#nodes_0_weight',
+    deleteAlert: '.ant-modal-body',
+    notificationCloseIcon: '.ant-notification-close-icon',
+    notification: '.ant-notification-notice-message',
     allow_credential: "#allow_credential",
     allow_origins_by_regex0: "#allow_origins_by_regex_0",
     allow_origins_by_regex1: "#allow_origins_by_regex_1",
     addButton: "[data-cy=add-allow_origins_by_regex]",
   }
 
+  const data = {
+    deleteRouteSuccess: 'Delete Route Successfully',
+    submitSuccess: 'Submit Successfully',
+    port: '80',
+    weight: 1,
+  };
+
   beforeEach(() => {
     cy.login();
-
-    cy.fixture('selector.json').as('domSelector');
-    cy.fixture('data.json').as('data');
   });
 
   it('should create route with cors form', function () {
     cy.visit('/');
     cy.contains('Route').click();
-    cy.get(this.domSelector.empty).should('be.visible');
+    cy.get(selector.empty).should('be.visible');
     cy.contains('Create').click();
     cy.contains('Next').click().click();
-    cy.get(this.domSelector.name).type('routeName');
-    cy.get(this.domSelector.description).type('desc');
+    cy.get(selector.name).type('routeName');
+    cy.get(selector.description).type('desc');
     cy.contains('Next').click();
 
-    cy.get(this.domSelector.nodes_0_host).type('127.0.0.1');
-    cy.get(this.domSelector.nodes_0_port).clear().type(this.data.port);
-    cy.get(this.domSelector.nodes_0_weight).clear().type(this.data.weight);
+    cy.get(selector.nodes_0_host).type('127.0.0.1');
+    cy.get(selector.nodes_0_port).clear().type(data.port);
+    cy.get(selector.nodes_0_weight).clear().type(data.weight);
     cy.contains('Next').click();
 
     // config cors plugin
-    cy.contains('cors').parents(this.domSelector.pluginCardBordered).within(() => {
+    cy.contains('cors').parents(selector.pluginCardBordered).within(() => {
       cy.get('button').click({
         force: true
       });
     });
 
-    cy.get(this.domSelector.drawer).should('be.visible').within(() => {
-      cy.get(this.domSelector.disabledSwitcher).click();
-      cy.get(this.domSelector.checkedSwitcher).should('exist');
+    cy.get(selector.drawer).should('be.visible').within(() => {
+      cy.get(selector.disabledSwitcher).click();
+      cy.get(selector.checkedSwitcher).should('exist');
     });
 
     // config cors form
     cy.get(selector.allow_credential).click();
     cy.get(selector.allow_origins_by_regex0).type('.*.test.com');
+
     // add allow_origins_by_regex, assert new input and minus icons exist
     cy.get(selector.addButton).click();
     cy.get(selector.allow_origins_by_regex1).should('exist');
     cy.get(selector.allow_origins_by_regex0).next().should('have.class', 'anticon-minus-circle');
     cy.get(selector.allow_origins_by_regex1).type('foo.com').next().should('have.class', 'anticon-minus-circle');
 
-    cy.get(this.domSelector.drawer).within(() => {
+    cy.get(selector.drawer).within(() => {
       cy.contains('Submit').click({
         force: true,
       });
     });
-    cy.get(this.domSelector.drawer).should('not.exist');
+    cy.get(selector.drawer).should('not.exist');
 
     cy.contains('button', 'Next').click();
     cy.contains('button', 'Submit').click();
-    cy.contains(this.data.submitSuccess);
+    cy.contains(data.submitSuccess);
 
     // back to route list page
     cy.contains('Goto List').click();
@@ -86,38 +104,38 @@ context('Create and delete route with cors form', () => {
   it('should edit route with cors form no allow_origins_by_regex configured', function () {
     cy.visit('/');
     cy.contains('Route').click();
-    cy.get(this.domSelector.name).clear().type('routeName');
+    cy.get(selector.name).clear().type('routeName');
     cy.contains('Search').click();
     cy.contains('routeName').siblings().contains('Configure').click();
-    cy.get(this.domSelector.name).should('have.value','routeName');
+    cy.get(selector.name).should('have.value','routeName');
     cy.contains('Next').click();
     cy.contains('Next').click();
 
     // config cors plugin
-    cy.contains('cors').parents(this.domSelector.pluginCardBordered).within(() => {
+    cy.contains('cors').parents(selector.pluginCardBordered).within(() => {
       cy.get('button').click({
         force: true
       });
     });
 
-    cy.get(this.domSelector.drawer).should('be.visible').within(() => {
-      cy.get(this.domSelector.disabledSwitcher).click();
-      cy.get(this.domSelector.checkedSwitcher).should('exist');
+    cy.get(selector.drawer).should('be.visible').within(() => {
+      cy.get(selector.disabledSwitcher).click();
+      cy.get(selector.checkedSwitcher).should('exist');
     });
 
     // edit allow_origins_by_regex ''
     cy.get(selector.allow_origins_by_regex0).clear();
     cy.get(selector.allow_origins_by_regex1).next().click();
-    cy.get(this.domSelector.drawer).within(() => {
+    cy.get(selector.drawer).within(() => {
       cy.contains('Submit').click({
         force: true,
       });
     });
-    cy.get(this.domSelector.drawer).should('not.exist');
+    cy.get(selector.drawer).should('not.exist');
 
     cy.contains('button', 'Next').click();
     cy.contains('button', 'Submit').click();
-    cy.contains(this.data.submitSuccess);
+    cy.contains(data.submitSuccess);
 
     // back to route list page
     cy.contains('Goto List').click();
@@ -126,19 +144,15 @@ context('Create and delete route with cors form', () => {
 
   it('should delete the route', function () {
     cy.visit('/routes/list');
-    const {
-      domSelector,
-      data
-    } = this;
 
-    cy.get(domSelector.name).clear().type('routeName');
+    cy.get(selector.name).clear().type('routeName');
     cy.contains('Search').click();
     cy.contains('routeName').siblings().contains('More').click();
     cy.contains('Delete').click();
-    cy.get(domSelector.deleteAlert).should('be.visible').within(() => {
+    cy.get(selector.deleteAlert).should('be.visible').within(() => {
       cy.contains('OK').click();
     });
-    cy.get(domSelector.notification).should('contain', data.deleteRouteSuccess);
-    cy.get(domSelector.notificationCloseIcon).click({ multiple: true});
+    cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
+    cy.get(selector.notificationCloseIcon).click({ multiple: true});
   });
 });