service-table-auto-jump-when-no-data.cy.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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('Table Auto Jump When No Data', () => {
  19. const selector = {
  20. name: '#name',
  21. nodes_0_host: '#submitNodes_0_host',
  22. page_item: '.ant-pagination-item-2',
  23. deleteAlert: '.ant-modal-body',
  24. notificationCloseIcon: '.ant-notification-close-icon',
  25. notification: '.ant-notification-notice-message',
  26. table_row: '.ant-table-row',
  27. };
  28. const data = {
  29. createServiceSuccess: 'Create Service Successfully',
  30. deleteServiceSuccess: 'Delete Service Successfully',
  31. };
  32. beforeEach(() => {
  33. cy.login().then(() => {
  34. Array.from({ length: 11 }).forEach((value, key) => {
  35. const payload = {
  36. name: `serviceName${key}`,
  37. plugins: {},
  38. upstream: {
  39. type: 'roundrobin',
  40. pass_host: 'pass',
  41. scheme: 'http',
  42. timeout: {
  43. connect: 6,
  44. send: 6,
  45. read: 6,
  46. },
  47. keepalive_pool: {
  48. size: 320,
  49. idle_timeout: 60,
  50. requests: 1000,
  51. },
  52. nodes: {
  53. '127.0.0.1': 1,
  54. },
  55. },
  56. };
  57. cy.requestWithToken({ method: 'POST', payload, url: '/apisix/admin/services' });
  58. });
  59. });
  60. });
  61. it('should delete last data and jump to first page', () => {
  62. cy.visit('/');
  63. cy.contains('Service').click();
  64. cy.get(selector.page_item).click();
  65. cy.wait(1000);
  66. cy.contains('serviceName').siblings().contains('Delete').click();
  67. cy.contains('button', 'Confirm').click();
  68. cy.get(selector.notification).should('contain', data.deleteServiceSuccess);
  69. cy.get(selector.notificationCloseIcon).click();
  70. cy.url().should('contains', '/service/list?page=1&pageSize=10');
  71. cy.get(selector.table_row).should((service) => {
  72. expect(service).to.have.length(10);
  73. });
  74. cy.get('.ant-table-cell:contains(serviceName)').each((elem) => {
  75. cy.requestWithToken({
  76. method: 'DELETE',
  77. url: `/apisix/admin/services/${elem.prev().text()}`,
  78. });
  79. });
  80. });
  81. });