search-route.cy.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 */
  18. context('Create and Search Route', () => {
  19. const timeout = 2000;
  20. const selector = {
  21. name: '#name',
  22. description: '#desc',
  23. hosts_0: '#hosts_0',
  24. uris_0: '#uris_0',
  25. labels_0_labelKey: '#labels_0_labelKey',
  26. labels_0_labelValue: '#labels_0_labelValue',
  27. nodes_0_host: '#submitNodes_0_host',
  28. nodes_0_port: '#submitNodes_0_port',
  29. nodes_0_weight: '#submitNodes_0_weight',
  30. nameSearchInput: '#name',
  31. pathSearchInput: '#uri',
  32. labelSelect_0: '.ant-select-selection-overflow',
  33. dropdown: '.rc-virtual-list',
  34. disabledSwitcher: '#disable',
  35. checkedSwitcher: '.ant-switch-checked',
  36. deleteAlert: '.ant-modal-body',
  37. drawerBody: '.ant-drawer-wrapper-body',
  38. notification: '.ant-notification-notice-message',
  39. notificationClose: '.anticon-close',
  40. expandSearch: '.ant-pro-form-collapse-button',
  41. };
  42. const data = {
  43. host1: '11.11.11.11',
  44. host2: '12.12.12.12',
  45. port: '80',
  46. weight: 1,
  47. uris: '/get',
  48. uris0: '/get0',
  49. uris1: '/get1',
  50. uris2: '/get2',
  51. urisx: '/getx',
  52. submitSuccess: 'Submit Successfully',
  53. deleteRouteSuccess: 'Delete Route Successfully',
  54. test: 'test',
  55. test0: 'test0',
  56. test1: 'test1',
  57. test2: 'test2',
  58. testx: 'testx',
  59. desc0: 'desc0',
  60. desc1: 'desc1',
  61. desc2: 'desc2',
  62. value0: 'value0',
  63. label0_value0: 'label0:value0',
  64. };
  65. before(() => {
  66. cy.clearLocalStorageSnapshot();
  67. cy.login();
  68. cy.saveLocalStorage();
  69. });
  70. beforeEach(() => {
  71. cy.restoreLocalStorage();
  72. });
  73. it('should create route test0, test1, test2', function () {
  74. cy.visit('/');
  75. cy.contains('Route').click();
  76. cy.wait(timeout);
  77. for (let i = 0; i < 3; i += 1) {
  78. cy.contains('Create').click();
  79. cy.contains('Next').click().click();
  80. cy.get(selector.name).type(`test${i}`);
  81. cy.get(selector.description).type(`desc${i}`);
  82. cy.get(selector.hosts_0).type(data.host1);
  83. cy.get(selector.uris_0).clear().type(`/get${i}`);
  84. // config label
  85. cy.contains('Manage').click();
  86. // eslint-disable-next-line no-loop-func
  87. cy.get(selector.drawerBody).within(() => {
  88. cy.contains('button', 'Add')
  89. .should('not.be.disabled')
  90. .click()
  91. .then(() => {
  92. cy.get(selector.labels_0_labelKey).type(`label${i}`);
  93. cy.get(selector.labels_0_labelValue).type(`value${i}`);
  94. cy.contains('Confirm').click();
  95. });
  96. });
  97. cy.contains('button', 'Next').should('not.be.disabled').click();
  98. cy.get(selector.nodes_0_host).type(data.host2, {
  99. timeout,
  100. });
  101. cy.wait(timeout);
  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. cy.contains('Next').click();
  106. cy.contains('Submit').click();
  107. cy.contains(data.submitSuccess);
  108. cy.contains('Goto List').click();
  109. cy.url().should('contains', 'routes/list');
  110. }
  111. });
  112. it('should search the route with name', function () {
  113. cy.visit('/');
  114. cy.contains('Route').click();
  115. cy.wait(timeout);
  116. // full match
  117. cy.get(selector.nameSearchInput).type(data.test1);
  118. cy.contains('Search').click();
  119. cy.contains(data.test1).siblings().should('contain', data.desc1);
  120. cy.contains(data.test0).should('not.exist');
  121. cy.contains(data.test2).should('not.exist');
  122. // partial match
  123. cy.get(selector.nameSearchInput).clear().type(data.test);
  124. cy.contains('Search').click();
  125. cy.contains(data.test0).siblings().should('contain', data.desc0);
  126. cy.contains(data.test1).siblings().should('contain', data.desc1);
  127. cy.contains(data.test2).siblings().should('contain', data.desc2);
  128. // no match
  129. cy.get(selector.nameSearchInput).clear().type(data.testx);
  130. cy.contains('Search').click();
  131. cy.contains(data.test0).should('not.exist');
  132. cy.contains(data.test1).should('not.exist');
  133. cy.contains(data.test2).should('not.exist');
  134. });
  135. it('should search the route with path', function () {
  136. cy.visit('/');
  137. cy.contains('Route').click();
  138. cy.wait(timeout);
  139. // full match
  140. // expand search
  141. cy.get(selector.expandSearch).click();
  142. cy.get(selector.pathSearchInput).type(data.uris1);
  143. cy.contains('Search').click();
  144. cy.contains(data.uris1).should('contain', data.uris1);
  145. cy.contains(data.uris0).should('not.exist');
  146. cy.contains(data.uris2).should('not.exist');
  147. // partial match
  148. cy.get(selector.pathSearchInput).clear().type(data.uris);
  149. cy.contains('Search').click();
  150. cy.contains(data.uris0).should('contain', data.uris);
  151. cy.contains(data.uris1).should('contain', data.uris);
  152. cy.contains(data.uris2).should('contain', data.uris);
  153. // no match
  154. cy.get(selector.pathSearchInput).clear().type(data.urisx);
  155. cy.contains('Search').click();
  156. cy.contains(data.uris0).should('not.exist');
  157. cy.contains(data.uris1).should('not.exist');
  158. cy.contains(data.uris2).should('not.exist');
  159. });
  160. it('should search the route with labels', function () {
  161. cy.visit('/');
  162. cy.contains('Route').click();
  163. cy.wait(timeout);
  164. // search one label
  165. cy.get(selector.expandSearch).click();
  166. cy.get(selector.labelSelect_0).click({ timeout });
  167. cy.get(selector.dropdown).contains(data.value0).should('be.visible').click();
  168. cy.contains('Search').click();
  169. cy.contains(data.test0).siblings().should('contain', data.label0_value0);
  170. cy.contains(data.test1).should('not.exist');
  171. cy.contains(data.test2).should('not.exist');
  172. });
  173. it('should delete the route', function () {
  174. cy.visit('/routes/list');
  175. cy.wait(timeout);
  176. for (let i = 0; i < 3; i += 1) {
  177. cy.contains(`test${i}`).siblings().contains('More').click({ timeout });
  178. cy.contains('Delete').should('be.visible').click({ timeout });
  179. cy.get(selector.deleteAlert)
  180. .should('be.visible')
  181. .within(() => {
  182. cy.contains('OK').click();
  183. });
  184. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  185. cy.get(selector.notificationClose).should('be.visible').click({
  186. force: true,
  187. multiple: true,
  188. });
  189. cy.wait(timeout);
  190. }
  191. });
  192. });