create-consumer-with-api-breaker-plugin-form.cy.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 api-breaker plugin form', () => {
  19. const selector = {
  20. break_response_code: '#break_response_code',
  21. break_response_body: '#break_response_body',
  22. break_response_headers_0_key: '#break_response_headers_0_key',
  23. break_response_headers_0_value: '#break_response_headers_0_value',
  24. empty: '.ant-empty-normal',
  25. username: '#username',
  26. description: '#desc',
  27. pluginCard: '.ant-card',
  28. drawer: '.ant-drawer-content',
  29. disabledSwitcher: '#disable',
  30. notification: '.ant-notification-notice-message',
  31. monacoViewZones: '.view-zones',
  32. };
  33. const data = {
  34. break_response_code: 200,
  35. break_response_body: 'breaker opened',
  36. break_response_headers_0_key: 'Content-Type',
  37. break_response_headers_0_value: 'application/json',
  38. consumerName: 'test_consumer',
  39. description: 'desc_by_autotest',
  40. createConsumerSuccess: 'Create Consumer Successfully',
  41. deleteConsumerSuccess: 'Delete Consumer Successfully',
  42. };
  43. beforeEach(() => {
  44. cy.login();
  45. });
  46. it('creates consumer with api-breaker form', function () {
  47. cy.visit('/');
  48. cy.contains('Consumer').click();
  49. cy.get(selector.empty).should('be.visible');
  50. cy.contains('Create').click();
  51. // basic information
  52. cy.get(selector.username).type(data.consumerName);
  53. cy.get(selector.description).type(data.description);
  54. cy.contains('Next').click();
  55. // config auth plugin
  56. cy.contains(selector.pluginCard, 'key-auth').within(() => {
  57. cy.contains('Enable').click({
  58. force: true,
  59. });
  60. });
  61. cy.focused(selector.drawer).should('exist');
  62. cy.get(selector.monacoViewZones).should('exist');
  63. cy.get(selector.disabledSwitcher).click();
  64. // edit monaco
  65. cy.window().then((window) => {
  66. window.monacoEditor.setValue(JSON.stringify({ key: 'test' }));
  67. cy.contains('button', 'Submit').click();
  68. });
  69. cy.contains(selector.pluginCard, 'api-breaker').within(() => {
  70. cy.contains('Enable').click({
  71. force: true,
  72. });
  73. });
  74. cy.focused(selector.drawer).should('exist');
  75. // config api-breaker form
  76. cy.get(selector.drawer).within(() => {
  77. cy.contains('Submit').click({
  78. force: true,
  79. });
  80. });
  81. cy.get(selector.notification).should('contain', 'Invalid plugin data');
  82. cy.contains('.ant-form-item', 'break_response_headers').within(() => {
  83. cy.contains('button', 'Create').click();
  84. });
  85. cy.get(selector.break_response_code).type(data.break_response_code);
  86. cy.get(selector.break_response_body).type(data.break_response_body);
  87. cy.get(selector.break_response_headers_0_key).type(data.break_response_headers_0_key);
  88. cy.get(selector.break_response_headers_0_value).type(data.break_response_headers_0_value);
  89. cy.get(selector.disabledSwitcher).click();
  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.get(selector.notification).should('contain', data.createConsumerSuccess);
  99. });
  100. it('delete the consumer', function () {
  101. cy.visit('/consumer/list');
  102. cy.contains(data.consumerName).should('be.visible').siblings().contains('Delete').click();
  103. cy.contains('button', 'Confirm').click();
  104. cy.get(selector.notification).should('contain', data.deleteConsumerSuccess);
  105. });
  106. });