2
0

create-route-with-proxy-rewrite-plugin.cy.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. import componentLocaleUS from '../../../src/locales/en-US/component';
  19. import menuLocaleUS from '../../../src/locales/en-US/menu';
  20. import routeLocaleUS from '../../../src/pages/Route/locales/en-US';
  21. context('create route with proxy-rewrite plugin', () => {
  22. const selector = {
  23. name: '#name',
  24. nodes_0_host: '#submitNodes_0_host',
  25. nodes_0_port: '#submitNodes_0_port',
  26. nodes_0_weight: '#submitNodes_0_weight',
  27. nameSelector: '[title=Name]',
  28. deleteAlert: '.ant-modal-body',
  29. notification: '.ant-notification-notice-message',
  30. staticUri: '[data-cy=uri-static]',
  31. regexUri: '[data-cy=uri-regex]',
  32. staticHost: '[data-cy=host-static]',
  33. keepHost: '[data-cy=host-keep]',
  34. newUri: '#proxyRewrite_uri',
  35. uriRewriteReg: '#proxyRewrite_regex_uri_0',
  36. uriRewriteTemp: '#proxyRewrite_regex_uri_1',
  37. newHost: '#proxyRewrite_host',
  38. methodRewriteSelect: '[data-cy=proxyRewrite-method]',
  39. methodRewriteSelectOption: '.ant-select-item-option',
  40. buttonCreateNewRewriteHeader: '[data-cy=create-new-rewrite-header]',
  41. rewriteHeaderKey1: '#proxyRewrite_kvHeaders_0_key',
  42. rewriteHeaderValue1: '#proxyRewrite_kvHeaders_0_value',
  43. rewriteHeaderKey2: '#proxyRewrite_kvHeaders_1_key',
  44. rewriteHeaderValue2: '#proxyRewrite_kvHeaders_1_value',
  45. };
  46. const data = {
  47. host2: '12.12.12.12',
  48. port: '80',
  49. weight: 1,
  50. routeName: 'test_route',
  51. submitSuccess: 'Submit Successfully',
  52. deleteRouteSuccess: 'Delete Route Successfully',
  53. rewriteUri: '/get',
  54. rewriteHeaderKey1: 'test1',
  55. rewriteHeaderKey2: 'test2',
  56. rewriteHeaderValue1: '1',
  57. rewriteHeaderValue2: '2',
  58. regex: '^/iresty/(.)/(.)/(.*)',
  59. };
  60. beforeEach(() => {
  61. cy.login();
  62. });
  63. it('should create route with proxy-rewrite plugin', function () {
  64. cy.visit('/');
  65. cy.contains(menuLocaleUS['menu.routes']).click();
  66. // show create page
  67. cy.contains(componentLocaleUS['component.global.create']).click();
  68. cy.contains('Next').click().click();
  69. cy.get(selector.name).type(data.routeName);
  70. // show requestOverride PanelSection
  71. cy.contains(routeLocaleUS['page.route.panelSection.title.requestOverride']).should(
  72. 'be.visible',
  73. );
  74. // should show newPath after the URIRewriteType static clicked
  75. cy.get(selector.staticUri).click();
  76. cy.contains(routeLocaleUS['page.route.form.itemLabel.newPath']).should('be.visible');
  77. cy.get(selector.newUri).should('be.visible').type(data.rewriteUri);
  78. // should show regexp and template after URIRewriteType regexp clicked
  79. cy.contains(routeLocaleUS['page.route.radio.regex']).click();
  80. cy.contains(routeLocaleUS['page.route.form.itemLabel.regex']).should('be.visible');
  81. cy.get(selector.uriRewriteReg).should('be.visible');
  82. cy.contains(routeLocaleUS['page.route.form.itemLabel.template']).should('be.visible');
  83. cy.get(selector.uriRewriteTemp).should('be.visible');
  84. cy.get(selector.staticUri).click();
  85. // should show newhost after static host clicked
  86. cy.get(selector.staticHost).click();
  87. cy.contains(routeLocaleUS['page.route.form.itemLabel.newHost']).should('be.visible');
  88. cy.get(selector.newHost).should('be.visible');
  89. cy.get(selector.keepHost).click();
  90. cy.get(selector.newHost).should('not.exist');
  91. // method rewrite
  92. cy.get(selector.methodRewriteSelect).click();
  93. cy.get(selector.methodRewriteSelectOption).contains('POST').click();
  94. // new header key value input after createNewRewriteHeader button clicked
  95. cy.get(selector.buttonCreateNewRewriteHeader).click();
  96. cy.get(selector.rewriteHeaderKey1).should('be.visible').type(data.rewriteHeaderKey1);
  97. cy.get(selector.rewriteHeaderValue1).should('be.visible').type(data.rewriteHeaderValue1);
  98. cy.get(selector.rewriteHeaderKey2).should('be.visible').type(data.rewriteHeaderKey2);
  99. cy.get(selector.rewriteHeaderValue2).should('be.visible').type(data.rewriteHeaderValue2);
  100. cy.contains('Next').click();
  101. cy.get(selector.nodes_0_host).type(data.host2);
  102. cy.get(selector.nodes_0_port).type(data.port);
  103. cy.get(selector.nodes_0_weight).type(data.weight);
  104. cy.contains('Next').click();
  105. // should not see proxy-rewrite plugin in the step3
  106. cy.contains('proxy-rewrite').should('not.exist');
  107. cy.contains('Next').click();
  108. cy.contains('Submit').click();
  109. cy.contains(data.submitSuccess).should('be.visible');
  110. });
  111. it('should keep the same proxy-rewrite data in edit route page with the create data', function () {
  112. cy.visit('/');
  113. cy.contains(menuLocaleUS['menu.routes']).click();
  114. cy.get(selector.nameSelector).type(data.routeName);
  115. cy.contains('Search').click();
  116. cy.contains(data.routeName).siblings().contains('Configure').click();
  117. // NOTE: make sure all components rerender done
  118. cy.get('#status').should('have.class', 'ant-switch-checked');
  119. cy.get(selector.name).type(data.routeName);
  120. cy.contains(routeLocaleUS['page.route.form.itemLabel.newPath']).should('be.visible');
  121. cy.get(selector.newUri).should('have.value', data.rewriteUri);
  122. cy.get(selector.newHost).should('not.exist');
  123. cy.get(selector.methodRewriteSelect).contains('POST').should('exist');
  124. cy.get(selector.rewriteHeaderKey1).should('have.value', data.rewriteHeaderKey1);
  125. cy.get(selector.rewriteHeaderValue1).should('have.value', data.rewriteHeaderValue1);
  126. cy.get(selector.rewriteHeaderKey2).should('have.value', data.rewriteHeaderKey2);
  127. cy.get(selector.rewriteHeaderValue2).should('have.value', data.rewriteHeaderValue2);
  128. cy.contains('Next').click();
  129. cy.get(selector.nodes_0_host).should('have.value', data.host2);
  130. cy.contains('Next').click();
  131. // should not see proxy-rewrite plugin in the step3
  132. cy.contains('proxy-rewrite').should('not.exist');
  133. cy.contains('Next').click();
  134. cy.contains('Submit').click();
  135. cy.contains(data.submitSuccess).should('be.visible');
  136. });
  137. it('should use proxy rewrite in regex uri moode without template', () => {
  138. cy.visit('/');
  139. cy.contains(menuLocaleUS['menu.routes']).click();
  140. cy.get(selector.nameSelector).type(data.routeName);
  141. cy.contains('Search').click();
  142. cy.contains(data.routeName).siblings().contains('Configure').click();
  143. cy.get('#status').should('have.class', 'ant-switch-checked');
  144. cy.get(selector.regexUri).click();
  145. cy.get(selector.uriRewriteReg).should('be.visible').type(data.regex);
  146. cy.get(selector.uriRewriteTemp).should('have.value', '');
  147. cy.contains('Next').click();
  148. cy.get(selector.nodes_0_host).type(data.host2);
  149. cy.get(selector.nodes_0_port).type(data.port);
  150. cy.get(selector.nodes_0_weight).type(data.weight);
  151. cy.contains('Next').click();
  152. cy.contains('proxy-rewrite').should('not.exist');
  153. cy.contains('Next').click();
  154. cy.contains('Submit').click();
  155. cy.contains(data.submitSuccess).should('be.visible');
  156. });
  157. it('should delete the route', function () {
  158. cy.visit('/routes/list');
  159. cy.get(selector.nameSelector).type(data.routeName);
  160. cy.contains('Search').click();
  161. cy.contains(data.routeName).siblings().contains('More').click();
  162. cy.contains('Delete').click();
  163. cy.get(selector.deleteAlert)
  164. .should('be.visible')
  165. .within(() => {
  166. cy.contains('OK').click();
  167. });
  168. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  169. });
  170. });