test toggle children button visibility

This commit is contained in:
Yisroel Baum 2026-04-20 09:32:28 +03:00
parent f79757ce7e
commit d26734facf
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -0,0 +1,67 @@
describe('Toggle display of child nodes', () => {
beforeEach(() => {
cy.exec('npm run db:seed')
cy.intercept('GET', '/api/texts/0').as('getText')
cy.intercept('GET', '/api/nodes/0').as('getNodes')
cy.visit('/admin/texts/0')
cy.wait('@getText')
cy.wait('@getNodes')
})
afterEach(() => {
cy.exec('npm run db:wipe')
})
it('shows a toggle button on nodes that have children', () => {
cy.get('#text-detail > ul > li')
.first()
.find('button.toggle-children')
.should('exist')
})
it('does not show a toggle button on leaf nodes', () => {
cy.get('#text-detail > ul > li > ul > li > ul > li')
.first()
.find('button.toggle-children')
.should('not.exist')
})
it('root node children are visible on initial load', () => {
cy.get('#text-detail > ul > li > ul > li')
.first()
.should('be.visible')
})
it('grandchildren are hidden on initial load', () => {
cy.get('#text-detail > ul > li > ul > li > ul')
.first()
.should('not.be.visible')
})
it('clicking toggle button on a node shows its children', () => {
cy.get('#text-detail > ul > li > ul > li')
.first()
.find('button.toggle-children')
.click()
cy.get('#text-detail > ul > li > ul > li > ul')
.first()
.should('be.visible')
})
it('clicking toggle button again hides children', () => {
cy.get('#text-detail > ul > li > ul > li')
.first()
.find('button.toggle-children')
.click()
cy.get('#text-detail > ul > li > ul > li > ul')
.first()
.should('be.visible')
cy.get('#text-detail > ul > li > ul > li')
.first()
.find('button.toggle-children')
.click()
cy.get('#text-detail > ul > li > ul > li > ul')
.first()
.should('not.be.visible')
})
})