guoqqqi commented on a change in pull request #2370: URL: https://github.com/apache/apisix-dashboard/pull/2370#discussion_r827741522
########## File path: web/cypress/integration/consumer/table-auto-jump-when-no-data.js.js ########## @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* eslint-disable no-undef */ + +context('Table Auto Jump When No Data', () => { + const selector = { + username: '#username', + page_item: '.ant-pagination-item-2', + deleteAlert: '.ant-modal-body', + notificationCloseIcon: '.ant-notification-close-icon', + notification: '.ant-notification-notice-message', + table_row: '.ant-table-row', + pluginCard: '.ant-card', + drawer: '.ant-drawer-content', + monacoScroll: '.monaco-scrollable-element', + monacoViewZones: '.view-zones', + disabledSwitcher: '#disable', + popoper: '.ant-popover', + popoprerHiden: '.ant-popover-hidden', + }; + + const data = { + consumerName: 'test_consumer', + createConsumerSuccess: 'Create Consumer Successfully', + deleteConsumerSuccess: 'Delete Consumer Successfully', + }; + + const deleteConsumer = () => { + cy.contains('Delete').click({ force: true }); + cy.get(selector.popoper) + .not(selector.popoprerHiden) + .contains('Confirm') + .should('be.visible') + .click({ force: true }); + cy.get(selector.notification).should('contain', data.deleteConsumerSuccess); + cy.get(selector.notificationCloseIcon).click(); + }; + + beforeEach(() => { + cy.login(); + Array.from({ length: 11 }).forEach((value, key) => { + const payload = { + username: data.consumerName + key, + plugins: { + 'key-auth': { + key: 'test', + disable: false, + }, + }, + }; + cy.requestWithToken({ method: 'PUT', payload, url: '/apisix/admin/consumers' }); + }); + }); + + afterEach(() => { + cy.visit('/'); + cy.contains('Consumer').click(); + cy.get(`.ant-table-cell:contains(${data.consumerName})`).each((elem) => { + cy.requestWithToken({ + method: 'DELETE', + url: `/apisix/admin/consumers/${elem.text()}`, + }); + }); + }); + + it('should delete last data and jump to first page', () => { + cy.visit('/'); + cy.contains('Consumer').click(); + cy.wait(500); Review comment: Do we really need to wait for this? ########## File path: web/cypress/integration/proto/table-auto-jump-when-no-data.js ########## @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* eslint-disable no-undef */ +context('Batch Create Proto And Delete Proto', () => { + const selector = { + id: '#id', + content: '.view-lines', + page_item: '.ant-pagination-item-2', + draw: '.ant-drawer-content', + deleteAlert: '.ant-modal-body', + notificationCloseIcon: '.ant-notification-close-icon', + notification: '.ant-notification-notice-message', + table_row: '.ant-table-row', + }; + + const data = { + createProtoSuccess: 'Create proto Successfully', + deleteProtoSuccess: 'Delete proto Successfully', + }; + + const deleteProto = () => { + cy.wait(500); + cy.contains('Delete').click(); + cy.contains('button', 'Confirm').click(); + cy.get(selector.notification).should('contain', data.deleteProtoSuccess); + cy.get(selector.notificationCloseIcon).click(); + }; Review comment: We can use the custom command from the official documentation, By the way, we do not recommend using wait https://docs.cypress.io/api/cypress-api/custom-commands https://docs.cypress.io/api/commands/wait#Wait-for-an-arbitrary-period-of-milliseconds ########## File path: web/src/hooks/usePagination.ts ########## @@ -30,5 +33,14 @@ export default function usePagination() { history.replace(`${location.pathname}?page=${page}&pageSize=${pageSize}`); }; - return { paginationConfig, savePageList }; + const checkPageList = (ref: MutableRefObject<ActionType | undefined>) => { + const { current, pageSize, total } = ref.current!.pageInfo as PageInfo; + if (current > pageSize / total && current > 1) { + savePageList(paginationConfig.current - 1, paginationConfig.pageSize); + } else { + ref.current?.reload(); + } + }; + + return { paginationConfig, savePageList, checkPageList }; Review comment: Since we have abstracted the pager into a hook, is it enough for us to write a test for the pagination ########## File path: web/cypress/integration/proto/table-auto-jump-when-no-data.js ########## @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* eslint-disable no-undef */ +context('Batch Create Proto And Delete Proto', () => { + const selector = { + id: '#id', + content: '.view-lines', + page_item: '.ant-pagination-item-2', + draw: '.ant-drawer-content', + deleteAlert: '.ant-modal-body', + notificationCloseIcon: '.ant-notification-close-icon', + notification: '.ant-notification-notice-message', + table_row: '.ant-table-row', + }; + + const data = { + createProtoSuccess: 'Create proto Successfully', + deleteProtoSuccess: 'Delete proto Successfully', + }; + + const deleteProto = () => { + cy.wait(500); + cy.contains('Delete').click(); + cy.contains('button', 'Confirm').click(); + cy.get(selector.notification).should('contain', data.deleteProtoSuccess); + cy.get(selector.notificationCloseIcon).click(); + }; + + beforeEach(() => { + cy.login(); + Array.from({ length: 11 }).forEach(async (value, key) => { + const payload = { + content: 'test', + desc: '', + id: `protoId${key}`, + }; + cy.requestWithToken({ method: 'POST', payload, url: '/apisix/admin/proto' }); + }); + }); + + afterEach(() => { + cy.visit('/'); + cy.contains('Proto').click(); + cy.get('.ant-table-cell:contains(protoId)').each((elem) => { + cy.requestWithToken({ + method: 'DELETE', + url: `/apisix/admin/proto/${elem.text()}`, + }); + }); + }); + + it('should delete last data and jump to first page', () => { + cy.visit('/'); + cy.contains('Proto').click(); + cy.wait(500); + cy.get(selector.page_item).click(); + cy.wait(500); + deleteProto(); Review comment: ```suggestion deleteProto(); ``` IMO, I think it looks strange the way it's written. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
