From e13ecdd38d8405bf152edce6bab0dfc9b5527b17 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Tue, 16 Apr 2024 16:55:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=94(app-impress)=20save=20the=20templa?= =?UTF-8?q?tes=20editor=20automatically?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On almost each change in the code editor, the template is saved automatically. It will restore as well the editor when we arrive on the template editor page. --- .../app-impress/template-editor.spec.ts | 33 ++++++++++++++ .../api/useUpdateTemplateCodeEditor.tsx | 39 ++++++++++++++++ .../template/components/TemplateEditor.tsx | 44 ++++++++++++++++++- .../src/features/templates/template/types.tsx | 3 ++ .../apps/impress/src/pages/templates/[id].tsx | 13 +++++- 5 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 src/frontend/apps/impress/src/features/templates/template/api/useUpdateTemplateCodeEditor.tsx diff --git a/src/frontend/apps/e2e/__tests__/app-impress/template-editor.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/template-editor.spec.ts index e8ea725a..5e5b2735 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/template-editor.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/template-editor.spec.ts @@ -26,4 +26,37 @@ test.describe('Template Editor', () => { page.locator('.gjs-editor .gjs-block[title="Text"]'), ).toBeVisible(); }); + + test('checks the template editor save on changed', async ({ + page, + browserName, + }) => { + const randomTemplate = await createTemplate( + page, + 'template-editor', + browserName, + 1, + ); + + await expect(page.locator('h2').getByText(randomTemplate[0])).toBeVisible(); + + const iframe = page.frameLocator('iFrame.gjs-frame'); + + await page.getByTitle('Open Blocks').click(); + await page + .locator('.gjs-editor .gjs-block[title="Text"]') + .dragTo(iframe.locator('body.gjs-dashed')); + + await iframe.getByText('Insert your text here').fill('Hello World'); + await iframe.locator('body.gjs-dashed').click(); + + // Come on the page again to check the changes are saved + await page.locator('menu').first().getByLabel(`Template button`).click(); + const panel = page.getByLabel('Templates panel').first(); + await panel.locator('li').getByText(randomTemplate[0]).click(); + + await expect(iframe.getByText('Hello World')).toBeVisible({ + timeout: 5000, + }); + }); }); diff --git a/src/frontend/apps/impress/src/features/templates/template/api/useUpdateTemplateCodeEditor.tsx b/src/frontend/apps/impress/src/features/templates/template/api/useUpdateTemplateCodeEditor.tsx new file mode 100644 index 00000000..520ae8eb --- /dev/null +++ b/src/frontend/apps/impress/src/features/templates/template/api/useUpdateTemplateCodeEditor.tsx @@ -0,0 +1,39 @@ +import { useMutation } from '@tanstack/react-query'; + +import { APIError, errorCauses, fetchAPI } from '@/api'; + +import { Template } from '../types'; + +type UpdateTemplateProps = Pick; + +export const updateTemplateCodeEditor = async ({ + code_editor, + id, +}: UpdateTemplateProps): Promise