create-edit-route-with-redirect-plugin.cy.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* eslint-disable no-undef */
  18. context('Create Edit and Delete Route with redirect plugin', () => {
  19. const name = `routeName${Date.now()}`;
  20. const newName = `newName${Date.now()}`;
  21. const timeout = 2000;
  22. const selector = {
  23. empty: '.ant-empty-normal',
  24. name: '#name',
  25. redirect: '[data-cy=route-redirect]',
  26. customRedirectSelectOpt: '#redirectOption_list_1',
  27. httpsRedirectSelectOpt: '#redirectOption_list_2',
  28. customRedirectUrI: '#redirectURI',
  29. customRedirectCode: '[data-cy=redirect_code]',
  30. customRedirectLabel: "[title='Custom Redirect']",
  31. deleteAlert: '.ant-modal-body',
  32. notificationCloseIcon: '.ant-notification-close-icon',
  33. notification: '.ant-notification-notice-message',
  34. webSocketSelector: '[title=WebSocket]',
  35. enable_websocket_button: '#enable_websocket',
  36. hosts_0: '#hosts_0',
  37. nodes_0_host: '#submitNodes_0_host',
  38. };
  39. const data = {
  40. customRedirectUrI: '/test',
  41. host1: 'test.com',
  42. submitSuccess: 'Submit Successfully',
  43. deleteRouteSuccess: 'Delete Route Successfully',
  44. step2Title: 'Define API Backend Server',
  45. step3Title: 'Plugin Config',
  46. setUpstreamNotice: 'If you do not bind the service, you must set the Upstream (Step 2)',
  47. };
  48. before(() => {
  49. cy.clearLocalStorageSnapshot();
  50. cy.login();
  51. cy.saveLocalStorage();
  52. });
  53. beforeEach(() => {
  54. cy.restoreLocalStorage();
  55. });
  56. it('should create route with custom redirect plugin', function () {
  57. cy.visit('/');
  58. cy.contains('Route').click();
  59. cy.wait(timeout * 2);
  60. cy.get(selector.empty).should('be.visible');
  61. cy.contains('Create').click();
  62. cy.wait(timeout * 2);
  63. cy.contains('Next').click();
  64. cy.contains('Next').click();
  65. cy.get(selector.name).type(name);
  66. cy.get(selector.redirect).click();
  67. cy.contains('Custom').click({ force: true });
  68. // after choose Custom option, Custom Redirect form field should be visible
  69. cy.get(selector.customRedirectLabel).should('be.visible');
  70. cy.get(selector.customRedirectUrI).should('be.visible');
  71. cy.get(selector.customRedirectCode).should('be.visible');
  72. cy.get(selector.webSocketSelector).should('exist');
  73. cy.get(selector.enable_websocket_button).should('exist');
  74. // step 2 and step 3 should not be visible
  75. cy.contains(data.step2Title).should('not.exist');
  76. cy.contains(data.step3Title).should('not.exist');
  77. // type customRedirectUrI
  78. cy.get(selector.customRedirectUrI).type(data.customRedirectUrI);
  79. cy.contains('Next').click();
  80. cy.contains('Submit').click();
  81. cy.contains(data.submitSuccess);
  82. // back to route list page
  83. cy.contains('Goto List').click();
  84. cy.url().should('contains', 'routes/list');
  85. });
  86. it('should edit the route without notice', function () {
  87. cy.visit('/');
  88. cy.contains('Route').click();
  89. cy.get(selector.name).type(name);
  90. cy.contains('Search').click();
  91. cy.contains(name).siblings().contains('Configure').click();
  92. // NOTE: make sure all components rerender done
  93. cy.wait(timeout);
  94. cy.get('#status').should('have.class', 'ant-switch-checked');
  95. // should not shown set upstream notice
  96. cy.contains(data.setUpstreamNotice).should('not.exist');
  97. cy.get(selector.name).focus().clear().type(newName).blur();
  98. cy.get(selector.webSocketSelector).should('exist');
  99. cy.get(selector.enable_websocket_button).should('exist');
  100. for (let i = 0; i < 3; i += 1) {
  101. cy.contains('Next').focus().click({ force: true });
  102. cy.wait(timeout);
  103. }
  104. cy.contains('Submit').click();
  105. cy.contains(data.submitSuccess);
  106. cy.contains('Goto List').click();
  107. cy.url().should('contains', 'routes/list');
  108. cy.contains(newName).should('be.visible');
  109. });
  110. it('should delete the route', function () {
  111. cy.visit('/routes/list');
  112. cy.get(selector.name).focus().clear().type(newName);
  113. cy.contains('Search').click();
  114. cy.contains(newName).siblings().contains('More').click();
  115. cy.contains('Delete').click();
  116. cy.get(selector.deleteAlert)
  117. .should('be.visible')
  118. .within(() => {
  119. cy.contains('OK').click();
  120. });
  121. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  122. cy.get(selector.notificationCloseIcon).click({ multiple: true });
  123. });
  124. it('should enable https redirect without ssl', () => {
  125. cy.visit('/');
  126. cy.contains('Route').click();
  127. cy.wait(timeout * 2);
  128. cy.get(selector.empty).should('be.visible');
  129. cy.contains('Create').click();
  130. cy.wait(timeout * 2);
  131. cy.contains('Next').click();
  132. cy.contains('Next').click();
  133. cy.get(selector.name).type(name);
  134. cy.get(selector.redirect).click();
  135. cy.contains('Enable HTTPS').click({ force: true });
  136. cy.get(selector.hosts_0).type(data.host1);
  137. cy.contains('Next').click();
  138. cy.get(selector.nodes_0_host).type(data.host1);
  139. cy.contains('Next').click();
  140. cy.contains('Next').click();
  141. cy.contains('Submit').click();
  142. cy.contains(data.submitSuccess);
  143. cy.contains('Goto List').click();
  144. cy.url().should('contains', 'routes/list');
  145. cy.get(selector.name).focus().clear().type(name);
  146. cy.contains('Search').click();
  147. cy.contains(name).siblings().contains('More').click();
  148. cy.contains('Delete').click();
  149. cy.get(selector.deleteAlert)
  150. .should('be.visible')
  151. .within(() => {
  152. cy.contains('OK').click();
  153. });
  154. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  155. cy.get(selector.notificationCloseIcon).click({ multiple: true });
  156. });
  157. });