2
0

service-save-paginator-status.cy.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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('Save Paginator Status', () => {
  18. const timeout = 2000;
  19. const token = localStorage.getItem('token');
  20. const { SERVE_URL } = Cypress.env();
  21. const selector = {
  22. twentyPerPage: '[title="20 / page"]',
  23. pageList: '.ant-table-pagination-right',
  24. pageTwo: '.ant-pagination-item-2',
  25. pageTwoActived: '.ant-pagination-item-2.ant-pagination-item-active',
  26. paginationOptions: '.ant-pagination-options',
  27. deleteButton: '.ant-btn-dangerous',
  28. notification: '.ant-notification-notice-message',
  29. notificationCloseIcon: '.ant-notification-close-icon',
  30. };
  31. const data = {
  32. serviceName: 'test_service',
  33. deleteServiceSuccess: 'Delete Service Successfully',
  34. };
  35. before(() => {
  36. cy.clearLocalStorageSnapshot();
  37. cy.login();
  38. cy.saveLocalStorage();
  39. });
  40. beforeEach(() => {
  41. cy.restoreLocalStorage();
  42. });
  43. it('should create 11 test services', function () {
  44. cy.visit('/');
  45. cy.contains('Service').click();
  46. for (let i = 0; i <= 10; i += 1) {
  47. cy.request(
  48. {
  49. method: 'POST',
  50. url: `${SERVE_URL}/apisix/admin/services`,
  51. headers: {
  52. Authorization: token,
  53. },
  54. body: {
  55. upstream: {
  56. nodes: { '39.97.63.215:80': 1 },
  57. timeout: { connect: 6, read: 6, send: 6 },
  58. type: 'roundrobin',
  59. pass_host: 'pass',
  60. },
  61. enable_websocket: true,
  62. name: `${data.serviceName}${i}`,
  63. },
  64. },
  65. {
  66. retryOnStatusCodeFailure: true,
  67. },
  68. ).then((res) => {
  69. expect(res.body.code).to.equal(0);
  70. });
  71. }
  72. cy.get(selector.pageList).should('be.visible');
  73. });
  74. it("should save paginator' status", function () {
  75. cy.visit('/');
  76. cy.contains('Service').click();
  77. // Test page status
  78. cy.get(selector.pageList).should('be.visible');
  79. cy.get(selector.pageTwo).click();
  80. cy.get(selector.pageTwoActived).should('exist');
  81. cy.location('href').should('include', 'page=2');
  82. cy.reload();
  83. cy.get(selector.pageTwoActived).should('exist');
  84. cy.location('href').should('include', 'page=2');
  85. // Test pageSize status
  86. cy.get(selector.paginationOptions).click();
  87. cy.contains('20 / page').should('be.visible').click();
  88. cy.get(selector.twentyPerPage).should('exist');
  89. cy.location('href').should('include', 'pageSize=20');
  90. cy.reload();
  91. cy.get(selector.twentyPerPage).should('exist');
  92. cy.location('href').should('include', 'pageSize=20');
  93. });
  94. it('should delete test service', function () {
  95. cy.visit('/service/list?page=1&pageSize=20');
  96. cy.reload();
  97. cy.contains('Service List').should('be.visible');
  98. cy.get(selector.deleteButton, { timeout })
  99. .should('exist')
  100. .each(function ($el) {
  101. cy.wrap($el).click().click({ timeout });
  102. cy.contains('button', 'Confirm').click({ force: true });
  103. cy.get(selector.notification).should('contain', data.deleteServiceSuccess);
  104. cy.get(selector.notificationCloseIcon).click().should('not.exist');
  105. });
  106. });
  107. });