create_and_delete_consumer.cy.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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', () => {
  19. const selector = {
  20. empty: '.ant-empty-normal',
  21. username: '#username',
  22. description: '#desc',
  23. pluginCard: '.ant-card',
  24. drawer: '.ant-drawer-content',
  25. disabledSwitcher: '#disable',
  26. notification: '.ant-notification-notice-message',
  27. nameSelector: '[title=Name]',
  28. serviceSelector: '[title=test_service]',
  29. monacoScroll: '.monaco-scrollable-element',
  30. monacoViewZones: '.view-zones',
  31. notificationCloseIcon: '.ant-notification-close-icon',
  32. };
  33. const data = {
  34. consumerName: 'test_consumer',
  35. noPluginsConsumerName: 'no_plugins_consumer',
  36. description: 'desc_by_autotest',
  37. createConsumerSuccess: 'Create Consumer Successfully',
  38. deleteConsumerSuccess: 'Delete Consumer Successfully',
  39. editConsumerSuccess: 'Edit Consumer Successfully',
  40. pluginErrorAlert: 'Invalid plugin data',
  41. };
  42. beforeEach(() => {
  43. cy.login();
  44. cy.fixture('selector.json').as('domSelector');
  45. cy.fixture('data.json').as('data');
  46. });
  47. it('creates consumer without plugins', function () {
  48. cy.visit('/consumer/list');
  49. cy.contains('Create').click();
  50. // basic information
  51. cy.get(selector.username).type(data.noPluginsConsumerName);
  52. cy.get(selector.description).type(data.description);
  53. cy.contains('Next').click();
  54. cy.contains('button', 'Next').click();
  55. cy.contains('button', 'Submit').click();
  56. cy.get(selector.notification).should('contain', data.createConsumerSuccess);
  57. // should configure the comsumer
  58. cy.contains(data.noPluginsConsumerName)
  59. .should('be.visible')
  60. .siblings()
  61. .contains('Configure')
  62. .click();
  63. cy.url().should('contain', `/${data.noPluginsConsumerName}/edit`);
  64. cy.get('#username').should('have.value', data.noPluginsConsumerName);
  65. cy.get('#desc').should('have.value', data.description);
  66. cy.contains('button', 'Next').click();
  67. cy.get('[data-cy-plugin-name="basic-auth"]').should('be.visible');
  68. cy.contains('button', 'Next').click();
  69. cy.contains('button', 'Submit').click();
  70. cy.get(selector.notification).should('contain', data.editConsumerSuccess);
  71. cy.contains(data.noPluginsConsumerName)
  72. .should('be.visible')
  73. .siblings()
  74. .contains('Delete')
  75. .click();
  76. cy.contains('button', 'Confirm').click();
  77. cy.get(selector.notification).should('contain', data.deleteConsumerSuccess);
  78. });
  79. it('creates consumer with key-auth', function () {
  80. cy.visit('/');
  81. cy.contains('Consumer').click();
  82. cy.get(selector.empty).should('be.visible');
  83. cy.contains('Create').click();
  84. // basic information
  85. cy.get(selector.username).type(data.consumerName);
  86. cy.get(selector.description).type(data.description);
  87. cy.contains('Next').click();
  88. // plugin config
  89. cy.contains(selector.pluginCard, 'key-auth').within(() => {
  90. cy.contains('Enable').click({
  91. force: true,
  92. });
  93. });
  94. cy.focused(selector.drawer).should('exist');
  95. cy.get(selector.disabledSwitcher).click();
  96. // edit monaco
  97. cy.get(selector.monacoViewZones).should('exist').click({
  98. force: true,
  99. });
  100. cy.window().then((window) => {
  101. window.monacoEditor.setValue(
  102. JSON.stringify({
  103. key: 'test',
  104. }),
  105. );
  106. cy.contains('button', 'Submit').click();
  107. });
  108. cy.contains('button', 'Next').click();
  109. cy.contains('button', 'Submit').click();
  110. cy.get(selector.notification).should('contain', data.createConsumerSuccess);
  111. });
  112. it('should view the consumer', function () {
  113. cy.visit('/consumer/list');
  114. cy.get(selector.nameSelector).type(data.consumerName);
  115. cy.contains('Search').click();
  116. cy.contains('key-auth').should('be.visible');
  117. cy.contains(data.consumerName).siblings().contains('View').click();
  118. cy.get(selector.drawer).should('be.visible');
  119. cy.get(selector.monacoScroll).within(() => {
  120. cy.contains('plugins').should('exist');
  121. cy.contains(data.consumerName).should('exist');
  122. });
  123. });
  124. it('delete the consumer', function () {
  125. cy.visit('/consumer/list');
  126. cy.contains(data.consumerName).should('be.visible').siblings().contains('Delete').click();
  127. cy.contains('button', 'Confirm').click();
  128. cy.get(selector.notification).should('contain', data.deleteConsumerSuccess);
  129. });
  130. it('creates consumer with wrong json', function () {
  131. cy.visit('/consumer/list');
  132. cy.contains('Create').click();
  133. // basic information
  134. cy.get(selector.username).type(data.consumerName);
  135. cy.get(selector.description).type(data.description);
  136. cy.contains('Next').click();
  137. // plugin config
  138. cy.contains(selector.pluginCard, 'key-auth').within(() => {
  139. cy.get('button').click({
  140. force: true,
  141. });
  142. });
  143. // edit monaco
  144. cy.get(selector.monacoViewZones).should('exist').click({
  145. force: true,
  146. });
  147. cy.window().then((window) => {
  148. window.monacoEditor.setValue(
  149. JSON.stringify({
  150. key_not_exist: 'test',
  151. }),
  152. );
  153. cy.contains('button', 'Submit').click();
  154. });
  155. cy.get(selector.notification).should('contain', data.pluginErrorAlert);
  156. });
  157. });