add tests for admin text page, move some tests over from original admin test file

This commit is contained in:
Yisroel Baum 2026-04-18 21:27:02 +03:00
parent f5a8b8447f
commit 2121a0ba9d
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 86 additions and 17 deletions

View file

@ -26,23 +26,6 @@ describe('The admin page', () => {
cy.contains('Test Text')
})
it('shows one root node and child node on the seeded text page', () => {
cy.visit('/admin/texts/0')
cy.intercept('GET', '/api/nodes/0').as('getNodes')
cy.wait('@getNodes')
cy.get('#text-detail > ul > li > ul > li').should('have.length', 1)
})
it('shows one root node on the text page', () => {
cy.visit('/admin/texts')
cy.get('#newTextName').type('My Node Text')
cy.get('#submit').click()
cy.intercept('GET', '/api/nodes/1').as('getNodes')
cy.get('a').contains('My Node Text').click()
cy.wait('@getNodes')
cy.get('#text-detail > ul').should('have.length', 1)
})
it('navigates to a specific texts page', () => {
cy.visit('/admin/texts')
cy.get('#newTextName').type('My New Text')

View file

@ -0,0 +1,86 @@
describe('The admin text detail page', () => {
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 the text name as a heading', () => {
cy.get('h1').should('contain', 'test text')
})
it('shows the root node', () => {
cy.get('#text-detail li').first().should('contain', 'Chapter 1')
})
it('shows a child node under the root node', () => {
cy.get('#text-detail > ul > li > ul > li').should('contain', 'Section 1.1')
})
it('shows an "Add child" button on each node', () => {
cy.get('#text-detail li').each(($li) => {
cy.wrap($li).find('button.add-child').should('exist')
})
})
it('clicking "Add child" reveals an inline form', () => {
cy.get('#text-detail li').first().find('button.add-child').click()
cy.get('#text-detail li').first().find('input.child-title').should('be.visible')
cy.get('#text-detail li').first().find('button.save-child').should('be.visible')
})
it('can add a child to the root node', () => {
cy.intercept('POST', '/api/nodes').as('createNode')
cy.intercept('GET', '/api/nodes/0').as('getNodesRefresh')
cy.get('#text-detail > ul > li').first().find('button.add-child').click()
cy.get('#text-detail > ul > li').first().find('input.child-title').type('New Child Node')
cy.get('#text-detail > ul > li').first().find('button.save-child').click()
cy.wait('@createNode').its('response.statusCode').should('eq', 201)
cy.wait('@getNodesRefresh')
cy.get('#text-detail li').should('contain', 'New Child Node')
})
it('can add a child to a child node', () => {
cy.intercept('POST', '/api/nodes').as('createNode')
cy.intercept('GET', '/api/nodes/0').as('getNodesRefresh')
cy.get('#text-detail > ul > li > ul > li').first().find('button.add-child').click()
cy.get('#text-detail > ul > li > ul > li').first().find('input.child-title').type('Nested Child Node')
cy.get('#text-detail > ul > li > ul > li').first().find('button.save-child').click()
cy.wait('@createNode').its('response.statusCode').should('eq', 201)
cy.wait('@getNodesRefresh')
cy.get('#text-detail li').should('contain', 'Nested Child Node')
})
it('newly added child persists after page reload', () => {
cy.intercept('POST', '/api/nodes').as('createNode')
cy.intercept('GET', '/api/nodes/0').as('getNodesRefresh')
cy.get('#text-detail > ul > li').first().find('button.add-child').click()
cy.get('#text-detail > ul > li').first().find('input.child-title').type('Persistent Child')
cy.get('#text-detail > ul > li').first().find('button.save-child').click()
cy.wait('@createNode')
cy.wait('@getNodesRefresh')
cy.intercept('GET', '/api/texts/0').as('getTextReload')
cy.intercept('GET', '/api/nodes/0').as('getNodesReload')
cy.reload()
cy.wait('@getTextReload')
cy.wait('@getNodesReload')
cy.get('#text-detail li').should('contain', 'Persistent Child')
})
})