create-edit-duplicate-delete-route.cy.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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', () => {
  19. const name = `routeName${new Date().valueOf()}`;
  20. const newName = `newName${new Date().valueOf()}`;
  21. const duplicateNewName = `duplicateName${new Date().valueOf()}`;
  22. const timeout = 5000;
  23. const selector = {
  24. empty: '.ant-empty-normal',
  25. name: '#name',
  26. description: '#desc',
  27. hosts_0: '#hosts_0',
  28. hosts_1: '#hosts_1',
  29. remoteHost: '#remote_addrs_0',
  30. remoteAddress: '[data-cy=addRemoteAddr]',
  31. address1: '#remote_addrs_1',
  32. parameterPosition: '#position',
  33. ruleCard: '.ant-modal',
  34. operator: '#operator',
  35. value: '#value',
  36. nodes_0_host: '#submitNodes_0_host',
  37. nodes_1_host: '#submitNodes_1_host',
  38. nodes_0_port: '#submitNodes_0_port',
  39. nodes_0_weight: '#submitNodes_0_weight',
  40. pluginCardBordered: '.ant-card-bordered',
  41. disabledSwitcher: '#disable',
  42. checkedSwitcher: '.ant-switch-checked',
  43. drawer: '.ant-drawer-content',
  44. selectDropdown: '.ant-select-dropdown',
  45. monacoMode: "[data-cy='monaco-mode']",
  46. selectJSON: '.ant-select-dropdown [label=JSON]',
  47. drawerFooter: '.ant-drawer-footer',
  48. nameSelector: '[title=Name]',
  49. monacoScroll: '.monaco-scrollable-element',
  50. deleteAlert: '.ant-modal-body',
  51. notificationCloseIcon: '.ant-notification-close-icon',
  52. notification: '.ant-notification-notice-message',
  53. addHost: '[data-cy=addHost]',
  54. addNode: '[data-cy=add-node]',
  55. schemaErrorMessage: '.ant-form-item-explain.ant-form-item-explain-error',
  56. stepCheck: '.ant-steps-finish-icon',
  57. advancedMatchingTable: '.ant-table-row.ant-table-row-level-0',
  58. advancedMatchingTableOperation: '.ant-space',
  59. };
  60. const data = {
  61. description: 'desc_by_autotest',
  62. invalidName: 'a'.repeat(101),
  63. host1: '11.11.11.11',
  64. host2: '12.12.12.12',
  65. host3: '10.10.10.10',
  66. host4: '@',
  67. host5: '*1',
  68. host_ipv6: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
  69. host_ipv6_2: '::1',
  70. port: '80',
  71. weight: 1,
  72. basicAuthPlugin: 'basic-auth',
  73. submitSuccess: 'Submit Successfully',
  74. description2: 'description2',
  75. deleteRouteSuccess: 'Delete Route Successfully',
  76. };
  77. const opreatorList = ['Equal(==)', 'Case insensitive regular match(~*)', 'HAS'];
  78. before(() => {
  79. cy.clearLocalStorageSnapshot();
  80. cy.login();
  81. cy.saveLocalStorage();
  82. });
  83. beforeEach(() => {
  84. cy.restoreLocalStorage();
  85. cy.visit('/');
  86. });
  87. it('should not create route with name above 100 characters', function () {
  88. cy.visit('/');
  89. cy.contains('Route').click();
  90. cy.get(selector.empty).should('be.visible');
  91. cy.contains('Create').click();
  92. cy.contains('Next').click();
  93. cy.get(selector.name).type(data.invalidName);
  94. cy.contains(selector.schemaErrorMessage, 'Maximum length should be of 100 only').should(
  95. 'be.visible',
  96. );
  97. cy.contains('Next').click();
  98. cy.get(selector.stepCheck).should('not.exist');
  99. });
  100. it('should create route', function () {
  101. cy.contains('Route').click();
  102. cy.get(selector.empty).should('be.visible');
  103. cy.contains('Create').click();
  104. cy.contains('Next').click().click();
  105. cy.get(selector.name).type(name);
  106. cy.get(selector.description).type(data.description);
  107. // input request basic define
  108. cy.get(selector.hosts_0).type(data.host1);
  109. cy.get(selector.addHost).click();
  110. cy.get(selector.hosts_1).type(data.host2);
  111. cy.get(selector.remoteHost).type(data.host2);
  112. cy.get(selector.remoteAddress).click();
  113. cy.get(selector.address1).type(data.host3);
  114. // All Of Operational Character Should Exist And Can be Created
  115. cy.wrap(opreatorList).each((opreator) => {
  116. cy.contains('Advanced Routing Matching Conditions')
  117. .parent()
  118. .siblings()
  119. .contains('Add')
  120. .click()
  121. .then(() => {
  122. cy.get(selector.parameterPosition)
  123. .click()
  124. .then(() => {
  125. cy.get('.ant-select-dropdown').within(() => {
  126. cy.contains('Cookie').should('be.visible').click();
  127. });
  128. });
  129. cy.get(selector.ruleCard).within(() => {
  130. cy.get(selector.name).type('modalName');
  131. });
  132. cy.get(selector.operator).click();
  133. cy.get(`[title="${opreator}"]`).should('be.visible').click();
  134. cy.get(selector.value).type('value');
  135. cy.contains('Confirm').click();
  136. });
  137. });
  138. cy.contains('Next').click();
  139. cy.get(selector.nodes_0_host).type(data.host4);
  140. cy.get(selector.schemaErrorMessage).should('exist');
  141. cy.get(selector.nodes_0_host).clear().type(data.host5);
  142. cy.get(selector.schemaErrorMessage).should('not.exist');
  143. cy.get(selector.nodes_0_host).clear().type(data.host2);
  144. cy.get(selector.nodes_0_port).type(data.port);
  145. cy.get(selector.nodes_0_weight).type(data.weight);
  146. cy.contains('Next').click();
  147. // redirect plugin should not display in route step3
  148. const nameSelector = '[data-cy-plugin-name]';
  149. cy.get(nameSelector).then((cards) => {
  150. [...cards].forEach((card) => {
  151. expect(card.innerText).to.not.equal('redirect');
  152. });
  153. });
  154. // config basic auth plugin
  155. cy.contains(data.basicAuthPlugin)
  156. .parents(selector.pluginCardBordered)
  157. .within(() => {
  158. cy.get('button').click({ force: true });
  159. });
  160. cy.get(selector.drawer)
  161. .should('be.visible')
  162. .within(() => {
  163. cy.get(selector.disabledSwitcher).click();
  164. cy.get(selector.checkedSwitcher).should('exist');
  165. });
  166. cy.get(selector.monacoMode).click();
  167. cy.get(selector.selectDropdown).should('be.visible');
  168. cy.get(selector.selectJSON).click();
  169. cy.contains('button', 'Submit').click();
  170. cy.get(selector.drawer, { timeout }).should('not.exist');
  171. cy.contains(data.basicAuthPlugin)
  172. .parents(selector.pluginCardBordered)
  173. .within(() => {
  174. cy.get('button').click({ force: true });
  175. });
  176. cy.get(selector.drawerFooter).contains('button', 'Delete').click({ force: true });
  177. cy.contains('button', 'Confirm').click({ force: true });
  178. cy.contains(data.basicAuthPlugin)
  179. .parents(selector.pluginCardBordered)
  180. .within(() => {
  181. cy.get('button').click({ force: true });
  182. });
  183. cy.get(selector.drawerFooter).contains('button', 'Delete').should('not.exist');
  184. cy.contains('button', 'Cancel').click({ force: true });
  185. cy.contains('Next').click();
  186. cy.contains('Submit').click();
  187. cy.contains(data.submitSuccess);
  188. // back to route list page
  189. cy.contains('Goto List').click();
  190. cy.url().should('contains', 'routes/list');
  191. });
  192. it('should view the route', function () {
  193. cy.contains('Route').click();
  194. cy.get(selector.nameSelector).type(name);
  195. cy.contains('Search').click();
  196. cy.contains(name).siblings().contains('More').click();
  197. cy.contains('View').click();
  198. cy.get(selector.drawer).should('be.visible');
  199. cy.get(selector.monacoScroll).within(() => {
  200. cy.contains('upstream').should('exist');
  201. cy.contains('vars').should('exist');
  202. cy.contains('uri').should('exist');
  203. cy.contains('hosts').should('exist');
  204. cy.contains('remote_addr').should('exist');
  205. cy.contains(name).should('exist');
  206. });
  207. });
  208. it('should edit the route', function () {
  209. cy.contains('Route').click();
  210. cy.get(selector.nameSelector).type(name);
  211. cy.contains('Search').click();
  212. cy.contains(name).siblings().contains('Configure').click();
  213. // NOTE: make sure all components rerender done
  214. cy.get('#status').should('have.class', 'ant-switch-checked');
  215. cy.get(selector.name).clear().type(newName);
  216. cy.get(selector.description).clear().type(data.description2);
  217. cy.get(selector.advancedMatchingTable).should('exist');
  218. cy.wrap(opreatorList).each(() => {
  219. cy.get(selector.advancedMatchingTableOperation).within(() => {
  220. cy.contains('Delete').click().should('not.exist');
  221. });
  222. });
  223. cy.contains('Next').click();
  224. cy.contains('Next').click();
  225. cy.contains('Next').click();
  226. cy.contains('Submit').click();
  227. cy.contains(data.submitSuccess);
  228. cy.contains('Goto List').click();
  229. cy.url().should('contains', 'routes/list');
  230. cy.contains(newName).siblings().should('contain', data.description2);
  231. // test view
  232. cy.contains(newName).siblings().contains('More').click();
  233. cy.contains('View').click();
  234. cy.get(selector.drawer).should('be.visible');
  235. cy.get(selector.monacoScroll).within(() => {
  236. cy.contains('upstream').should('exist');
  237. cy.contains(newName).should('exist');
  238. cy.contains('vars').should('not.exist');
  239. });
  240. });
  241. it('should duplicate the route', function () {
  242. cy.contains('Route').click();
  243. cy.reload();
  244. cy.get(selector.nameSelector).type(newName);
  245. cy.contains('Search').click();
  246. cy.contains(newName).siblings().contains('More').click();
  247. cy.contains('Duplicate').click();
  248. // NOTE: make sure all components rerender done
  249. cy.get('#status').should('have.class', 'ant-switch-checked');
  250. cy.get(selector.name).clear().type(duplicateNewName);
  251. cy.get(selector.description).clear().type(data.description2);
  252. cy.contains('Next').click();
  253. cy.contains('Next').click();
  254. cy.contains('Next').click();
  255. cy.contains('Submit').click();
  256. cy.contains(data.submitSuccess);
  257. cy.contains('Goto List').click();
  258. cy.url().should('contains', 'routes/list');
  259. cy.contains(duplicateNewName).siblings().should('contain', data.description2);
  260. // test view
  261. cy.contains(duplicateNewName).siblings().contains('More').click();
  262. cy.contains('View').click();
  263. cy.get(selector.drawer).should('be.visible');
  264. cy.get(selector.monacoScroll).within(() => {
  265. cy.contains('upstream').should('exist');
  266. cy.contains(duplicateNewName).should('exist');
  267. });
  268. });
  269. it('should delete the route', function () {
  270. cy.visit('/routes/list');
  271. const routeNames = [newName, duplicateNewName];
  272. routeNames.forEach(function (routeName) {
  273. cy.get(selector.name).clear().type(routeName);
  274. cy.contains('Search').click();
  275. cy.contains(routeName).siblings().contains('More').click();
  276. cy.contains('Delete').click();
  277. cy.get(selector.deleteAlert)
  278. .should('be.visible')
  279. .within(() => {
  280. cy.contains('OK').click();
  281. });
  282. cy.get(selector.deleteAlert).within(() => {
  283. cy.get('.ant-btn-loading-icon').should('be.visible');
  284. });
  285. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  286. cy.get(selector.notificationCloseIcon).click();
  287. });
  288. });
  289. it('should create route with ipv6 upstream node', () => {
  290. cy.visit('/');
  291. cy.contains('Route').click();
  292. cy.get(selector.empty).should('be.visible');
  293. cy.contains('Create').click();
  294. // step 1
  295. cy.get(selector.name).type(name);
  296. cy.get(selector.description).type(data.description);
  297. cy.contains('Next').click();
  298. // step2
  299. cy.get(selector.nodes_0_host).type(data.host_ipv6);
  300. cy.get(selector.nodes_0_port).type(80);
  301. cy.get(selector.addNode).click();
  302. cy.get(selector.nodes_1_host).type(data.host_ipv6_2);
  303. cy.contains('Next').click();
  304. cy.contains('Next').click();
  305. cy.contains('button', 'Submit').click();
  306. cy.contains(data.submitSuccess);
  307. cy.contains('Goto List').click();
  308. cy.url().should('contains', 'routes/list');
  309. cy.get(selector.nameSelector).type(name);
  310. cy.contains('Search').click();
  311. cy.contains(name).siblings().contains('Configure').click();
  312. cy.get('#status').should('have.class', 'ant-switch-checked');
  313. cy.contains('Next').click();
  314. cy.get(selector.nodes_0_host).should('have.value', data.host_ipv6);
  315. cy.get(selector.nodes_0_port).should('have.value', 80);
  316. cy.get(selector.nodes_1_host).should('have.value', data.host_ipv6_2);
  317. cy.contains('Next').click();
  318. cy.contains('Next').click();
  319. cy.contains('Submit').click();
  320. cy.contains(data.submitSuccess);
  321. cy.contains('Goto List').click();
  322. cy.url().should('contains', 'routes/list');
  323. cy.contains(name).siblings().contains('More').click();
  324. cy.contains('View').click();
  325. cy.get(selector.drawer).should('be.visible');
  326. cy.get(selector.monacoScroll).within(() => {
  327. cy.contains(name).should('exist');
  328. cy.contains(`[${data.host_ipv6}]`).should('exist');
  329. cy.contains(`[${data.host_ipv6_2}]`).should('exist');
  330. });
  331. cy.visit('/routes/list');
  332. cy.get(selector.name).clear().type(name);
  333. cy.contains('Search').click();
  334. cy.contains(name).siblings().contains('More').click();
  335. cy.contains('Delete').click();
  336. cy.get(selector.deleteAlert)
  337. .should('be.visible')
  338. .within(() => {
  339. cy.contains('OK').click();
  340. });
  341. cy.get(selector.deleteAlert).within(() => {
  342. cy.get('.ant-btn-loading-icon').should('be.visible');
  343. });
  344. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  345. cy.get(selector.notificationCloseIcon).click();
  346. });
  347. });