can-skip-upstream-when-select-service-id.cy.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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('Can select service_id skip upstream in route', () => {
  19. const timeout = 2000;
  20. const selector = {
  21. name: '#name',
  22. nodes_0_host: '#submitNodes_0_host',
  23. nodes_0_port: '#submitNodes_0_port',
  24. nodes_0_weight: '#submitNodes_0_weight',
  25. notification: '.ant-notification-notice-message',
  26. upstreamSelector: '[data-cy=upstream_selector]',
  27. input: ':input',
  28. nameSelector: '[title=Name]',
  29. serviceSelector: '[title=test_service]',
  30. deleteAlert: '.ant-modal-body',
  31. notificationCloseIcon: '.ant-notification-close-icon',
  32. enable_websocket: '#enable_websocket',
  33. addbtn: '.ant-btn-primary',
  34. selectItem: '.ant-select-item-option-content',
  35. position: '#position',
  36. value: '#value',
  37. operator: '#operator',
  38. rowcard: '.ant-table-row-level-0',
  39. reverse: '#reverse',
  40. };
  41. const data = {
  42. createUpstreamSuccess: 'Create Upstream Successfully',
  43. createServiceSuccess: 'Create Service Successfully',
  44. upstreamName: 'test_upstream',
  45. serviceName: 'test_service',
  46. routeName: 'test_route',
  47. submitSuccess: 'Submit Successfully',
  48. deleteUpstreamSuccess: 'Delete Upstream Successfully',
  49. deleteServiceSuccess: 'Delete Service Successfully',
  50. deleteRouteSuccess: 'Delete Route Successfully',
  51. ip1: '127.0.0.1',
  52. port0: '7000',
  53. weight0: '1',
  54. parameterName: 'text_Parameter',
  55. value: '["1", "2"]',
  56. };
  57. before(() => {
  58. cy.clearLocalStorageSnapshot();
  59. cy.login();
  60. cy.saveLocalStorage();
  61. });
  62. beforeEach(() => {
  63. cy.restoreLocalStorage();
  64. cy.visit('/');
  65. cy.contains('Route').click();
  66. });
  67. it('should create test upstream and service', function () {
  68. cy.contains('Upstream').click();
  69. cy.wait(timeout);
  70. cy.contains('Create').click();
  71. cy.get(selector.name).type(data.upstreamName);
  72. cy.contains('Next').click();
  73. cy.get(selector.nodes_0_host).type(data.ip1);
  74. cy.get(selector.nodes_0_port).clear().type(data.port0);
  75. cy.get(selector.nodes_0_weight).clear().type(data.weight0);
  76. cy.contains('Next').click();
  77. cy.wait(timeout);
  78. cy.contains('Submit').click();
  79. cy.get(selector.notification).should('contain', data.createUpstreamSuccess);
  80. cy.contains(data.createUpstreamSuccess);
  81. cy.visit('/');
  82. cy.contains('Service').click();
  83. cy.contains('Create').click();
  84. cy.get(selector.name).type(data.serviceName);
  85. cy.get(selector.upstreamSelector).click();
  86. cy.contains(data.upstreamName).click();
  87. cy.contains('Next').click();
  88. cy.contains('Next').click();
  89. cy.contains('Submit').click();
  90. cy.wait(timeout * 2);
  91. cy.get(selector.notification).should('contain', data.createServiceSuccess);
  92. cy.contains(data.createServiceSuccess);
  93. });
  94. it('should skip upstream module after service is selected when creating route', function () {
  95. cy.contains('Create').click();
  96. // The None option doesn't exist when service isn't selected
  97. cy.contains('Next').click().click();
  98. cy.get(selector.name).type(data.routeName);
  99. cy.contains('Next').click();
  100. cy.wait(timeout * 2);
  101. cy.get(selector.upstreamSelector).click();
  102. cy.get('.ant-select-item-option-disabled > .ant-select-item-option-content').contains('None');
  103. cy.contains('Previous').click();
  104. cy.wait(500);
  105. cy.contains('None').click();
  106. cy.contains(data.serviceName).click();
  107. cy.get(selector.enable_websocket).click();
  108. cy.contains('Next').click();
  109. // make sure upstream data can be saved
  110. cy.get(selector.upstreamSelector).click();
  111. cy.contains(data.upstreamName).click();
  112. cy.get(selector.input).should('be.disabled');
  113. cy.contains(data.upstreamName).click();
  114. cy.contains('None').click({
  115. force: true,
  116. });
  117. cy.contains('Next').click();
  118. cy.contains('Next').click();
  119. cy.contains('Submit').click();
  120. cy.contains('Goto List').click();
  121. });
  122. it('should Add Advanced Routing Matching Conditions', function () {
  123. cy.get(selector.nameSelector).type(data.routeName);
  124. cy.contains('Search').click();
  125. cy.contains(data.routeName).siblings().contains('Configure').click();
  126. cy.get(selector.addbtn).contains('Add').click();
  127. cy.get(selector.position).click();
  128. cy.get(selector.selectItem).within(() => {
  129. cy.contains('HTTP Request Header').click();
  130. });
  131. cy.wait(timeout);
  132. cy.get('.ant-form-item-control-input-content > #name').type(data.parameterName);
  133. cy.get(selector.reverse).click();
  134. cy.get(selector.operator).click();
  135. cy.get(selector.selectItem).within(() => {
  136. cy.contains('IN').click();
  137. });
  138. cy.get(selector.value).type(data.value);
  139. cy.contains('Confirm').click();
  140. cy.get(selector.rowcard).should('be.visible');
  141. cy.get(selector.rowcard).get('tr>td').eq(2).contains('true').should('be.visible');
  142. cy.get(selector.rowcard).contains('Configure').click();
  143. cy.get(selector.reverse).click();
  144. cy.contains('Confirm').click();
  145. cy.get(selector.rowcard).get('tr>td').eq(2).contains('false').should('be.visible');
  146. cy.contains('Next').click();
  147. cy.wait(timeout);
  148. cy.contains('Next').click();
  149. cy.wait(timeout);
  150. cy.contains('Next').click();
  151. cy.wait(timeout);
  152. cy.contains('Submit').click();
  153. cy.contains(data.submitSuccess);
  154. });
  155. it('should skip upstream module after service is selected when editing route', function () {
  156. cy.get(selector.nameSelector).type(data.routeName);
  157. cy.contains('Search').click();
  158. cy.contains(data.routeName).siblings().contains('Configure').click();
  159. cy.get(selector.serviceSelector).click();
  160. cy.get(selector.enable_websocket).should('have.class', 'ant-switch-checked');
  161. cy.contains('None').click();
  162. cy.contains('Next').click();
  163. cy.wait(timeout);
  164. cy.get('.ant-select-selector').click({ force: true });
  165. cy.wait(timeout);
  166. cy.contains(data.upstreamName).click();
  167. cy.contains('Next').click();
  168. cy.contains('Next').click();
  169. cy.contains('Submit').click();
  170. cy.contains(data.submitSuccess);
  171. });
  172. it('should delete route, service and upstream', function () {
  173. cy.contains(data.routeName).siblings().contains('More').click();
  174. cy.contains('Delete').click();
  175. cy.get(selector.deleteAlert)
  176. .should('be.visible')
  177. .within(() => {
  178. cy.contains('OK').click();
  179. });
  180. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  181. cy.visit('/');
  182. cy.contains('Service').click();
  183. cy.contains(data.serviceName).siblings().contains('Delete').click();
  184. cy.contains('button', 'Confirm').click();
  185. cy.get(selector.notification).should('contain', data.deleteServiceSuccess);
  186. cy.visit('/');
  187. cy.contains('Upstream').click();
  188. cy.contains(data.upstreamName).siblings().contains('Delete').click();
  189. cy.contains('button', 'Confirm').click();
  190. cy.get(selector.notification).should('contain', data.deleteUpstreamSuccess);
  191. cy.get(selector.notificationCloseIcon).click();
  192. });
  193. });