data-loader-import.cy.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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('Data Loader import', () => {
  18. const selector = {
  19. drawer: '.ant-drawer-content',
  20. selectDropdown: '.ant-select-dropdown',
  21. listTbody: '.ant-table-tbody',
  22. listRow: 'tr.ant-table-row-level-0',
  23. refresh: '.anticon-reload',
  24. notification: '.ant-notification-notice-message',
  25. notificationCloseIcon: '.ant-notification-notice-close',
  26. fileSelector: '[type=file]',
  27. notificationDesc: '.ant-notification-notice-description',
  28. task_name: '#task_name',
  29. merge_method: '#merge_method',
  30. };
  31. const data = {
  32. importRouteSuccess: 'Import Successfully',
  33. deleteRouteSuccess: 'Delete Route Successfully',
  34. deleteUpstreamSuccess: 'Delete Upstream Successfully',
  35. };
  36. const cases = {
  37. API101: '../../../api/test/testdata/import/Postman-API101.yaml',
  38. };
  39. before(() => {
  40. cy.clearLocalStorageSnapshot();
  41. cy.login();
  42. cy.saveLocalStorage();
  43. });
  44. beforeEach(() => {
  45. cy.restoreLocalStorage();
  46. cy.visit('/');
  47. cy.contains('Route').click();
  48. cy.get(selector.refresh).click();
  49. });
  50. it('should import API101 with merge mode', () => {
  51. cy.get('.ant-pro-page-container').within(() => {
  52. cy.wait(1000);
  53. cy.contains('Advanced').click();
  54. });
  55. cy.contains('Import').should('be.visible').click();
  56. // select Data Loader type
  57. cy.contains('OpenAPI 3').should('be.visible').click();
  58. cy.get(selector.selectDropdown).contains('OpenAPI 3').should('be.visible').click();
  59. cy.get(selector.drawer).get(selector.task_name).type('api101_mm');
  60. cy.get(selector.fileSelector).attachFile(cases.API101);
  61. cy.get(selector.drawer).contains('Submit').click();
  62. cy.get(selector.drawer).contains('Import Successfully').should('be.visible');
  63. cy.get(selector.drawer).contains('Total 3 route imported, 0 failed').click();
  64. cy.get(selector.drawer).contains('Close').click();
  65. cy.get(selector.drawer).should('not.exist');
  66. // check result
  67. cy.get(selector.listTbody).get(selector.listRow).should('have.length', 3);
  68. cy.contains('api101_mm_customer').should('be.visible');
  69. cy.contains('api101_mm_customer/{customer_id}').should('be.visible');
  70. cy.contains('api101_mm_customers').should('be.visible');
  71. // remove route
  72. for (let i = 0; i < 3; i += 1) {
  73. cy.get(selector.listTbody).get(selector.listRow).contains('More').click();
  74. cy.contains('Delete').should('be.visible').click();
  75. cy.contains('OK').should('be.visible').click();
  76. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  77. cy.get(selector.notificationCloseIcon).click();
  78. }
  79. });
  80. it('should import API101 with duplicate upstream', () => {
  81. cy.get('.ant-pro-page-container').within(() => {
  82. cy.wait(1000);
  83. cy.contains('Advanced').click();
  84. });
  85. cy.contains('Import').should('be.visible').click();
  86. // select Data Loader type
  87. cy.contains('OpenAPI 3').should('be.visible').click();
  88. cy.get(selector.selectDropdown).contains('OpenAPI 3').should('be.visible').click();
  89. cy.get(selector.drawer).get(selector.task_name).type('api101_mm');
  90. cy.get(selector.fileSelector).attachFile(cases.API101);
  91. cy.get(selector.drawer).contains('Submit').click();
  92. cy.get(selector.drawer).contains('Import Failed').should('be.visible');
  93. cy.get(selector.drawer).contains('Total 1 upstream imported, 1 failed').click();
  94. cy.get(selector.drawer).contains('key: api101_mm is conflicted').should('be.visible');
  95. cy.get(selector.drawer).contains('Close').click();
  96. cy.get(selector.drawer).should('not.exist');
  97. // remove route
  98. for (let i = 0; i < 3; i += 1) {
  99. cy.get(selector.listTbody).get(selector.listRow).contains('More').click();
  100. cy.contains('Delete').should('be.visible').click();
  101. cy.contains('OK').should('be.visible').click();
  102. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  103. cy.get(selector.notificationCloseIcon).click();
  104. }
  105. });
  106. it('should import API101 with non-merge mode', () => {
  107. cy.get('.ant-pro-page-container').within(() => {
  108. cy.wait(1000);
  109. cy.contains('Advanced').click();
  110. });
  111. cy.contains('Import').should('be.visible').click();
  112. // select Data Loader type
  113. cy.contains('OpenAPI 3').should('be.visible').click();
  114. cy.get(selector.selectDropdown).contains('OpenAPI 3').should('be.visible').click();
  115. cy.get(selector.drawer).get(selector.task_name).type('api101_nmm');
  116. cy.get(selector.drawer).get(selector.merge_method).click();
  117. cy.get(selector.fileSelector).attachFile(cases.API101);
  118. cy.get(selector.drawer).contains('Submit').click();
  119. cy.get(selector.drawer).contains('Import Successfully').should('be.visible');
  120. cy.get(selector.drawer).contains('Total 5 route imported, 0 failed').click();
  121. cy.get(selector.drawer).contains('Close').click();
  122. cy.get(selector.drawer).should('not.exist');
  123. // check result
  124. cy.get(selector.listTbody).get(selector.listRow).should('have.length', 5);
  125. });
  126. it('should import API101 with duplicate route', () => {
  127. cy.get('.ant-pro-page-container').within(() => {
  128. cy.wait(1000);
  129. cy.contains('Advanced').click();
  130. });
  131. cy.contains('Import').should('be.visible').click();
  132. // select Data Loader type
  133. cy.contains('OpenAPI 3').should('be.visible').click();
  134. cy.get(selector.selectDropdown).contains('OpenAPI 3').should('be.visible').click();
  135. cy.get(selector.drawer).get(selector.task_name).type('api101_nmm');
  136. cy.get(selector.drawer).get(selector.merge_method).click();
  137. cy.get(selector.fileSelector).attachFile(cases.API101);
  138. cy.get(selector.drawer).contains('Submit').click();
  139. cy.get(selector.drawer).contains('Import Failed').should('be.visible');
  140. cy.get(selector.drawer).contains('Total 5 route imported, 1 failed').click();
  141. cy.get(selector.drawer).contains('is duplicated with route api101_nmm_').should('be.visible');
  142. cy.get(selector.drawer).contains('Close').click();
  143. cy.get(selector.drawer).should('not.exist');
  144. });
  145. it('should remove all routes and upstreams', function () {
  146. // remove route
  147. for (let i = 0; i < 5; i += 1) {
  148. cy.wait(1000);
  149. cy.get(selector.listTbody).get(selector.listRow).contains('More').click();
  150. cy.contains('Delete').should('be.visible').click();
  151. cy.contains('OK').should('be.visible').click();
  152. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  153. cy.get(selector.notificationCloseIcon).click();
  154. }
  155. cy.visit('/');
  156. cy.contains('Upstream').click();
  157. cy.get(selector.refresh).click();
  158. // remove route
  159. for (let i = 0; i < 2; i += 1) {
  160. cy.wait(1000);
  161. cy.get(selector.listTbody).get(selector.listRow).contains('Delete').click();
  162. cy.contains('Confirm').should('be.visible').click();
  163. cy.get(selector.notification).should('contain', data.deleteUpstreamSuccess);
  164. cy.get(selector.notificationCloseIcon).click();
  165. }
  166. });
  167. });