create-route-with-upstream.cy.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 Upstream', () => {
  19. const selector = {
  20. name: '#name',
  21. description: '#desc',
  22. nodes_0_host: '#submitNodes_0_host',
  23. nodes_0_port: '#submitNodes_0_port',
  24. nodes_0_weight: '#submitNodes_0_weight',
  25. upstreamSelector: '[data-cy=upstream_selector]',
  26. nameSelector: '[title=Name]',
  27. input: ':input',
  28. deleteAlert: '.ant-modal-body',
  29. notification: '.ant-notification-notice-message',
  30. };
  31. const data = {
  32. deleteRouteSuccess: 'Delete Route Successfully',
  33. submitSuccess: 'Submit Successfully',
  34. deleteUpstreamSuccess: 'Delete Upstream Successfully',
  35. host1: '11.11.11.11',
  36. port: '80',
  37. weight: 1,
  38. description: 'desc_by_autotest',
  39. upstreamName: 'test_upstream',
  40. routeName: 'test_route',
  41. ip1: '127.0.0.1',
  42. ip2: '127.0.0.2',
  43. FQDN: 'bigserver.mycompany.com',
  44. };
  45. beforeEach(() => {
  46. cy.login();
  47. });
  48. it('should create an upstream', function () {
  49. cy.visit('/');
  50. cy.contains('Upstream').click();
  51. cy.contains('Create').click();
  52. cy.get(selector.name).type(data.upstreamName);
  53. cy.get(selector.description).type(data.description);
  54. cy.get(selector.nodes_0_host).type(data.FQDN);
  55. cy.get('label[title="Port"]').then(($els) => {
  56. const win = $els[0].ownerDocument.defaultView;
  57. const before = win.getComputedStyle($els[0], 'before');
  58. const contentValue = before.getPropertyValue('content');
  59. expect(contentValue).to.eq('none');
  60. });
  61. cy.get(selector.nodes_0_port).clear();
  62. cy.get(selector.nodes_0_weight).type(data.weight);
  63. cy.contains('Next').click();
  64. cy.contains('Submit').click();
  65. });
  66. it('should create route with upstream just created', function () {
  67. cy.visit('/');
  68. cy.get('[role=menu]')
  69. .should('be.visible')
  70. .within(() => {
  71. cy.contains('Route').click();
  72. });
  73. cy.contains('Create').click();
  74. cy.contains('Next').click().click();
  75. cy.get(selector.name).type(data.routeName);
  76. cy.contains('Next').click();
  77. // should disable Upstream input boxes after selecting an existing upstream
  78. cy.get(selector.upstreamSelector).click();
  79. cy.contains(data.upstreamName).click();
  80. cy.get(selector.input).should('be.disabled');
  81. // should enable Upstream input boxes after selecting Custom mode
  82. cy.get(selector.upstreamSelector).click();
  83. cy.contains('.ant-select-item-option-content', 'Custom').click();
  84. cy.get(selector.nodes_0_host).should('have.value', data.FQDN).clear().type(data.ip1);
  85. cy.get(selector.nodes_0_port).should('have.value', '').type(data.port);
  86. cy.get(selector.nodes_0_weight).type(data.weight);
  87. cy.contains('Next').click();
  88. cy.contains('Next').click();
  89. cy.contains('Submit').click();
  90. cy.contains(data.submitSuccess).should('be.visible');
  91. cy.contains('Goto List').click();
  92. cy.url().should('contains', 'routes/list');
  93. });
  94. it('should edit this route with upstream', function () {
  95. cy.visit('/');
  96. cy.contains('Route').click();
  97. cy.get(selector.nameSelector).type(data.routeName);
  98. cy.contains('Search').click();
  99. cy.contains(data.routeName).siblings().contains('Configure').click();
  100. cy.get(selector.name).should('value', data.routeName);
  101. cy.contains('Next').click({
  102. force: true,
  103. });
  104. // check if the changes have been saved
  105. cy.get(selector.nodes_0_host).should('value', data.ip1);
  106. cy.get(selector.upstreamSelector).click();
  107. cy.contains(data.upstreamName).click();
  108. cy.get(selector.input).should('be.disabled');
  109. cy.contains(data.upstreamName).click();
  110. cy.contains('.ant-select-item-option-content', 'Custom').click();
  111. cy.get(selector.input).should('not.be.disabled');
  112. cy.get(selector.nodes_0_host).clear().type(data.ip2);
  113. cy.get(selector.nodes_0_port).type(data.port);
  114. cy.get(selector.nodes_0_weight).type(data.weight);
  115. cy.contains('Next').click();
  116. cy.contains('Next').click();
  117. cy.contains('Submit').click();
  118. cy.contains(data.submitSuccess).should('be.visible');
  119. cy.contains('Goto List').click();
  120. cy.url().should('contains', 'routes/list');
  121. // check if the changes have been saved
  122. cy.get(selector.nameSelector).type(data.routeName);
  123. cy.contains('Search').click();
  124. cy.contains(data.routeName).siblings().contains('Configure').click();
  125. // ensure it has already changed to edit page
  126. cy.get(selector.name).should('value', data.routeName);
  127. cy.contains('Next').click({
  128. force: true,
  129. });
  130. cy.get(selector.nodes_0_host).should('value', data.ip2);
  131. });
  132. it('should delete this test route and upstream', function () {
  133. cy.visit('/routes/list');
  134. cy.get(selector.nameSelector).type(data.routeName);
  135. cy.contains('Search').click();
  136. cy.contains(data.routeName).siblings().contains('More').click();
  137. cy.contains('Delete').click();
  138. cy.get(selector.deleteAlert)
  139. .should('be.visible')
  140. .within(() => {
  141. cy.contains('OK').click();
  142. });
  143. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  144. cy.visit('/');
  145. cy.contains('Upstream').click();
  146. cy.contains(data.upstreamName).siblings().contains('Delete').click();
  147. cy.contains('button', 'Confirm').click();
  148. cy.get(selector.notification).should('contain', data.deleteUpstreamSuccess);
  149. });
  150. });