2
0

create-route-with-advanced-matching-conditions.cy.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 Route with advanced matching conditions', () => {
  19. const selector = {
  20. name: '#name',
  21. nodes_0_host: '#submitNodes_0_host',
  22. nodes_0_port: '#submitNodes_0_port',
  23. nodes_0_weight: '#submitNodes_0_weight',
  24. deleteAlert: '.ant-modal-body',
  25. notification: '.ant-notification-notice-message',
  26. parameterPosition: '#position',
  27. ruleCard: '.ant-modal',
  28. reverse: '#reverse',
  29. operator: '#operator',
  30. value: '#value',
  31. advancedMatchingTable: '.ant-table-row.ant-table-row-level-0',
  32. advancedMatchingTableOperation: '.ant-space',
  33. advancedMatchingTableCell: '.ant-table-cell',
  34. };
  35. const data = {
  36. routeName: `test_route_${Date.now()}`,
  37. submitSuccess: 'Submit Successfully',
  38. ip1: '127.0.0.1',
  39. port: '80',
  40. weight: 1,
  41. matchingParamName: 'server_port',
  42. deleteRouteSuccess: 'Delete Route Successfully',
  43. };
  44. const operatorList = [
  45. // 'Equal(==)' : '1234',
  46. 'Unequal(~=)',
  47. 'Greater Than(>)',
  48. 'Less Than(<)',
  49. // 'Regex Match(~~)',
  50. 'IN',
  51. ];
  52. const matchingValueList1 = ['1000', '800', '2000', '["1800","1888"]'];
  53. const matchingValueList2 = ['2000', '1800', '3000', '["2800","2888"]'];
  54. before(() => {
  55. cy.clearLocalStorageSnapshot();
  56. cy.login();
  57. cy.saveLocalStorage();
  58. });
  59. beforeEach(() => {
  60. cy.restoreLocalStorage();
  61. });
  62. it('should create route with advanced matching conditions', function () {
  63. cy.visit('/routes/list');
  64. cy.contains('Create').click();
  65. cy.contains('Next').click().click();
  66. cy.get(selector.name).type(data.routeName);
  67. // All Of Operational Character Should Exist And Can be Created
  68. cy.wrap(operatorList).each((op, index) => {
  69. cy.wait(2000);
  70. cy.contains('Advanced Routing Matching Conditions')
  71. .parent()
  72. .siblings()
  73. .contains('Add')
  74. .click()
  75. .then(() => {
  76. cy.get(selector.parameterPosition)
  77. .click()
  78. .then(() => {
  79. cy.get('.ant-select-dropdown').within(() => {
  80. cy.contains('Built-in').should('be.visible').click();
  81. });
  82. });
  83. cy.get(selector.ruleCard).within(() => {
  84. cy.get(selector.name).type(data.matchingParamName);
  85. });
  86. // reverse switch should exist
  87. cy.get(selector.reverse)
  88. .should('exist')
  89. .and('be.visible')
  90. .should('have.class', 'ant-switch')
  91. .and('not.have.class', 'ant-switch-checked')
  92. .click()
  93. .and('have.class', 'ant-switch-checked');
  94. cy.get(selector.operator).click();
  95. cy.wait(2000);
  96. cy.get(`[title="${op}"]`).should('be.visible').click();
  97. cy.get(selector.value).type(matchingValueList1[index]);
  98. cy.contains('Confirm').click({ force: true });
  99. });
  100. });
  101. cy.get(selector.advancedMatchingTable).should('exist');
  102. cy.wrap(operatorList).each((operator, index) => {
  103. cy.get(selector.advancedMatchingTableCell).within(() => {
  104. cy.contains('th', 'Reverse the result(!)').should('be.visible');
  105. cy.contains('td', 'Built-in Parameter').should('be.visible');
  106. cy.contains('td', data.matchingParamName).should('be.visible');
  107. cy.contains('td', matchingValueList1[index]).should('be.visible');
  108. });
  109. });
  110. cy.contains('Next').click();
  111. cy.get(selector.nodes_0_host).clear().type(data.ip1);
  112. cy.get(selector.nodes_0_port).type(data.port);
  113. cy.get(selector.nodes_0_weight).type(data.weight);
  114. cy.contains('Next').click();
  115. cy.contains('Next').click();
  116. cy.contains('Submit').click();
  117. cy.contains(data.submitSuccess).should('be.visible');
  118. cy.contains('Goto List').click();
  119. cy.url().should('contains', 'routes/list');
  120. });
  121. it('should edit this route matching conditions', function () {
  122. cy.visit('/routes/list');
  123. cy.get(selector.name).clear().type(data.routeName);
  124. cy.contains('Search').click();
  125. cy.contains(data.routeName).siblings().contains('Configure').click();
  126. cy.get(selector.advancedMatchingTable).should('exist');
  127. cy.wrap(operatorList).each((op, index) => {
  128. cy.get(selector.advancedMatchingTableCell).within(() => {
  129. cy.contains(`${op}`)
  130. .parent('tr')
  131. .within(() => {
  132. cy.get(selector.advancedMatchingTableOperation).within(() => {
  133. cy.contains('Configure').click();
  134. });
  135. });
  136. });
  137. cy.get(selector.ruleCard).within(() => {
  138. cy.get(`[title="Built-in Parameter"]`).should('have.class', 'ant-select-selection-item');
  139. cy.get(selector.name).clear().type(data.matchingParamName);
  140. cy.get(selector.reverse).should('have.class', 'ant-switch-checked');
  141. cy.get(`[title="${op}"]`).should('have.class', 'ant-select-selection-item');
  142. cy.get(selector.value).clear().type(matchingValueList2[index]);
  143. cy.contains('Confirm').click();
  144. });
  145. cy.get(selector.advancedMatchingTableCell).within(() => {
  146. cy.contains('th', 'Reverse the result(!)').should('be.visible');
  147. cy.contains('td', 'Built-in Parameter').should('be.visible');
  148. cy.contains('td', data.matchingParamName).should('be.visible');
  149. cy.contains('td', matchingValueList2[index]).should('be.visible');
  150. });
  151. });
  152. cy.contains('Next').click();
  153. cy.get(selector.nodes_0_port).focus();
  154. cy.contains('Next').click();
  155. cy.contains('Next').click();
  156. cy.contains('Submit').click();
  157. cy.contains(data.submitSuccess);
  158. cy.contains('Goto List').click();
  159. cy.url().should('contains', 'routes/list');
  160. });
  161. it('should delete route matching conditions', function () {
  162. cy.visit('/routes/list');
  163. cy.get(selector.name).clear().type(data.routeName);
  164. cy.contains('Search').click();
  165. cy.contains(data.routeName).siblings().contains('Configure').click();
  166. cy.get(selector.name).should('value', data.routeName);
  167. cy.get(selector.advancedMatchingTable).should('exist');
  168. cy.wrap(operatorList).each(() => {
  169. cy.get(selector.advancedMatchingTableOperation).within(() => {
  170. cy.contains('Delete').click().should('not.exist');
  171. });
  172. });
  173. cy.get(selector.advancedMatchingTable).should('not.exist');
  174. cy.contains('Next').click();
  175. cy.get(selector.nodes_0_port).focus();
  176. cy.contains('Next').click();
  177. cy.contains('Next').click();
  178. cy.contains('Submit').click();
  179. cy.contains(data.submitSuccess);
  180. cy.contains('Goto List').click();
  181. cy.url().should('contains', 'routes/list');
  182. cy.visit('/routes/list');
  183. cy.get(selector.name).clear().type(data.routeName);
  184. cy.contains('Search').click();
  185. cy.contains(data.routeName).siblings().contains('More').click();
  186. cy.contains('Delete').click();
  187. cy.get(selector.deleteAlert)
  188. .should('be.visible')
  189. .within(() => {
  190. cy.contains('OK').click();
  191. });
  192. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  193. });
  194. });