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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. username: '#username',
  20. page_item: '.ant-pagination-item-2',
  21. deleteAlert: '.ant-modal-body',
  22. notificationCloseIcon: '.ant-notification-close-icon',
  23. notification: '.ant-notification-notice-message',
  24. table_row: '.ant-table-row',
  25. pluginCard: '.ant-card',
  26. drawer: '.ant-drawer-content',
  27. monacoScroll: '.monaco-scrollable-element',
  28. monacoViewZones: '.view-zones',
  29. disabledSwitcher: '#disable',
  30. popoper: '.ant-popover',
  31. popoprerHiden: '.ant-popover-hidden',
  32. };
  33. const data = {
  34. consumerName: 'test_consumer',
  35. createConsumerSuccess: 'Create Consumer Successfully',
  36. deleteConsumerSuccess: 'Delete Consumer Successfully',
  37. };
  38. before(() => {
  39. cy.login().then(() => {
  40. Array.from({ length: 11 }).forEach((value, key) => {
  41. const payload = {
  42. username: data.consumerName + key,
  43. plugins: {
  44. 'key-auth': {
  45. key: 'test',
  46. disable: false,
  47. },
  48. },
  49. };
  50. cy.requestWithToken({ method: 'PUT', payload, url: '/apisix/admin/consumers' });
  51. });
  52. });
  53. });
  54. it('should delete last data and jump to first page', () => {
  55. cy.visit('/');
  56. cy.contains('Consumer').click();
  57. cy.get(selector.page_item).click();
  58. cy.wait(1000);
  59. cy.contains('Delete').click();
  60. cy.get(selector.popoper)
  61. .not(selector.popoprerHiden)
  62. .contains('Confirm')
  63. .should('be.visible')
  64. .click();
  65. cy.get(selector.notification).should('contain', data.deleteConsumerSuccess);
  66. cy.get(selector.notificationCloseIcon).click();
  67. cy.url().should('contains', '/consumer/list?page=1&pageSize=10');
  68. cy.get(selector.table_row).should((consumer) => {
  69. expect(consumer).to.have.length(10);
  70. });
  71. cy.get(`.ant-table-cell:contains(${data.consumerName})`).each((elem) => {
  72. cy.requestWithToken({
  73. method: 'DELETE',
  74. url: `/apisix/admin/consumers/${elem.text()}`,
  75. });
  76. });
  77. });
  78. });