create-upstream-with-cors-form.cy.js 3.9 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', () => {
  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. rate: '#rate',
  30. burst: '#burst',
  31. key: '#key',
  32. remote_addr: '[title=remote_addr]',
  33. max_age: '#max_age',
  34. allow_origins_by_regex: '#allow_origins_by_regex_0',
  35. monacoViewZones: '.view-zones',
  36. };
  37. const data = {
  38. consumerName: 'test_consumer',
  39. description: 'desc_by_autotest',
  40. createConsumerSuccess: 'Create Consumer Successfully',
  41. deleteConsumerSuccess: 'Delete Consumer Successfully',
  42. time: 2,
  43. };
  44. beforeEach(() => {
  45. cy.login();
  46. });
  47. it('creates consumer with cors form', function () {
  48. cy.visit('/');
  49. cy.contains('Consumer').click();
  50. cy.get(selector.empty).should('be.visible');
  51. cy.contains('Create').click();
  52. // basic information
  53. cy.get(selector.username).type(data.consumerName);
  54. cy.get(selector.description).type(data.description);
  55. cy.contains('Next').click();
  56. // config auth plugin
  57. cy.contains(selector.pluginCard, 'key-auth').within(() => {
  58. cy.contains('Enable').click({
  59. force: true,
  60. });
  61. });
  62. cy.focused(selector.drawer).should('exist');
  63. cy.get(selector.monacoViewZones).should('exist');
  64. cy.get(selector.disabledSwitcher).click().should('have.class', 'ant-switch-checked');
  65. // edit monaco
  66. cy.window().then((window) => {
  67. window.monacoEditor.setValue(JSON.stringify({ key: 'test' }));
  68. cy.contains('button', 'Submit').click();
  69. });
  70. cy.contains(selector.pluginCard, 'cors').within(() => {
  71. cy.contains('Enable').click({
  72. force: true,
  73. });
  74. });
  75. cy.get(selector.drawer).should('be.visible');
  76. cy.get(selector.max_age).clear();
  77. // config cors form
  78. cy.get(selector.drawer).within(() => {
  79. cy.contains('Submit').click({
  80. force: true,
  81. });
  82. });
  83. cy.get(selector.notification).should('contain', 'Invalid plugin data');
  84. cy.get(selector.notificationCloseIcon).click().should('not.exist');
  85. cy.get(selector.max_age).type(data.time);
  86. cy.get(selector.allow_origins_by_regex).type('.*.test.com');
  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. cy.contains('button', 'Next').click();
  94. cy.contains('button', 'Submit').click();
  95. cy.get(selector.notification).should('contain', data.createConsumerSuccess);
  96. cy.get(selector.notificationCloseIcon).click().should('not.exist');
  97. });
  98. it('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. });