Skip to content

✨(frontend) Duplicate a doc #1078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to
### Added

- ✨(frontend) add customization for translations #857
- ✨(frontend) Duplicate a doc #1078

### Changed

Expand Down
33 changes: 32 additions & 1 deletion src/frontend/apps/e2e/__tests__/app-impress/doc-header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ test.describe('Doc Header', () => {
});

test('it pins a document', async ({ page, browserName }) => {
const [docTitle] = await createDoc(page, `Favorite doc`, browserName);
const [docTitle] = await createDoc(page, `Pin doc`, browserName);

await page.getByLabel('Open the document options').click();

Expand Down Expand Up @@ -456,6 +456,37 @@ test.describe('Doc Header', () => {
await expect(row.getByLabel('Pin document icon')).toBeHidden();
await expect(leftPanelFavorites.getByText(docTitle)).toBeHidden();
});

test('it duplicates a document', async ({ page, browserName }) => {
const [docTitle] = await createDoc(page, `Duplicate doc`, browserName);

const editor = page.locator('.ProseMirror');
await editor.click();
await editor.fill('Hello Duplicated World');

await page.reload();

await page.getByLabel('Open the document options').click();

await page.getByRole('menuitem', { name: 'Duplicate' }).click();
await expect(
page.getByText('Document duplicated successfully!'),
).toBeVisible();

await page.goto('/');

const duplicateTitle = 'Copy of ' + docTitle;

const row = await getGridRow(page, duplicateTitle);

await expect(row.getByText(duplicateTitle)).toBeVisible();

await row.getByText(`more_horiz`).click();
await page.getByRole('menuitem', { name: 'Duplicate' }).click();
const duplicateDuplicateTitle = 'Copy of ' + duplicateTitle;
await page.getByText(duplicateDuplicateTitle).click();
await expect(page.getByText('Hello Duplicated World')).toBeVisible();
});
});

test.describe('Documents Header mobile', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { renderHook, waitFor } from '@testing-library/react';

import { AppWrapper } from '@/tests/utils';

// Mock the environment variable
const originalEnv = process.env.NEXT_PUBLIC_PUBLISH_AS_MIT;

// Mock the libAGPL module
jest.mock(
'../../libAGPL',
() => ({
exportToPdf: jest.fn(),
exportToDocx: jest.fn(),
}),
{ virtual: true },
);

describe('useModuleExport', () => {
afterAll(() => {
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = originalEnv;
});

it('should load modules when NEXT_PUBLIC_PUBLISH_AS_MIT is false', async () => {
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = 'false';
const { useModuleExport } = await import('../useModuleExport');

const { result } = renderHook(() => useModuleExport(), {
wrapper: AppWrapper,
});

// Initial state should be undefined
expect(result.current).toBeUndefined();

// After effects run, it should contain the modules from libAGPL
await waitFor(() => {
expect(result.current).toBeDefined();
});

expect(result.current).toHaveProperty('exportToPdf');
expect(result.current).toHaveProperty('exportToDocx');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { renderHook } from '@testing-library/react';

import { AppWrapper } from '@/tests/utils';
import { sleep } from '@/utils';

const originalEnv = process.env.NEXT_PUBLIC_PUBLISH_AS_MIT;

describe('useModuleExport', () => {
afterAll(() => {
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = originalEnv;
});

it('should return null when NEXT_PUBLIC_PUBLISH_AS_MIT is true', async () => {
const { useModuleExport } = await import('../useModuleExport');

const { result } = renderHook(() => useModuleExport(), {
wrapper: AppWrapper,
});

expect(result.current).toBeUndefined();

await sleep(1000);

expect(result.current).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useEffect, useState } from 'react';

const modulesAGPL =
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT === 'false'
? import('../libAGPL')
: Promise.resolve(null);

export const useModuleExport = () => {
const [modules, setModules] = useState<Awaited<typeof modulesAGPL>>();

useEffect(() => {
const resolveModule = async () => {
const resolvedModules = await modulesAGPL;
if (!resolvedModules) {
return;
}
setModules(resolvedModules);
};
void resolveModule();
}, []);

return modules;
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './api';
export * from './components';
export * from './hooks/useModuleExport';
export * from './utils';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ModalExport } from './components';
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class TestAnalytic extends AbstractAnalytic {

jest.mock('@/features/docs/doc-export/', () => ({
ModalExport: () => <span>ModalExport</span>,
useModuleExport: () => ({
exportToPdf: jest.fn(),
exportToDocx: jest.fn(),
}),
}));

const doc = {
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading