activate node before clicking action buttons in tests

This commit is contained in:
Yisroel Baum 2026-05-04 10:03:54 +03:00
parent c73cbe2f1a
commit 793b0149b8
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
5 changed files with 39 additions and 13 deletions

View file

@ -32,7 +32,8 @@ describe('The admin text detail page', () => {
})
it('clicking "Add child" reveals an inline form', () => {
cy.get('#text-detail li').first().children('button.add-child').click()
cy.get('#text-detail li').first().activateNode()
.children('button.add-child').click()
cy.get('#text-detail li').first().children('input.child-title').should('be.visible')
cy.get('#text-detail li').first().children('button.save-child').should('be.visible')
})
@ -41,7 +42,8 @@ describe('The admin text detail page', () => {
cy.intercept('POST', '/api/nodes').as('createNode')
cy.intercept('GET', '/api/nodes/0').as('getNodesRefresh')
cy.get('#text-detail > ul > li').first().children('button.add-child').click()
cy.get('#text-detail > ul > li').first().activateNode()
.children('button.add-child').click()
cy.get('#text-detail > ul > li').first().children('input.child-title').type('New Child Node')
cy.get('#text-detail > ul > li').first().children('button.save-child').click()
@ -55,7 +57,8 @@ describe('The admin text detail page', () => {
cy.intercept('POST', '/api/nodes').as('createNode')
cy.intercept('GET', '/api/nodes/0').as('getNodesRefresh')
cy.get('#text-detail > ul > li > ul > li').first().children('button.add-child').click()
cy.get('#text-detail > ul > li > ul > li').first().activateNode()
.children('button.add-child').click()
cy.get('#text-detail > ul > li > ul > li').first().children('input.child-title').type('Nested Child Node')
cy.get('#text-detail > ul > li > ul > li').first().children('button.save-child').click()
@ -69,6 +72,9 @@ describe('The admin text detail page', () => {
cy.intercept('POST', '/api/nodes').as('createNode')
cy.intercept('GET', '/api/nodes/0').as('getNodesRefresh')
cy.get('#text-detail > ul > li > ul > li')
.first()
.activateNode()
cy.get('#text-detail > ul > li > ul > li')
.first()
.find('button.toggle-children')
@ -107,6 +113,7 @@ describe('The admin text detail page', () => {
cy.get('#text-detail > ul > li')
.first()
.activateNode()
.children('button.add-child')
.click()
cy.get('#text-detail > ul > li')
@ -123,6 +130,7 @@ describe('The admin text detail page', () => {
it('opening add-child on another node closes the first one', () => {
cy.get('#text-detail > ul > li')
.first()
.activateNode()
.children('button.add-child')
.click()
cy.get('#text-detail > ul > li')
@ -132,6 +140,7 @@ describe('The admin text detail page', () => {
cy.get('#text-detail > ul > li > ul > li')
.first()
.activateNode()
.children('button.add-child')
.click()
@ -152,6 +161,7 @@ describe('The admin text detail page', () => {
it('opening bulk-add closes an open add-child form', () => {
cy.get('#text-detail > ul > li')
.first()
.activateNode()
.children('button.add-child')
.click()
cy.get('#text-detail > ul > li')
@ -161,6 +171,7 @@ describe('The admin text detail page', () => {
cy.get('#text-detail > ul > li > ul > li')
.first()
.activateNode()
.children('button.bulk-add-children')
.click()
@ -178,7 +189,8 @@ describe('The admin text detail page', () => {
cy.intercept('POST', '/api/nodes').as('createNode')
cy.intercept('GET', '/api/nodes/0').as('getNodesRefresh')
cy.get('#text-detail > ul > li').first().children('button.add-child').click()
cy.get('#text-detail > ul > li').first().activateNode()
.children('button.add-child').click()
cy.get('#text-detail > ul > li').first().children('input.child-title').type('Persistent Child')
cy.get('#text-detail > ul > li').first().children('button.save-child').click()

View file

@ -20,14 +20,16 @@ describe('Bulk add children on the admin text detail page', () => {
})
it('clicking "Bulk add children" reveals inline form inputs', () => {
cy.get('#text-detail > ul > li').first().children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().activateNode()
.children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().children('input.bulk-title').should('be.visible')
cy.get('#text-detail > ul > li').first().children('input.bulk-count').should('be.visible')
cy.get('#text-detail > ul > li').first().children('button.save-bulk').should('be.visible')
})
it('clicking "Bulk add children" again hides the form', () => {
cy.get('#text-detail > ul > li').first().children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().activateNode()
.children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().children('input.bulk-title').should('be.visible')
cy.get('#text-detail > ul > li').first().children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().children('input.bulk-title').should('not.exist')
@ -38,7 +40,8 @@ describe('Bulk add children on the admin text detail page', () => {
it('can bulk add children to the root node', () => {
cy.intercept('POST', '/api/nodes/bulk').as('bulkCreate')
cy.intercept('GET', '/api/nodes/0').as('getNodesRefresh')
cy.get('#text-detail > ul > li').first().children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().activateNode()
.children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().children('input.bulk-title').type('Page')
cy.get('#text-detail > ul > li').first().children('input.bulk-count').type('3')
cy.get('#text-detail > ul > li').first().children('button.save-bulk').click()
@ -51,7 +54,8 @@ describe('Bulk add children on the admin text detail page', () => {
it('does not submit if title prefix is empty', () => {
cy.intercept('POST', '/api/nodes/bulk').as('bulkCreate')
cy.get('#text-detail > ul > li').first().children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().activateNode()
.children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().children('input.bulk-count').type('3')
cy.get('#text-detail > ul > li').first().children('button.save-bulk').click()
cy.get('@bulkCreate.all').should('have.length', 0)
@ -59,7 +63,8 @@ describe('Bulk add children on the admin text detail page', () => {
it('does not submit if count is empty', () => {
cy.intercept('POST', '/api/nodes/bulk').as('bulkCreate')
cy.get('#text-detail > ul > li').first().children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().activateNode()
.children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().children('input.bulk-title').type('Page')
cy.get('#text-detail > ul > li').first().children('button.save-bulk').click()
cy.get('@bulkCreate.all').should('have.length', 0)
@ -68,7 +73,8 @@ describe('Bulk add children on the admin text detail page', () => {
it('pressing Enter in the bulk-count input submits', () => {
cy.intercept('POST', '/api/nodes/bulk').as('bulkCreate')
cy.intercept('GET', '/api/nodes/0').as('getNodesRefresh')
cy.get('#text-detail > ul > li').first().children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().activateNode()
.children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().children('input.bulk-title').type('Enter')
cy.get('#text-detail > ul > li').first().children('input.bulk-count').type('2{enter}')
cy.wait('@bulkCreate').its('response.statusCode').should('eq', 201)
@ -80,7 +86,8 @@ describe('Bulk add children on the admin text detail page', () => {
it('pressing Enter in the bulk-title input submits', () => {
cy.intercept('POST', '/api/nodes/bulk').as('bulkCreate')
cy.intercept('GET', '/api/nodes/0').as('getNodesRefresh')
cy.get('#text-detail > ul > li').first().children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().activateNode()
.children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().children('input.bulk-count').type('2')
cy.get('#text-detail > ul > li').first().children('input.bulk-title').type('Title{enter}')
cy.wait('@bulkCreate').its('response.statusCode').should('eq', 201)
@ -92,7 +99,8 @@ describe('Bulk add children on the admin text detail page', () => {
it('bulk added nodes persist after page reload', () => {
cy.intercept('POST', '/api/nodes/bulk').as('bulkCreate')
cy.intercept('GET', '/api/nodes/0').as('getNodesRefresh')
cy.get('#text-detail > ul > li').first().children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().activateNode()
.children('button.bulk-add-children').click()
cy.get('#text-detail > ul > li').first().children('input.bulk-title').type('Page')
cy.get('#text-detail > ul > li').first().children('input.bulk-count').type('3')
cy.get('#text-detail > ul > li').first().children('button.save-bulk').click()

View file

@ -35,6 +35,7 @@ describe('The admin text detail page horizontal layout', () => {
cy.get('#text-detail > ul > li')
.first()
.activateNode()
.children('button.add-child')
.click()
cy.get('#text-detail > ul > li')

View file

@ -30,7 +30,7 @@ describe('The user text detail page', () => {
cy.visit('/texts/0')
cy.wait('@getNodes')
cy.get('#text-detail > ul > li').first()
cy.get('#text-detail > ul > li').first().activateNode()
.children('button.add-child').click()
cy.get('#text-detail > ul > li').first()
.children('input.child-title').type('My new child')

View file

@ -17,3 +17,8 @@ Cypress.Commands.add('loginAsUser', () => {
Cypress.Commands.add('loginAsSecondUser', () => {
cy.login('user2@example.com', 'password2')
})
Cypress.Commands.add('activateNode', { prevSubject: 'element' }, ($li) => {
cy.wrap($li).children('span').first().click()
return cy.wrap($li)
})