create-route-with-cors-form.cy.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 and delete route with cors form', () => {
  19. const selector = {
  20. empty: '.ant-empty-normal',
  21. name: '#name',
  22. description: '#desc',
  23. pluginCardBordered: '.ant-card-bordered',
  24. disabledSwitcher: '#disable',
  25. checkedSwitcher: '.ant-switch-checked',
  26. drawer: '.ant-drawer-content',
  27. nodes_0_host: '#submitNodes_0_host',
  28. nodes_0_port: '#submitNodes_0_port',
  29. nodes_0_weight: '#submitNodes_0_weight',
  30. deleteAlert: '.ant-modal-body',
  31. notificationCloseIcon: '.ant-notification-close-icon',
  32. notification: '.ant-notification-notice-message',
  33. allow_credential: '#allow_credential',
  34. allow_origins_by_regex0: '#allow_origins_by_regex_0',
  35. allow_origins_by_regex1: '#allow_origins_by_regex_1',
  36. addButton: '[data-cy=add-allow_origins_by_regex]',
  37. };
  38. const data = {
  39. deleteRouteSuccess: 'Delete Route Successfully',
  40. submitSuccess: 'Submit Successfully',
  41. port: '80',
  42. weight: 1,
  43. };
  44. before(() => {
  45. cy.clearLocalStorageSnapshot();
  46. cy.login();
  47. cy.saveLocalStorage();
  48. });
  49. beforeEach(() => {
  50. cy.restoreLocalStorage();
  51. });
  52. it('should create route with cors form', function () {
  53. cy.visit('/');
  54. cy.contains('Route').click();
  55. cy.get(selector.empty).should('be.visible');
  56. cy.contains('Create').click();
  57. cy.contains('Next').click().click();
  58. cy.get(selector.name).type('routeName');
  59. cy.get(selector.description).type('desc');
  60. cy.contains('Next').click();
  61. cy.get(selector.nodes_0_host).type('127.0.0.1');
  62. cy.get(selector.nodes_0_port).clear().type(data.port);
  63. cy.get(selector.nodes_0_weight).clear().type(data.weight);
  64. cy.contains('Next').click();
  65. // config cors plugin
  66. cy.contains('cors')
  67. .parents(selector.pluginCardBordered)
  68. .within(() => {
  69. cy.get('button').click({
  70. force: true,
  71. });
  72. });
  73. cy.get(selector.drawer)
  74. .should('be.visible')
  75. .within(() => {
  76. cy.get(selector.disabledSwitcher).click();
  77. cy.get(selector.checkedSwitcher).should('exist');
  78. });
  79. // config cors form
  80. cy.get(selector.allow_credential).click();
  81. cy.get(selector.allow_origins_by_regex0).type('.*.test.com');
  82. // add allow_origins_by_regex, assert new input and minus icons exist
  83. cy.get(selector.addButton).click();
  84. cy.get(selector.allow_origins_by_regex1).should('exist');
  85. cy.get(selector.allow_origins_by_regex0).next().should('have.class', 'anticon-minus-circle');
  86. cy.get(selector.allow_origins_by_regex1)
  87. .type('foo.com')
  88. .next()
  89. .should('have.class', 'anticon-minus-circle');
  90. cy.get(selector.drawer).within(() => {
  91. cy.contains('Submit').click({
  92. force: true,
  93. });
  94. });
  95. cy.get(selector.drawer).should('not.exist');
  96. cy.contains('button', 'Next').click();
  97. cy.contains('button', 'Submit').click();
  98. cy.contains(data.submitSuccess);
  99. // back to route list page
  100. cy.contains('Goto List').click();
  101. cy.url().should('contains', 'routes/list');
  102. });
  103. it('should edit route with cors form no allow_origins_by_regex configured', function () {
  104. cy.visit('/');
  105. cy.contains('Route').click();
  106. cy.get(selector.name).clear().type('routeName');
  107. cy.contains('Search').click();
  108. cy.contains('routeName').siblings().contains('Configure').click();
  109. cy.get(selector.name).should('have.value', 'routeName');
  110. cy.contains('Next').click();
  111. cy.wait(2000);
  112. cy.contains('Next').click();
  113. cy.wait(2000);
  114. // config cors plugin
  115. cy.contains('cors')
  116. .parents(selector.pluginCardBordered)
  117. .within(() => {
  118. cy.get('button').click({
  119. force: true,
  120. });
  121. });
  122. cy.get(selector.drawer)
  123. .should('be.visible')
  124. .within(() => {
  125. cy.get(selector.disabledSwitcher).click();
  126. cy.get(selector.checkedSwitcher).should('exist');
  127. });
  128. // edit allow_origins_by_regex ''
  129. cy.get(selector.allow_origins_by_regex0).clear();
  130. cy.get(selector.allow_origins_by_regex1).next().click();
  131. cy.get(selector.drawer).within(() => {
  132. cy.contains('Submit').click({
  133. force: true,
  134. });
  135. });
  136. cy.get(selector.drawer).should('not.exist');
  137. cy.contains('button', 'Next').click();
  138. cy.contains('button', 'Submit').click();
  139. cy.contains(data.submitSuccess);
  140. // back to route list page
  141. cy.contains('Goto List').click();
  142. cy.url().should('contains', 'routes/list');
  143. });
  144. it('should delete the route', function () {
  145. cy.visit('/routes/list');
  146. cy.get(selector.name).clear().type('routeName');
  147. cy.contains('Search').click();
  148. cy.contains('routeName').siblings().contains('More').click();
  149. cy.contains('Delete').click();
  150. cy.get(selector.deleteAlert)
  151. .should('be.visible')
  152. .within(() => {
  153. cy.contains('OK').click();
  154. });
  155. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  156. cy.get(selector.notificationCloseIcon).click({ multiple: true });
  157. });
  158. });