create-route-with-limit-count-plugin-form.cy.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 limit-count form', () => {
  19. const selector = {
  20. empty: '.ant-empty-normal',
  21. name: '#name',
  22. description: '#desc',
  23. disabledSwitcher: '#disable',
  24. drawer: '.ant-drawer-content',
  25. nodes_0_host: '#submitNodes_0_host',
  26. nodes_0_port: '#submitNodes_0_port',
  27. nodes_0_weight: '#submitNodes_0_weight',
  28. deleteAlert: '.ant-modal-body',
  29. notificationCloseIcon: '.ant-notification-close-icon',
  30. notification: '.ant-notification-notice-message',
  31. pluginCard: '.ant-card',
  32. count: '#count',
  33. time_window: '#time_window',
  34. redis_timeout: '#time_window',
  35. key: '#key',
  36. rejected_code: '#rejected_code',
  37. rejected_msg: '#rejected_msg',
  38. policy: '#policy',
  39. group: '#group',
  40. redis_host: '#redis_host',
  41. redis_port: '#redis_port',
  42. redis_password: '#redis_password',
  43. redis_database: '#redis_database',
  44. redis_cluster_name: '#redis_cluster_name',
  45. redis_cluster_nodes_0: '#redis_cluster_nodes_0',
  46. redis_cluster_nodes_1: '#redis_cluster_nodes_1',
  47. dropdown: '.rc-virtual-list',
  48. };
  49. const data = {
  50. deleteRouteSuccess: 'Delete Route Successfully',
  51. submitSuccess: 'Submit Successfully',
  52. port: '80',
  53. weight: 1,
  54. rejected_msg: 'Requests are too frequent, please try again later.',
  55. redisClusterName: 'Please Enter redis_cluster_name',
  56. redisClusterNode: 'Please Enter redis_cluster_node',
  57. };
  58. beforeEach(() => {
  59. cy.login();
  60. });
  61. it('should create route with limit-count form', function () {
  62. cy.visit('/');
  63. cy.contains('Route').click();
  64. cy.get(selector.empty).should('be.visible');
  65. cy.contains('Create').click();
  66. cy.contains('Next').click().click();
  67. cy.get(selector.name).type('routeName');
  68. cy.get(selector.description).type('desc');
  69. cy.contains('Next').click();
  70. cy.get(selector.nodes_0_host).type('127.0.0.1');
  71. cy.get(selector.nodes_0_port).clear().type(data.port);
  72. cy.get(selector.nodes_0_weight).clear().type(data.weight);
  73. cy.contains('Next').click();
  74. // config limit-count form with local policy
  75. cy.contains(selector.pluginCard, 'limit-count').within(() => {
  76. cy.get('button').click({
  77. force: true,
  78. });
  79. });
  80. cy.focused(selector.drawer).should('exist');
  81. cy.get(selector.disabledSwitcher).click();
  82. cy.get(selector.count).type(1);
  83. cy.get(selector.time_window).type(1);
  84. cy.get(selector.rejected_code).type(500);
  85. cy.get(selector.rejected_msg).type(data.rejected_msg);
  86. cy.get(selector.group).type('test_group');
  87. cy.get(selector.drawer).within(() => {
  88. cy.contains('Submit').click({
  89. force: true,
  90. });
  91. });
  92. cy.get(selector.drawer).should('not.exist');
  93. // config limit-count form with redis policy
  94. cy.contains(selector.pluginCard, 'limit-count').within(() => {
  95. cy.get('button').click({
  96. force: true,
  97. });
  98. });
  99. cy.focused(selector.drawer).should('exist');
  100. cy.contains('local').click();
  101. cy.get(selector.dropdown).within(() => {
  102. cy.contains('redis').click({
  103. force: true,
  104. });
  105. });
  106. cy.get(selector.redis_host).type('127.0.0.1');
  107. cy.get(selector.redis_password).type('redis_password');
  108. cy.get(selector.drawer).within(() => {
  109. cy.contains('Submit').click({
  110. force: true,
  111. });
  112. });
  113. cy.get(selector.drawer).should('not.exist');
  114. // config limit-count form with redis-cluster policy
  115. cy.contains(selector.pluginCard, 'limit-count').within(() => {
  116. cy.get('button').click({
  117. force: true,
  118. });
  119. });
  120. cy.focused(selector.drawer).should('exist');
  121. cy.contains('redis').click();
  122. cy.get(selector.dropdown).within(() => {
  123. cy.contains('redis-cluster').click({
  124. force: true,
  125. });
  126. });
  127. cy.get(selector.redis_cluster_name).click();
  128. cy.contains(data.redisClusterName);
  129. cy.get(selector.redis_cluster_nodes_0).click();
  130. cy.contains(data.redisClusterNode);
  131. cy.get(selector.redis_cluster_name).type('redis_cluster_name');
  132. cy.get(selector.redis_cluster_nodes_0).type('127.0.0.1:5000');
  133. cy.get(selector.redis_cluster_nodes_1).type('127.0.0.1:5001');
  134. cy.get(selector.drawer).within(() => {
  135. cy.contains('Submit').click({
  136. force: true,
  137. });
  138. });
  139. cy.get(selector.drawer).should('not.exist');
  140. cy.contains('button', 'Next').click();
  141. cy.contains('button', 'Submit').click();
  142. cy.contains(data.submitSuccess);
  143. // back to route list page
  144. cy.contains('Goto List').click();
  145. cy.url().should('contains', 'routes/list');
  146. });
  147. it('should delete the route', function () {
  148. cy.visit('/routes/list');
  149. cy.get(selector.name).clear().type('routeName');
  150. cy.contains('Search').click();
  151. cy.contains('routeName').siblings().contains('More').click();
  152. cy.contains('Delete').click();
  153. cy.get(selector.deleteAlert)
  154. .should('be.visible')
  155. .within(() => {
  156. cy.contains('OK').click();
  157. });
  158. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  159. cy.get(selector.notificationCloseIcon).click();
  160. });
  161. });