create-route-with-search-service-and-set-priority.cy.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 search service name', () => {
  19. const selector = {
  20. name: '#name',
  21. description: '#desc',
  22. priority: '#priority',
  23. nodes_0_host: '#submitNodes_0_host',
  24. nodes_0_port: '#submitNodes_0_port',
  25. nodes_0_weight: '#submitNodes_0_weight',
  26. drawer: '.ant-drawer-content',
  27. monacoScroll: '.monaco-scrollable-element',
  28. notification: '.ant-notification-notice-message',
  29. result: '.ant-result',
  30. nameSelector: '[title=Name]',
  31. serviceSelector: '[title="None"]',
  32. upstreamSelector: '#upstream_id',
  33. deleteAlert: '.ant-modal-body',
  34. };
  35. const data = {
  36. serviceName: 'service_test1',
  37. description: 'desc_by_autotest',
  38. ip: '127.0.0.1',
  39. port: 8000,
  40. weight: 1,
  41. serviceName2: 'service_test2',
  42. ip2: '127.0.0.1',
  43. port2: 8000,
  44. weight2: 1,
  45. priority: 1,
  46. createServiceSuccess: 'Create Service Successfully',
  47. deleteServiceSuccess: 'Delete Service Successfully',
  48. createRouteSuccess: 'Submit Successfully',
  49. deleteRouteSuccess: 'Delete Route Successfully',
  50. routeName: 'route_test1',
  51. searchServiceName: 'service_test2',
  52. upstreamName: 'None (Only available when binding the service)',
  53. };
  54. const timeout = 2000;
  55. before(() => {
  56. cy.clearLocalStorageSnapshot();
  57. cy.login();
  58. cy.saveLocalStorage();
  59. });
  60. beforeEach(() => {
  61. cy.restoreLocalStorage();
  62. });
  63. it('should create two services', function () {
  64. cy.visit('/');
  65. cy.contains('Service').click();
  66. cy.wait(timeout);
  67. cy.contains('Create').click();
  68. cy.get(selector.name).type(data.serviceName);
  69. cy.get(selector.description).type(data.description);
  70. cy.contains('Next').click();
  71. cy.get(selector.nodes_0_host).click();
  72. cy.get(selector.nodes_0_host).type(data.ip);
  73. cy.get(selector.nodes_0_port).clear().type(data.port);
  74. cy.get(selector.nodes_0_weight).clear().type(data.weight);
  75. cy.contains('Next').click();
  76. cy.contains('Next').click();
  77. cy.contains('Submit').click();
  78. cy.wait(timeout);
  79. cy.get(selector.notification).should('contain', data.createServiceSuccess);
  80. cy.visit('/');
  81. cy.contains('Service').click();
  82. cy.contains('Create').click();
  83. cy.get(selector.name).focus().type(data.serviceName2);
  84. cy.get(selector.description).type(data.description);
  85. cy.get(selector.nodes_0_host).click();
  86. cy.get(selector.nodes_0_host).type(data.ip2);
  87. cy.get(selector.nodes_0_port).clear().type(data.port2);
  88. cy.get(selector.nodes_0_weight).clear().type(data.weight2);
  89. cy.wait(timeout);
  90. cy.contains('Next').click();
  91. cy.contains('Next').click();
  92. cy.contains('Submit').click();
  93. cy.get(selector.notification).should('contain', data.createServiceSuccess);
  94. });
  95. it('should create route with search service and set priority', function () {
  96. cy.visit('/');
  97. cy.contains('Route').click();
  98. cy.contains('Create').click();
  99. cy.contains('Next').click().click();
  100. // set name
  101. cy.get(selector.name).type(data.routeName);
  102. cy.get(selector.serviceSelector).type(`${data.serviceName2}\n`);
  103. // set priority
  104. cy.get(selector.priority).type(data.priority);
  105. cy.contains('Next').click();
  106. cy.wait(timeout);
  107. // select upstream with None
  108. cy.get('.ant-select-selector')
  109. .find(selector.upstreamSelector)
  110. .focus()
  111. .type(`${data.upstreamName}\n`, { force: true });
  112. cy.wait(timeout);
  113. cy.contains('Next').click();
  114. cy.contains('Next').click();
  115. cy.contains('Submit').click();
  116. cy.get(selector.result).should('contain', data.createRouteSuccess);
  117. });
  118. it('should check the priority and service was seted', function () {
  119. let serviceUuid = '';
  120. cy.visit('/');
  121. cy.contains('Service').click();
  122. cy.get(selector.name).type(`${data.serviceName2}\n`);
  123. cy.contains(data.serviceName2)
  124. .siblings()
  125. .first()
  126. .then((a) => {
  127. serviceUuid = a.text();
  128. });
  129. cy.visit('/');
  130. cy.contains('Route').click();
  131. cy.get(selector.name).type(`${data.routeName}\n`);
  132. cy.contains(data.routeName).siblings().contains('More').click();
  133. cy.contains('View').click();
  134. cy.get(selector.drawer).should('be.visible');
  135. cy.get(selector.monacoScroll).within(() => {
  136. cy.contains('priority').should('exist');
  137. cy.contains(`${serviceUuid}`).should('exist');
  138. });
  139. });
  140. it('should delete the route and services', function () {
  141. cy.visit('/');
  142. cy.contains('Route').click();
  143. cy.wait(4000);
  144. cy.get(selector.name).type(`${data.routeName}\n`);
  145. cy.contains(data.routeName).siblings().contains('More').click();
  146. cy.contains('Delete').click();
  147. cy.get(selector.deleteAlert)
  148. .should('be.visible')
  149. .within(() => {
  150. cy.contains('OK').click();
  151. });
  152. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  153. cy.visit('/');
  154. cy.contains('Service').click();
  155. cy.contains(data.serviceName).siblings().contains('Delete').click();
  156. cy.contains('button', 'Confirm').click();
  157. cy.get(selector.notification).should('contain', data.deleteServiceSuccess);
  158. cy.get('.ant-notification-close-icon').click().should('not.exist');
  159. cy.contains(data.serviceName2).siblings().contains('Delete').click();
  160. cy.contains('button', 'Confirm').click();
  161. cy.get(selector.notification).should('contain', data.deleteServiceSuccess);
  162. });
  163. });