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