table-auto-jump-when-no-data.cy.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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('Table Auto Jump When No Data', () => {
  18. const selector = {
  19. name: '#name',
  20. nodes_0_host: '#submitNodes_0_host',
  21. page_item: '.ant-pagination-item-2',
  22. deleteAlert: '.ant-modal-body',
  23. notificationCloseIcon: '.ant-notification-close-icon',
  24. notification: '.ant-notification-notice-message',
  25. table_row: '.ant-table-row',
  26. };
  27. const data = {
  28. submitSuccess: 'Submit Successfully',
  29. deleteRouteSuccess: 'Delete Route Successfully',
  30. };
  31. before(() => {
  32. cy.login().then(() => {
  33. Array.from({ length: 11 }).forEach((value, key) => {
  34. const payload = {
  35. methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS', 'CONNECT', 'TRACE'],
  36. priority: 0,
  37. name: `routeName${key}`,
  38. desc: '',
  39. status: 1,
  40. labels: {},
  41. uri: '/*',
  42. upstream: {
  43. type: 'roundrobin',
  44. pass_host: 'pass',
  45. scheme: 'http',
  46. timeout: {
  47. connect: 6,
  48. send: 6,
  49. read: 6,
  50. },
  51. keepalive_pool: {
  52. size: 320,
  53. idle_timeout: 60,
  54. requests: 1000,
  55. },
  56. nodes: {
  57. '127.0.0.1': 1,
  58. },
  59. },
  60. };
  61. cy.requestWithToken({ method: 'POST', payload, url: '/apisix/admin/routes' });
  62. });
  63. });
  64. });
  65. it('should delete last data and jump to first page', () => {
  66. cy.visit('/');
  67. cy.contains('Route').click();
  68. cy.get(selector.page_item).click();
  69. cy.wait(1000);
  70. cy.contains('routeName').siblings().contains('More').click();
  71. cy.contains('Delete').click();
  72. cy.get(selector.deleteAlert)
  73. .should('be.visible')
  74. .within(() => {
  75. cy.contains('OK').click();
  76. });
  77. cy.get(selector.notification).should('contain', data.deleteRouteSuccess);
  78. cy.get(selector.notificationCloseIcon).click();
  79. cy.url().should('contains', '/routes/list?page=1&pageSize=10');
  80. cy.get(selector.table_row).should((route) => {
  81. expect(route).to.have.length(10);
  82. });
  83. cy.get('.ant-table-cell:contains(routeName)').each((elem) => {
  84. cy.requestWithToken({
  85. method: 'DELETE',
  86. url: `/apisix/admin/routes/${elem.next().text()}`,
  87. });
  88. });
  89. });
  90. });