From a62b8763f0fcd50188a7f4a0e91b92e29c1db4d0 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Sun, 3 May 2026 19:13:50 +0300 Subject: [PATCH] test admin nav link visibility --- cypress/e2e/adminNavLink.cy.js | 70 ++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 cypress/e2e/adminNavLink.cy.js diff --git a/cypress/e2e/adminNavLink.cy.js b/cypress/e2e/adminNavLink.cy.js new file mode 100644 index 0000000..0b0ae36 --- /dev/null +++ b/cypress/e2e/adminNavLink.cy.js @@ -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') + }) + }) +})