From 527cf2898dd3de84595dcb8894021a0bb72eb96c Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Thu, 28 May 2026 20:10:07 +0300 Subject: [PATCH] test admin element editing --- .../cypress/e2e/admin-element.cy.ts | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 frontend/rabbi_gerzi/cypress/e2e/admin-element.cy.ts diff --git a/frontend/rabbi_gerzi/cypress/e2e/admin-element.cy.ts b/frontend/rabbi_gerzi/cypress/e2e/admin-element.cy.ts new file mode 100644 index 0000000..8678ec2 --- /dev/null +++ b/frontend/rabbi_gerzi/cypress/e2e/admin-element.cy.ts @@ -0,0 +1,123 @@ +function loginAsAdmin(): void { + cy.visit('/login') + + cy.get('[data-cy="login-email"]').type('admin@rabbigerzi.test') + cy.get('[data-cy="login-password"]').type('password123!@#') + cy.get('[data-cy="login-submit"]').click() + + cy.url().should('eq', Cypress.config().baseUrl + '/') + cy.getCookie('auth_token').should('exist') +} + +function fillElementForm( + title: string, + description: string, + iconImageUrl: string, + richText: string, + pdfPath: string, + youtubeUrl: string, +): void { + cy.get('[data-cy="admin-element-title"]').clear().type(title) + cy.get('[data-cy="admin-element-description"]').clear().type(description) + cy.get('[data-cy="admin-element-icon-image-url"]') + .clear() + .type(iconImageUrl) + cy.get('[data-cy="admin-element-rich-text"]').clear() + if (richText !== '') { + cy.get('[data-cy="admin-element-rich-text"]').type(richText, { + parseSpecialCharSequences: false, + }) + } + cy.get('[data-cy="admin-element-pdf-path"]').clear() + if (pdfPath !== '') { + cy.get('[data-cy="admin-element-pdf-path"]').type(pdfPath) + } + cy.get('[data-cy="admin-element-youtube-url"]').clear() + if (youtubeUrl !== '') { + cy.get('[data-cy="admin-element-youtube-url"]').type(youtubeUrl) + } +} + +describe('admin element editing', () => { + it('does not show the edit link to logged-out users', () => { + cy.visit('/element/1') + + cy.contains('header.site-header a', 'Edit Element').should('not.exist') + }) + + it('shows the edit link on public element pages to logged-in users', () => { + loginAsAdmin() + + cy.visit('/element/1') + + cy.contains('header.site-header a', 'Edit Element') + .should('be.visible') + .and('have.attr', 'href', '/admin/element/1') + .click() + cy.location('pathname').should('eq', '/admin/element/1') + }) + + it('redirects logged-out admin element visits to login', () => { + cy.visit('/admin/element/1') + + cy.location('pathname').should('eq', '/login') + }) + + it('shows the view link on admin element pages', () => { + loginAsAdmin() + + cy.visit('/admin/element/1') + + cy.contains('header.site-header a', 'View Element') + .should('be.visible') + .and('have.attr', 'href', '/element/1') + cy.contains('header.site-header a', 'Edit Element').should('not.exist') + cy.get('[data-cy="admin-element-title"]') + .should('have.value', 'Baderech HaAvodah') + }) + + it('saves element edits and restores the seed content through the UI', () => { + const originalTitle = 'Baderech HaAvodah' + const originalDescription = 'a structured path for inner and outer growth' + const originalIconImageUrl = '/assets/baderech-haavodah-icon.png' + const updatedTitle = 'Baderech HaAvodah Updated' + const updatedDescription = 'Updated admin description' + const updatedRichText = '

Updated admin rich text

' + + loginAsAdmin() + cy.visit('/admin/element/1') + + fillElementForm( + updatedTitle, + updatedDescription, + originalIconImageUrl, + updatedRichText, + '', + '', + ) + cy.get('[data-cy="admin-element-save"]').click() + + cy.get('[data-cy="admin-element-status"]') + .should('be.visible') + .and('contain.text', 'Saved') + cy.contains('header.site-header a', 'View Element').click() + cy.location('pathname').should('eq', '/element/1') + cy.contains('h1', updatedTitle).should('be.visible') + cy.get('[data-cy="element-rich-text"]') + .should('contain.text', 'Updated admin rich text') + + cy.visit('/admin/element/1') + fillElementForm( + originalTitle, + originalDescription, + originalIconImageUrl, + '', + '', + '', + ) + cy.get('[data-cy="admin-element-save"]').click() + cy.get('[data-cy="admin-element-status"]') + .should('be.visible') + .and('contain.text', 'Saved') + }) +})