Goal-Calibration/cypress/e2e/adminTextBulkAdd.cy.js

85 lines
4.2 KiB
JavaScript

describe('Bulk add children on 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 a "Bulk add children" button on each node', () => {
cy.get('#text-detail li').each(($li) => {
cy.wrap($li).find('button.bulk-add-children').should('exist')
})
})
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().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().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')
cy.get('#text-detail > ul > li').first().children('input.bulk-count').should('not.exist')
cy.get('#text-detail > ul > li').first().children('button.save-bulk').should('not.exist')
})
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().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()
cy.wait('@bulkCreate').its('response.statusCode').should('eq', 201)
cy.wait('@getNodesRefresh')
cy.get('#text-detail li').should('contain', 'Page 1')
cy.get('#text-detail li').should('contain', 'Page 2')
cy.get('#text-detail li').should('contain', 'Page 3')
})
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().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)
})
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().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)
})
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().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()
cy.wait('@bulkCreate')
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', 'Page 1')
cy.get('#text-detail li').should('contain', 'Page 2')
cy.get('#text-detail li').should('contain', 'Page 3')
})
})