create-consumer-with-limit-count-plugin-form.cy.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 consumer with limit-count plugin form', () => {
  19. const selector = {
  20. empty: '.ant-empty-normal',
  21. username: '#username',
  22. description: '#desc',
  23. pluginCard: '.ant-card',
  24. drawer: '.ant-drawer-content',
  25. dropdown: '.rc-virtual-list',
  26. disabledSwitcher: '#disable',
  27. notification: '.ant-notification-notice-message',
  28. count: '#count',
  29. time_window: '#time_window',
  30. key: '#key',
  31. rejected_code: '#rejected_code',
  32. policy: '#policy',
  33. redis_host: '#redis_host',
  34. redis_port: '#redis_port',
  35. redis_password: '#redis_password',
  36. redis_database: '#redis_database',
  37. redis_cluster_name: '#redis_cluster_name',
  38. redis_cluster_nodes_0: '#redis_cluster_nodes_0',
  39. redis_cluster_nodes_1: '#redis_cluster_nodes_1',
  40. monacoViewZones: '.view-zones',
  41. };
  42. const data = {
  43. consumerName: 'test_consumer',
  44. description: 'desc_by_autotest',
  45. createConsumerSuccess: 'Create Consumer Successfully',
  46. deleteConsumerSuccess: 'Delete Consumer Successfully',
  47. redisClusterName: 'Please Enter redis_cluster_name',
  48. redisClusterNode: 'Please Enter redis_cluster_node',
  49. };
  50. beforeEach(() => {
  51. cy.login();
  52. });
  53. it('should create consumer with limit-count form', function () {
  54. cy.visit('/');
  55. cy.contains('Consumer').click();
  56. cy.get(selector.empty).should('be.visible');
  57. cy.contains('Create').click();
  58. // basic information
  59. cy.get(selector.username).type(data.consumerName);
  60. cy.get(selector.description).type(data.description);
  61. cy.contains('Next').click();
  62. // config auth plugin
  63. cy.contains(selector.pluginCard, 'key-auth').within(() => {
  64. cy.contains('Enable').click({
  65. force: true,
  66. });
  67. });
  68. cy.focused(selector.drawer).should('exist');
  69. cy.get(selector.monacoViewZones).should('exist');
  70. cy.get(selector.disabledSwitcher).click();
  71. // edit monaco
  72. cy.window().then((window) => {
  73. window.monacoEditor.setValue(JSON.stringify({ key: 'test' }));
  74. cy.contains('button', 'Submit').click();
  75. });
  76. cy.contains(selector.pluginCard, 'limit-count').within(() => {
  77. cy.contains('Enable').click({
  78. force: true,
  79. });
  80. });
  81. cy.focused(selector.drawer).should('exist');
  82. // config limit-count form with local policy
  83. cy.get(selector.count).type(1);
  84. cy.get(selector.time_window).type(1);
  85. cy.get(selector.rejected_code).type(500);
  86. cy.get(selector.drawer).within(() => {
  87. cy.contains('Submit').click({
  88. force: true,
  89. });
  90. });
  91. cy.get(selector.drawer).should('not.exist');
  92. // config limit-count form with redis policy
  93. cy.contains(selector.pluginCard, 'limit-count').within(() => {
  94. cy.contains('Enable').click({
  95. force: true,
  96. });
  97. });
  98. cy.focused(selector.drawer).should('exist');
  99. cy.contains('local').click();
  100. cy.get(selector.dropdown).within(() => {
  101. cy.contains('redis').click({
  102. force: true,
  103. });
  104. });
  105. cy.get(selector.redis_host).type('127.0.0.1');
  106. cy.get(selector.redis_password).type('redis_password');
  107. cy.get(selector.drawer).within(() => {
  108. cy.contains('Submit').click({
  109. force: true,
  110. });
  111. });
  112. cy.get(selector.drawer).should('not.exist');
  113. // config limit-count form with redis-cluster policy
  114. cy.contains(selector.pluginCard, 'limit-count').within(() => {
  115. cy.contains('Enable').click({
  116. force: true,
  117. });
  118. });
  119. cy.focused(selector.drawer).should('exist');
  120. cy.contains('redis').click();
  121. cy.get(selector.dropdown).within(() => {
  122. cy.contains('redis-cluster').click({
  123. force: true,
  124. });
  125. });
  126. cy.get(selector.redis_cluster_name).click();
  127. cy.contains(data.redisClusterName);
  128. cy.get(selector.redis_cluster_nodes_0).click();
  129. cy.contains(data.redisClusterNode);
  130. cy.get(selector.redis_cluster_name).type('redis_cluster_name');
  131. cy.get(selector.redis_cluster_nodes_0).type('127.0.0.1:5000');
  132. cy.get(selector.redis_cluster_nodes_1).type('127.0.0.1:5001');
  133. cy.get(selector.drawer).within(() => {
  134. cy.contains('Submit').click({
  135. force: true,
  136. });
  137. });
  138. cy.get(selector.drawer).should('not.exist');
  139. cy.contains('button', 'Next').click();
  140. cy.contains('button', 'Submit').click();
  141. cy.get(selector.notification).should('contain', data.createConsumerSuccess);
  142. });
  143. it('should delete the consumer', function () {
  144. cy.visit('/consumer/list');
  145. cy.contains(data.consumerName).should('be.visible').siblings().contains('Delete').click();
  146. cy.contains('button', 'Confirm').click();
  147. cy.get(selector.notification).should('contain', data.deleteConsumerSuccess);
  148. });
  149. });