create-consumer-with-proxy-mirror-form.cy.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 proxy-mirror 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. notificationCloseIcon: '.ant-notification-close-icon',
  29. max_age: '#max_age',
  30. allow_origins_by_regex: '#allow_origins_by_regex_0',
  31. host: '#host',
  32. alert: '[role=alert]',
  33. monacoViewZones: '.view-zones',
  34. };
  35. const data = {
  36. consumerName: 'test_consumer',
  37. description: 'desc_by_autotest',
  38. createConsumerSuccess: 'Create Consumer Successfully',
  39. deleteConsumerSuccess: 'Delete Consumer Successfully',
  40. time: 2,
  41. };
  42. beforeEach(() => {
  43. cy.login();
  44. });
  45. it('should create consumer with proxy-mirror form', function () {
  46. cy.visit('/');
  47. cy.contains('Consumer').click();
  48. cy.get(selector.empty).should('be.visible');
  49. cy.contains('Create').click();
  50. // basic information
  51. cy.get(selector.username).type(data.consumerName);
  52. cy.get(selector.description).type(data.description);
  53. cy.contains('Next').click();
  54. // config auth plugin
  55. cy.contains(selector.pluginCard, 'key-auth').within(() => {
  56. cy.contains('Enable').click({
  57. force: true,
  58. });
  59. });
  60. cy.focused(selector.drawer).should('exist');
  61. cy.get(selector.monacoViewZones).should('exist');
  62. cy.get(selector.disabledSwitcher).click();
  63. // edit monaco
  64. cy.window().then((window) => {
  65. window.monacoEditor.setValue(JSON.stringify({ key: 'test' }));
  66. cy.contains('button', 'Submit').click();
  67. });
  68. cy.contains(selector.pluginCard, 'proxy-mirror').within(() => {
  69. cy.contains('Enable').click({
  70. force: true,
  71. });
  72. });
  73. cy.focused(selector.drawer).should('exist');
  74. // config proxy-mirror form with wrong host
  75. cy.get(selector.host).type('127.0.0.1:1999');
  76. cy.get(selector.alert).contains('address needs to contain schema: http or https, not URI part');
  77. cy.get(selector.drawer).within(() => {
  78. cy.contains('Submit').click({
  79. force: true,
  80. });
  81. });
  82. cy.get(selector.notification).should('contain', 'Invalid plugin data');
  83. cy.get(selector.notificationCloseIcon).click();
  84. // config proxy-mirror form with correct host
  85. cy.get(selector.host).clear().type('http://127.0.0.1:1999');
  86. cy.get(selector.alert).should('not.be.visible');
  87. cy.get(selector.disabledSwitcher).click();
  88. cy.get(selector.drawer).within(() => {
  89. cy.contains('Submit').click({
  90. force: true,
  91. });
  92. });
  93. cy.get(selector.drawer).should('not.exist');
  94. cy.contains('button', 'Next').click();
  95. cy.contains('button', 'Submit').click();
  96. cy.get(selector.notification).should('contain', data.createConsumerSuccess);
  97. });
  98. it('should delete the consumer', function () {
  99. cy.visit('/consumer/list');
  100. cy.contains(data.consumerName).should('be.visible').siblings().contains('Delete').click();
  101. cy.contains('button', 'Confirm').click();
  102. cy.get(selector.notification).should('contain', data.deleteConsumerSuccess);
  103. });
  104. });