diff --git a/cypress/integration/grid_pagination.js b/cypress/integration/grid_pagination.js new file mode 100644 index 0000000000..bf6f144358 --- /dev/null +++ b/cypress/integration/grid_pagination.js @@ -0,0 +1,45 @@ +context('Grid Pagination', () => { + beforeEach(() => { + cy.visit('/desk#Form/Contact/Test Contact'); + }); + before(() => { + cy.login(); + cy.visit('/desk'); + cy.window().its('frappe').then(frappe => { + frappe.call("frappe.tests.ui_test_helpers.create_contact_phone_nos_records"); + }); + }); + it('creates pages for child table', () => { + cy.get('.frappe-control[data-fieldname="phone_nos"]').as('table'); + cy.get('@table').find('.current-page-number').should('contain', '1'); + cy.get('@table').find('.total-page-number').should('contain', '50'); + cy.get('@table').find('.grid-body .grid-row').should('have.length', 20); + }); + it('goes to the next and previous page', () => { + cy.get('.frappe-control[data-fieldname="phone_nos"]').as('table'); + cy.get('@table').find('.next-page').click(); + cy.get('@table').find('.current-page-number').should('contain', '2'); + cy.get('@table').find('.grid-body .grid-row').first().should('have.attr', 'data-idx', '21'); + cy.get('@table').find('.prev-page').click(); + cy.get('@table').find('.current-page-number').should('contain', '1'); + cy.get('@table').find('.grid-body .grid-row').first().should('have.attr', 'data-idx', '1'); + }); + it('adds and deletes rows and changes page', ()=> { + cy.get('.frappe-control[data-fieldname="phone_nos"]').as('table'); + cy.get('@table').find('button.grid-add-row').click(); + cy.get('@table').find('.grid-body .row-index').should('contain', 1001); + cy.get('@table').find('.current-page-number').should('contain', '51'); + cy.get('@table').find('.total-page-number').should('contain', '51'); + cy.get('@table').find('.grid-body .grid-row .grid-row-check').click({force: true}); + cy.get('@table').find('button.grid-remove-rows').click(); + cy.get('@table').find('.grid-body .row-index').last().should('contain', 1000); + cy.get('@table').find('.current-page-number').should('contain', '50'); + cy.get('@table').find('.total-page-number').should('contain', '50'); + }); + it('deletes all rows', ()=> { + cy.get('.frappe-control[data-fieldname="phone_nos"]').as('table'); + cy.get('@table').find('.grid-heading-row .grid-row-check').click({force: true}); + cy.get('@table').find('button.grid-remove-all-rows').click(); + cy.get('@table').find('.grid-body .grid-row').should('have.length', 0); + }); +}); \ No newline at end of file diff --git a/frappe/tests/ui_test_helpers.py b/frappe/tests/ui_test_helpers.py index 3747eaa75b..05f3c0617e 100644 --- a/frappe/tests/ui_test_helpers.py +++ b/frappe/tests/ui_test_helpers.py @@ -63,3 +63,15 @@ def setup_workflow(): create_todo_workflow() create_todo_records() frappe.clear_cache() + +@frappe.whitelist() +def create_contact_phone_nos_records(): + if frappe.db.get_all('Contact', {'first_name': 'Test Contact'}): + return + + doc = frappe.new_doc('Contact') + doc.first_name = 'Test Contact' + doc.insert() + for x in range(1000): + doc.append('phone_nos', {'phone': '123456789'}) + doc.save() \ No newline at end of file