create-route-with-proxy-mirror-form.cy.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 route with proxy-mirror form', () => {
  19. const selector = {
  20. empty: '.ant-empty-normal',
  21. name: '#name',
  22. description: '#desc',
  23. disabledSwitcher: '#disable',
  24. drawer: '.ant-drawer-content',
  25. pluginCardBordered: '.ant-card-bordered',
  26. checkedSwitcher: '.ant-switch-checked',
  27. nodes_0_host: '#submitNodes_0_host',
  28. nodes_0_port: '#submitNodes_0_port',
  29. nodes_0_weight: '#submitNodes_0_weight',
  30. deleteAlert: '.ant-modal-body',
  31. notificationCloseIcon: '.ant-notification-close-icon',
  32. notification: '.ant-notification-notice-message',
  33. host: '#host',
  34. alert: '.ant-form-item-explain',
  35. };
  36. const data = {
  37. deleteRouteSuccess: 'Delete Route Successfully',
  38. submitSuccess: 'Submit Successfully',
  39. port: '80',
  40. weight: 1,
  41. };
  42. before(() => {
  43. cy.clearLocalStorageSnapshot();
  44. cy.login();
  45. cy.saveLocalStorage();
  46. });
  47. beforeEach(() => {
  48. cy.restoreLocalStorage();
  49. });
  50. it('should create route with proxy-mirror form', function () {
  51. cy.visit('/');
  52. cy.contains('Route').click();
  53. cy.wait(2000);
  54. cy.get(selector.empty).should('be.visible');
  55. cy.contains('Create').click();
  56. cy.contains('Next').click().click();
  57. cy.get(selector.name).type('routeName');
  58. cy.get(selector.description).type('desc');
  59. cy.contains('Next').click();
  60. cy.get(selector.nodes_0_host).type('127.0.0.1');
  61. cy.get(selector.nodes_0_port).clear().type(data.port);
  62. cy.get(selector.nodes_0_weight).clear().type(data.weight);
  63. cy.contains('Next').click();
  64. // config proxy-mirror plugin
  65. cy.contains('proxy-mirror')
  66. .parents(selector.pluginCardBordered)
  67. .within(() => {
  68. cy.get('button').click({
  69. force: true,
  70. });
  71. });
  72. cy.wait(2000);
  73. cy.get(selector.drawer)
  74. .should('be.visible')
  75. .within(() => {
  76. cy.get(selector.disabledSwitcher).focus().click();
  77. cy.get(selector.checkedSwitcher).should('exist');
  78. });
  79. // config proxy-mirror form with wrong host
  80. cy.get(selector.host).type('127.0.0.1:1999');
  81. cy.get(selector.alert).contains('address needs to contain schema: http or https, not URI part');
  82. cy.get(selector.drawer).within(() => {
  83. cy.contains('Submit').click({
  84. force: true,
  85. });
  86. });
  87. cy.get(selector.notification).should('contain', 'Invalid plugin data');
  88. cy.get(selector.notificationCloseIcon).click();
  89. // config proxy-mirror form with correct host
  90. cy.get(selector.host).clear().type('http://127.0.0.1:1999');
  91. cy.get(selector.alert).should('not.exist');
  92. cy.get(selector.disabledSwitcher).click();
  93. cy.get(selector.drawer).within(() => {
  94. cy.contains('Submit').click({
  95. force: true,
  96. });
  97. });
  98. cy.get(selector.drawer).should('not.exist');
  99. cy.contains('button', 'Next').click();
  100. cy.contains('button', 'Submit').click();
  101. cy.contains(data.submitSuccess);
  102. // back to route list page
  103. cy.contains('Goto List').click();
  104. cy.url().should('contains', 'routes/list');
  105. });
  106. it('should delete the route', function () {
  107. cy.visit('/routes/list');
  108. cy.get(selector.name).clear().type('routeName');
  109. cy.contains('Search').click();
  110. cy.contains('routeName').siblings().contains('More').click();
  111. cy.contains('Delete').click();
  112. cy.get(selector.deleteAlert)
  113. .should('be.visible')
  114. .within(() => {
  115. cy.contains('OK').click();
  116. });
  117. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  118. cy.get(selector.notificationCloseIcon).click({ multiple: true });
  119. });
  120. });