create-route-with-service-discovery-upstream.cy.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 Service Discovery Upstream', () => {
  19. const selector = {
  20. name: '#name',
  21. description: '#desc',
  22. discovery_type: '#discovery_type',
  23. service_name: '#service_name',
  24. upstreamSelector: '[data-cy=upstream_selector]',
  25. nameSelector: '[title=Name]',
  26. selectItem: '.ant-select-item-option-content',
  27. drawer: '.ant-drawer-content',
  28. monacoScroll: '.monaco-scrollable-element',
  29. input: ':input',
  30. deleteAlert: '.ant-modal-body',
  31. notification: '.ant-notification-notice-message',
  32. };
  33. const data = {
  34. deleteRouteSuccess: 'Delete Route Successfully',
  35. submitSuccess: 'Submit Successfully',
  36. deleteUpstreamSuccess: 'Delete Upstream Successfully',
  37. weight: 1,
  38. description: 'desc_by_autotest',
  39. upstreamName: 'test_upstream',
  40. routeName: 'test_route',
  41. serviceName: 'test.cluster.local',
  42. consul: 'Consul',
  43. };
  44. beforeEach(() => {
  45. cy.login();
  46. });
  47. it('should create route with DNS service discovery upstream', function () {
  48. cy.visit('/');
  49. cy.get('[role=menu]')
  50. .should('be.visible')
  51. .within(() => {
  52. cy.contains('Route').click();
  53. });
  54. cy.contains('Create').click();
  55. cy.contains('Next').click().click();
  56. cy.get(selector.name).type(data.routeName);
  57. cy.contains('Next').click();
  58. // should enable Upstream input boxes after selecting Custom mode
  59. cy.get(selector.upstreamSelector).click();
  60. cy.contains('.ant-select-item-option-content', 'Custom').click();
  61. // set service discovery
  62. cy.get('[title="Node"]').click();
  63. cy.get(selector.selectItem).within(() => {
  64. cy.contains('Service Discovery').click();
  65. });
  66. cy.get(selector.discovery_type).click();
  67. cy.get(selector.selectItem).within(() => {
  68. cy.contains('DNS').click();
  69. });
  70. cy.get(selector.service_name).type(data.serviceName);
  71. cy.contains('Next').click();
  72. cy.contains('Next').click();
  73. cy.contains('Submit').click();
  74. cy.contains(data.submitSuccess).should('be.visible');
  75. cy.contains('Goto List').click();
  76. cy.url().should('contains', 'routes/list');
  77. // check if the service discovery have been saved
  78. cy.get(selector.nameSelector).type(data.routeName);
  79. cy.contains('Search').click();
  80. cy.contains(data.routeName).siblings().contains('Configure').click();
  81. // ensure it has already changed to edit page
  82. cy.get(selector.name).should('value', data.routeName);
  83. cy.contains('Next').click({
  84. force: true,
  85. });
  86. cy.get(selector.service_name).should('value', data.serviceName);
  87. });
  88. it('should edit this route with Nacos Service Discovery upstream', function () {
  89. cy.visit('/');
  90. cy.contains('Route').click();
  91. cy.get(selector.nameSelector).type(data.routeName);
  92. cy.contains('Search').click();
  93. cy.contains(data.routeName).siblings().contains('Configure').click();
  94. cy.get(selector.name).should('value', data.routeName);
  95. cy.contains('Next').click({
  96. force: true,
  97. });
  98. cy.contains('DNS').should('exist');
  99. // set another service discovery
  100. cy.get(selector.discovery_type).click({ force: true });
  101. cy.get(selector.selectItem).within(() => {
  102. cy.contains('Nacos').click();
  103. });
  104. cy.get(selector.service_name).clear().type(`another.${data.serviceName}`);
  105. cy.contains('Next').click();
  106. cy.contains('Next').click();
  107. cy.contains('Submit').click();
  108. cy.contains(data.submitSuccess).should('be.visible');
  109. cy.contains('Goto List').click();
  110. cy.url().should('contains', 'routes/list');
  111. // check if the changes have been saved
  112. cy.get(selector.nameSelector).type(data.routeName);
  113. cy.contains('Search').click();
  114. cy.contains(data.routeName).siblings().contains('Configure').click();
  115. // ensure it has already changed to edit page
  116. cy.get(selector.name).should('value', data.routeName);
  117. cy.contains('Next').click({
  118. force: true,
  119. });
  120. cy.get(selector.service_name).should('value', `another.${data.serviceName}`);
  121. });
  122. it('should view the test route', function () {
  123. cy.visit('/');
  124. cy.contains('Route').click();
  125. cy.get(selector.nameSelector).type(data.routeName);
  126. cy.contains('Search').click();
  127. cy.contains(data.routeName).siblings().contains('More').click();
  128. cy.contains('View').click();
  129. cy.get(selector.drawer).should('be.visible');
  130. cy.get(selector.monacoScroll).within(() => {
  131. cy.contains('service_name').should('exist');
  132. cy.contains('discovery').should('exist');
  133. });
  134. });
  135. it('should edit this route with Consul Service Discovery upstream', function () {
  136. cy.visit('/');
  137. cy.contains('Route').click();
  138. cy.get(selector.nameSelector).type(data.routeName);
  139. cy.contains('Search').click();
  140. cy.contains(data.routeName).siblings().contains('Configure').click();
  141. cy.get(selector.name).should('value', data.routeName);
  142. cy.contains('Next').click({
  143. force: true,
  144. });
  145. cy.contains('Nacos').should('exist');
  146. // set another service discovery
  147. cy.get(selector.discovery_type).click({ force: true });
  148. cy.get('[title="Consul"] > .ant-select-item-option-content').click();
  149. cy.get(selector.service_name).clear().type(`another.${data.serviceName}`);
  150. cy.contains('Next').click();
  151. cy.contains('Next').click();
  152. cy.contains('Submit').click();
  153. cy.contains(data.submitSuccess).should('be.visible');
  154. cy.contains('Goto List').click();
  155. cy.url().should('contains', 'routes/list');
  156. // check if the changes have been saved
  157. cy.get(selector.nameSelector).type(data.routeName);
  158. cy.contains('Search').click();
  159. cy.contains(data.routeName).siblings().contains('More').click();
  160. cy.contains('View').click();
  161. cy.get(selector.drawer).should('be.visible');
  162. cy.get(selector.monacoScroll).within(() => {
  163. cy.contains(`another.${data.serviceName}`).should('exist');
  164. cy.contains('consul').should('exist');
  165. });
  166. });
  167. it('should delete this test route and upstream', function () {
  168. cy.visit('/routes/list');
  169. cy.get(selector.nameSelector).type(data.routeName);
  170. cy.contains('Search').click();
  171. cy.contains(data.routeName).siblings().contains('More').click();
  172. cy.contains('Delete').click();
  173. cy.get(selector.deleteAlert)
  174. .should('be.visible')
  175. .within(() => {
  176. cy.contains('OK').click();
  177. });
  178. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  179. });
  180. });