test admin nav link visibility

This commit is contained in:
Yisroel Baum 2026-05-03 19:13:50 +03:00
parent 03f0466274
commit a62b8763f0
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -0,0 +1,70 @@
describe('The admin nav link', () => {
beforeEach(() => {
cy.exec('npm run db:seed')
})
afterEach(() => {
cy.exec('npm run db:wipe')
})
describe('when logged in as an admin', () => {
beforeEach(() => {
cy.loginAsAdmin()
})
it('shows the admin link on the home page', () => {
cy.visit('/home')
cy.get('#admin-link')
.should('be.visible')
.and('have.attr', 'href', '/admin')
})
it('shows the admin link on the today page', () => {
cy.visit('/today')
cy.get('#admin-link')
.should('be.visible')
.and('have.attr', 'href', '/admin')
})
it('shows the admin link on the user texts page', () => {
cy.visit('/texts')
cy.get('#admin-link')
.should('be.visible')
.and('have.attr', 'href', '/admin')
})
it('navigates to the admin page when clicked', () => {
cy.visit('/home')
cy.get('#admin-link').click()
cy.url().should('include', '/admin')
cy.get('h1').should('contain', 'Admin')
})
})
describe('when logged in as a regular user', () => {
beforeEach(() => {
cy.loginAsUser()
})
it('does not show the admin link on the home page', () => {
cy.visit('/home')
cy.get('#admin-link').should('not.be.visible')
})
it('does not show the admin link on the today page', () => {
cy.visit('/today')
cy.get('#admin-link').should('not.be.visible')
})
it('does not show the admin link on the user texts page', () => {
cy.visit('/texts')
cy.get('#admin-link').should('not.be.visible')
})
it('does not show the admin link on a user text page', () => {
cy.intercept('GET', '/api/texts/0').as('getText')
cy.visit('/texts/0')
cy.wait('@getText')
cy.get('#admin-link').should('not.be.visible')
})
})
})