From c6b123734bbc0676bd4a00c94aea5ae2ee209075 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 22 Oct 2023 14:21:13 +0200 Subject: [PATCH] feat(editor): add tests to check rendering of task description --- cypress/e2e/task/task.spec.ts | 72 +++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/cypress/e2e/task/task.spec.ts b/cypress/e2e/task/task.spec.ts index 5963a7597..b3f7876ba 100644 --- a/cypress/e2e/task/task.spec.ts +++ b/cypress/e2e/task/task.spec.ts @@ -721,5 +721,77 @@ This is a checklist: cy.get('.task-view .checklist-summary') .should('contain.text', '2 of 5 tasks') }) + + it('Should use the editor to render description', () => { + const tasks = TaskFactory.create(1, { + id: 1, + description: ` +

Lorem Ipsum

+

Dolor sit amet

+`, + }) + cy.visit(`/tasks/${tasks[0].id}`) + + cy.get('.tiptap__editor ul > li input[type=checkbox]') + .should('exist') + cy.get('.tiptap__editor h1') + .contains('Lorem Ipsum') + .should('exist') + cy.get('.tiptap__editor p') + .contains('Dolor sit amet') + .should('exist') + }) + + it.only('Should render an image from attachment', async () => { + + TaskAttachmentFactory.truncate() + + const tasks = TaskFactory.create(1, { + id: 1, + description: '', + }) + + cy.readFile('cypress/fixtures/image.jpg', null).then(file => { + + const formData = new FormData() + formData.append('files', new Blob([file]), 'image.jpg') + + cy.request({ + method: 'PUT', + url: `${Cypress.env('API_URL')}/tasks/${tasks[0].id}/attachments`, + headers: { + 'Authorization': `Bearer ${window.localStorage.getItem('token')}`, + 'Content-Type': 'multipart/form-data', + }, + body: formData, + }) + .then(({body}) => { + const dec = new TextDecoder('utf-8') + const {success} = JSON.parse(dec.decode(body)) + + TaskFactory.create(1, { + id: 1, + description: `test image`, + }) + + cy.visit(`/tasks/${tasks[0].id}`) + + cy.get('.tiptap__editor img') + .should('be.visible') + .and(($img) => { + // "naturalWidth" and "naturalHeight" are set when the image loads + expect($img[0].naturalWidth).to.be.greaterThan(0) + }) + + }) + }) + }) }) })