batch-delete-route.cy.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. context('Create and Batch Deletion Routes', () => {
  18. const timeout = 5000;
  19. const selector = {
  20. name: '#name',
  21. description: '#desc',
  22. hosts_0: '#hosts_0',
  23. uris_0: '#uris_0',
  24. labels_0_labelKey: '#labels_0_labelKey',
  25. labels_0_labelValue: '#labels_0_labelValue',
  26. nodes_0_host: '#submitNodes_0_host',
  27. nodes_0_port: '#submitNodes_0_port',
  28. nodes_0_weight: '#submitNodes_0_weight',
  29. nameSearchInput: '#name',
  30. pathSearchInput: '#uri',
  31. drawerBody: '.ant-drawer-wrapper-body',
  32. notification: '.ant-notification-notice-message',
  33. notificationClose: '.anticon-close',
  34. };
  35. const data = {
  36. host1: '11.11.11.11',
  37. host2: '12.12.12.12',
  38. port: '80',
  39. weight: 1,
  40. submitSuccess: 'Submit Successfully',
  41. deleteRouteSuccess: 'Delete Route Successfully',
  42. value0: 'value0',
  43. label0_value0: 'label0:value0',
  44. };
  45. before(() => {
  46. cy.clearLocalStorageSnapshot();
  47. cy.login();
  48. cy.saveLocalStorage();
  49. });
  50. beforeEach(() => {
  51. cy.restoreLocalStorage();
  52. cy.visit('/');
  53. });
  54. it('should successfully create 3 routes', function () {
  55. cy.get('#root > div > section > aside > div ul', { timeout }).contains('Route').click();
  56. for (let i = 0; i < 3; i += 1) {
  57. cy.wait(timeout);
  58. cy.get('.ant-pro-table-list-toolbar-right').contains('Create').click();
  59. cy.get('.ant-row').contains('Next').click().click();
  60. cy.get(selector.name).type(`test${i}`);
  61. cy.get(selector.description).type(`desc${i}`);
  62. cy.get(selector.hosts_0).type(data.host1);
  63. cy.get(selector.uris_0).clear().type(`/get${i}`);
  64. // config label
  65. cy.contains('Manage').click();
  66. // eslint-disable-next-line @typescript-eslint/no-loop-func
  67. cy.get(selector.drawerBody).within(($drawer) => {
  68. cy.wrap($drawer)
  69. .contains('button', 'Add')
  70. .should('not.be.disabled')
  71. .click()
  72. .then(() => {
  73. cy.get(selector.labels_0_labelKey).type(`label${i}`);
  74. cy.get(selector.labels_0_labelValue).type(`value${i}`);
  75. cy.contains('Confirm').click();
  76. });
  77. });
  78. cy.contains('button', 'Next').should('not.be.disabled').click();
  79. cy.get(selector.nodes_0_host).type(data.host2, {
  80. timeout,
  81. });
  82. cy.get(selector.nodes_0_port).type(data.port);
  83. cy.get(selector.nodes_0_weight).type(data.weight);
  84. cy.get('.ant-row').contains('Next').click();
  85. cy.get('.ant-row').contains('Next').click();
  86. cy.get('.ant-row').contains('Submit').click();
  87. cy.contains(data.submitSuccess);
  88. cy.contains('Goto List').click();
  89. cy.url().should('contains', 'routes/list');
  90. }
  91. });
  92. it('should delete the route', function () {
  93. cy.visit('/routes/list');
  94. cy.wrap([0, 2]).each(($n) => {
  95. cy.contains(`test${$n}`).get('[type="checkbox"]').check();
  96. });
  97. cy.contains('BatchDeletion Routes').should('be.visible').click({ timeout });
  98. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  99. cy.get(selector.notificationClose).should('be.visible').click({
  100. force: true,
  101. multiple: true,
  102. });
  103. });
  104. it('should batch delete the name of the route', function () {
  105. cy.contains('Route').click();
  106. const cases = [
  107. [1, 0, 2], // full match
  108. [0, 1, 2], // partial match
  109. [0, 1, 2], // none match
  110. ];
  111. const prefix = 'test';
  112. cy.wrap([0, 2, 'x']).each(($n, i) => {
  113. cy.get(selector.nameSearchInput).clear().type(`${prefix}${$n}`);
  114. cy.contains('Search').click();
  115. // eslint-disable-next-line @typescript-eslint/no-shadow
  116. cy.wrap(cases[i]).each(($n) => {
  117. cy.contains(`${prefix}${$n}`).should('not.exist');
  118. });
  119. });
  120. });
  121. it('should batch delete the path of the route', function () {
  122. cy.contains('Route').click();
  123. const cases = [
  124. [1, 0, 2], // full match
  125. [0, 1, 2], // partial match
  126. [0, 1, 2], // none match
  127. ];
  128. const prefix = '/get';
  129. cy.wrap([0, 2, 'x']).each(($n, i) => {
  130. cy.get(selector.nameSearchInput).clear().type(`${prefix}${$n}`);
  131. cy.contains('Search').click();
  132. // eslint-disable-next-line @typescript-eslint/no-shadow
  133. cy.wrap(cases[i]).each(($n) => {
  134. cy.contains(`${prefix}${$n}`).should('not.exist');
  135. });
  136. });
  137. });
  138. });