add cypress coverage for user text pages
loginAsSecondUser helper backs new specs that cover the
/texts list (own-only scoping, create form, link to
/texts/{id}) and /texts/{id} detail (own access, 403 on
another user's text, owner can add a child node).
This commit is contained in:
parent
6d11f7e887
commit
71e5fb8fda
3 changed files with 114 additions and 0 deletions
53
cypress/e2e/userTexts.cy.js
Normal file
53
cypress/e2e/userTexts.cy.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
describe('The user texts page', () => {
|
||||
beforeEach(() => {
|
||||
cy.exec('npm run db:seed')
|
||||
cy.loginAsUser()
|
||||
})
|
||||
afterEach(() => {
|
||||
cy.exec('npm run db:wipe')
|
||||
})
|
||||
|
||||
it('shows my texts page with heading and form', () => {
|
||||
cy.visit('/texts')
|
||||
cy.get('h1').should('contain', 'My Texts')
|
||||
cy.get('#newTextName').should('exist')
|
||||
cy.get('#submit').should('exist')
|
||||
})
|
||||
|
||||
it('lists the seeded text owned by the user', () => {
|
||||
cy.intercept('GET', '/api/texts').as('getTexts')
|
||||
cy.visit('/texts')
|
||||
cy.wait('@getTexts')
|
||||
cy.get('#texts-list').should('contain', 'Tanach')
|
||||
})
|
||||
|
||||
it('creates a new text', () => {
|
||||
cy.visit('/texts')
|
||||
cy.get('#newTextName').type('My Notes')
|
||||
cy.get('#submit').click()
|
||||
cy.contains('My Notes')
|
||||
})
|
||||
|
||||
it('newly created text links to /texts/{id}', () => {
|
||||
cy.visit('/texts')
|
||||
cy.get('#newTextName').type('Linked Text')
|
||||
cy.get('#submit').click()
|
||||
cy.get('a')
|
||||
.contains('Linked Text')
|
||||
.should('have.attr', 'href')
|
||||
.and('match', /^\/texts\/\d+$/)
|
||||
})
|
||||
|
||||
it('does not show texts owned by other users', () => {
|
||||
cy.loginAsSecondUser()
|
||||
cy.visit('/texts')
|
||||
cy.get('#texts-list').should('not.contain', 'Tanach')
|
||||
})
|
||||
|
||||
it('navigates to user text detail on click', () => {
|
||||
cy.visit('/texts')
|
||||
cy.get('a').contains('Tanach').click()
|
||||
cy.url().should('match', /\/texts\/0$/)
|
||||
cy.get('#back').should('have.attr', 'href', '/texts')
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue