154 lines
4.8 KiB
TypeScript
154 lines
4.8 KiB
TypeScript
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,
|
|
richText: 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-rich-text"]').clear()
|
|
if (richText !== '') {
|
|
cy.get('[data-cy="admin-element-rich-text"]').type(richText, {
|
|
parseSpecialCharSequences: false,
|
|
})
|
|
}
|
|
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 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,
|
|
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,
|
|
'',
|
|
'',
|
|
)
|
|
cy.get('[data-cy="admin-element-save"]').click()
|
|
cy.get('[data-cy="admin-element-status"]')
|
|
.should('be.visible')
|
|
.and('contain.text', 'Saved')
|
|
})
|
|
|
|
it('uploads icon and pdf files immediately through the UI', () => {
|
|
cy.resetDb()
|
|
loginAsAdmin()
|
|
cy.visit('/admin/element/1')
|
|
cy.intercept('POST', /\/api\/element\/update$/).as('updateElement')
|
|
|
|
cy.get('[data-cy="admin-element-icon-image-input"]').selectFile(
|
|
'public/assets/baderech-haavodah-icon.png',
|
|
{ force: true },
|
|
)
|
|
cy.wait('@updateElement')
|
|
cy.get('[data-cy="admin-element-icon-image-status"]')
|
|
.should('be.visible')
|
|
.and('contain.text', 'Icon image updated')
|
|
cy.get('[data-cy="admin-element-current-icon"]')
|
|
.should('be.visible')
|
|
.and('have.attr', 'src')
|
|
.and('include', '/storage/element-icons/')
|
|
|
|
cy.get('[data-cy="admin-element-pdf-input"]').selectFile(
|
|
'public/assets/pdfs/baderech.pdf',
|
|
{ force: true },
|
|
)
|
|
cy.wait('@updateElement')
|
|
cy.get('[data-cy="admin-element-pdf-status"]')
|
|
.should('be.visible')
|
|
.and('contain.text', 'PDF updated')
|
|
cy.get('[data-cy="admin-element-current-pdf"]')
|
|
.should('be.visible')
|
|
.and('have.attr', 'href')
|
|
.and('include', '/storage/element-pdfs/')
|
|
|
|
cy.contains('header.site-header a', 'View Element').click()
|
|
cy.get('[data-cy="element-icon"]')
|
|
.should('be.visible')
|
|
.and('have.attr', 'src')
|
|
.and('include', '/storage/element-icons/')
|
|
cy.get('[data-cy="element-pdf-link"]')
|
|
.should('be.visible')
|
|
.and('have.attr', 'href')
|
|
.and('include', '/storage/element-pdfs/')
|
|
|
|
cy.resetDb()
|
|
})
|
|
})
|