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

75 lines
2.2 KiB
JavaScript

describe('The today page', () => {
beforeEach(() => {
cy.exec('npm run db:seed')
})
afterEach(() => {
cy.exec('npm run db:wipe')
})
it('redirects to login when not authenticated', () => {
cy.visit('/today')
cy.url().should('include', '/login')
})
it('displays a Today heading when authenticated', () => {
cy.loginAsUser()
cy.visit('/today')
cy.get('h1').should('contain', 'Today')
})
it('has a list element for scheduled nodes', () => {
cy.loginAsUser()
cy.visit('/today')
cy.get('#scheduled-nodes-list').should('exist')
})
it('home page links to the today page', () => {
cy.loginAsUser()
cy.visit('/home')
cy.get('a[href="/today"]').should('be.visible')
})
it('lists scheduled nodes for today', () => {
const today = new Date()
const year = today.getFullYear()
const month = String(today.getMonth() + 1).padStart(2, '0')
const day = String(today.getDate()).padStart(2, '0')
const todayString = year + '-' + month + '-' + day
cy.loginAsUser()
cy.request({
method: 'POST',
url: '/api/plans',
body: {
textId: 0,
name: 'My reading plan',
dateStart: todayString,
dateEnd: todayString,
},
})
cy.intercept('GET', '/api/scheduled-nodes*')
.as('getScheduledNodes')
cy.visit('/today')
cy.wait('@getScheduledNodes').then((interception) => {
expect(interception.request.url).to.include(
'date=' + todayString
)
})
cy.get('#scheduled-nodes-list').should(
'contain',
'My reading plan'
)
cy.get('#scheduled-nodes-list').should('contain', 'Bereishis')
})
it('shows an empty list when no nodes are scheduled today', () => {
cy.loginAsUser()
cy.intercept('GET', '/api/scheduled-nodes*')
.as('getScheduledNodes')
cy.visit('/today')
cy.wait('@getScheduledNodes')
cy.get('#scheduled-nodes-list li').should('have.length', 0)
})
})