test admin element editing
This commit is contained in:
parent
73b0befc97
commit
527cf2898d
1 changed files with 123 additions and 0 deletions
123
frontend/rabbi_gerzi/cypress/e2e/admin-element.cy.ts
Normal file
123
frontend/rabbi_gerzi/cypress/e2e/admin-element.cy.ts
Normal file
|
|
@ -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 = '<p>Updated admin rich text</p>'
|
||||||
|
|
||||||
|
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')
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
Add table
Add a link
Reference in a new issue