create-route-with-api-breaker-form.cy.js 4.2 KB

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