test rich text editor

This commit is contained in:
Yisroel Baum 2026-06-21 21:09:48 +03:00
parent 3db7b9d98f
commit cdc29b795a
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 41 additions and 11 deletions

View file

@ -17,11 +17,9 @@ function fillElementForm(
): void { ): void {
cy.get('[data-cy="admin-element-title"]').clear().type(title) 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-description"]').clear().type(description)
cy.get('[data-cy="admin-element-rich-text"]').clear() clearRichText()
if (richText !== '') { if (richText !== '') {
cy.get('[data-cy="admin-element-rich-text"]').type(richText, { cy.get('[data-cy="admin-element-rich-text"]').type(richText)
parseSpecialCharSequences: false,
})
} }
cy.get('[data-cy="admin-element-youtube-url"]').clear() cy.get('[data-cy="admin-element-youtube-url"]').clear()
if (youtubeUrl !== '') { if (youtubeUrl !== '') {
@ -29,6 +27,12 @@ function fillElementForm(
} }
} }
function clearRichText(): void {
cy.get('[data-cy="admin-element-rich-text"]')
.click()
.type('{selectAll}{backspace}')
}
describe('admin element editing', () => { describe('admin element editing', () => {
it('does not show the edit link to logged-out users', () => { it('does not show the edit link to logged-out users', () => {
cy.visit('/element/1') cy.visit('/element/1')
@ -72,7 +76,6 @@ describe('admin element editing', () => {
const originalDescription = 'a structured path for inner and outer growth' const originalDescription = 'a structured path for inner and outer growth'
const updatedTitle = 'Baderech HaAvodah Updated' const updatedTitle = 'Baderech HaAvodah Updated'
const updatedDescription = 'Updated admin description' const updatedDescription = 'Updated admin description'
const updatedRichText = '<p>Updated admin rich text</p>'
loginAsAdmin() loginAsAdmin()
cy.visit('/admin/element/1') cy.visit('/admin/element/1')
@ -80,9 +83,28 @@ describe('admin element editing', () => {
fillElementForm( fillElementForm(
updatedTitle, updatedTitle,
updatedDescription, updatedDescription,
updatedRichText, '',
'', '',
) )
cy.get('[data-cy="admin-element-rich-text"]')
.should('have.attr', 'contenteditable', 'true')
cy.get('[data-cy="admin-rich-text-block-type"]').select('heading-2')
cy.get('[data-cy="admin-element-rich-text"]')
.type('Updated admin heading{enter}')
cy.get('[data-cy="admin-rich-text-bold"]').click()
cy.get('[data-cy="admin-element-rich-text"]').type('Strong admin text')
cy.get('[data-cy="admin-rich-text-bold"]').click()
cy.get('[data-cy="admin-element-rich-text"]').type('{enter}')
cy.get('[data-cy="admin-rich-text-bullet-list"]').click()
cy.get('[data-cy="admin-element-rich-text"]')
.type('First saved item{enter}Second saved item')
cy.get('[data-cy="admin-rich-text-bullet-list"]').click()
cy.window().then((windowObject) => {
cy.stub(windowObject, 'prompt').returns('https://example.com/rich-text')
})
cy.get('[data-cy="admin-rich-text-link"]').click()
cy.get('[data-cy="admin-rich-text-insert-table"]').click()
cy.get('[data-cy="admin-element-save"]').click() cy.get('[data-cy="admin-element-save"]').click()
cy.get('[data-cy="admin-element-status"]') cy.get('[data-cy="admin-element-status"]')
@ -91,8 +113,16 @@ describe('admin element editing', () => {
cy.contains('header.site-header a', 'View Element').click() cy.contains('header.site-header a', 'View Element').click()
cy.location('pathname').should('eq', '/element/1') cy.location('pathname').should('eq', '/element/1')
cy.contains('h1', updatedTitle).should('be.visible') cy.contains('h1', updatedTitle).should('be.visible')
cy.get('[data-cy="element-rich-text"] h2')
.should('contain.text', 'Updated admin heading')
cy.get('[data-cy="element-rich-text"] strong')
.should('contain.text', 'Strong admin text')
cy.get('[data-cy="element-rich-text"]') cy.get('[data-cy="element-rich-text"]')
.should('contain.text', 'Updated admin rich text') .should('contain.text', 'First saved item')
.and('contain.text', 'Second saved item')
cy.get('[data-cy="element-rich-text"] a')
.should('have.attr', 'href', 'https://example.com/rich-text')
cy.get('[data-cy="element-rich-text"] table').should('exist')
cy.visit('/admin/element/1') cy.visit('/admin/element/1')
fillElementForm( fillElementForm(
@ -105,6 +135,8 @@ describe('admin element editing', () => {
cy.get('[data-cy="admin-element-status"]') cy.get('[data-cy="admin-element-status"]')
.should('be.visible') .should('be.visible')
.and('contain.text', 'Saved') .and('contain.text', 'Saved')
cy.contains('header.site-header a', 'View Element').click()
cy.get('[data-cy="element-rich-text"]').should('not.exist')
}) })
it('uploads icon and pdf files immediately through the UI', () => { it('uploads icon and pdf files immediately through the UI', () => {

View file

@ -21,10 +21,8 @@ describe('cypress database reset', () => {
.clear() .clear()
.type('Dirty Cypress description') .type('Dirty Cypress description')
cy.get('[data-cy="admin-element-rich-text"]') cy.get('[data-cy="admin-element-rich-text"]')
.clear() .click()
.type('<p>Dirty Cypress rich text</p>', { .type('{selectAll}{backspace}Dirty Cypress rich text')
parseSpecialCharSequences: false,
})
cy.get('[data-cy="admin-element-save"]').click() cy.get('[data-cy="admin-element-save"]').click()
cy.get('[data-cy="admin-element-status"]') cy.get('[data-cy="admin-element-status"]')