♻️(frontend) one click create doc
We can now create a doc in one click. The doc will be created with a default name, the user will be able to edit the name inline.
This commit is contained in:
@@ -13,6 +13,7 @@ and this project adheres to
|
|||||||
|
|
||||||
- ✨(ci) add security scan #291
|
- ✨(ci) add security scan #291
|
||||||
- ✨(frontend) Activate versions feature #240
|
- ✨(frontend) Activate versions feature #240
|
||||||
|
- ✨(frontend) one-click document creation #275
|
||||||
|
|
||||||
## Changed
|
## Changed
|
||||||
|
|
||||||
|
|||||||
@@ -7,48 +7,12 @@ test.beforeEach(async ({ page }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test.describe('Doc Create', () => {
|
test.describe('Doc Create', () => {
|
||||||
test('checks all the create doc elements are visible', async ({ page }) => {
|
|
||||||
const buttonCreateHomepage = page.getByRole('button', {
|
|
||||||
name: 'Create a new document',
|
|
||||||
});
|
|
||||||
await buttonCreateHomepage.click();
|
|
||||||
await expect(buttonCreateHomepage).toBeHidden();
|
|
||||||
|
|
||||||
const card = page.getByRole('dialog').first();
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
card.locator('h2').getByText('Create a new document'),
|
|
||||||
).toBeVisible();
|
|
||||||
await expect(card.getByLabel('Document name')).toBeVisible();
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
card.getByRole('button', {
|
|
||||||
name: 'Create the document',
|
|
||||||
}),
|
|
||||||
).toBeVisible();
|
|
||||||
|
|
||||||
await expect(card.getByLabel('Close the modal')).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('checks the cancel button interaction', async ({ page }) => {
|
|
||||||
const buttonCreateHomepage = page.getByRole('button', {
|
|
||||||
name: 'Create a new document',
|
|
||||||
});
|
|
||||||
await buttonCreateHomepage.click();
|
|
||||||
await expect(buttonCreateHomepage).toBeHidden();
|
|
||||||
|
|
||||||
const card = page.getByRole('dialog').first();
|
|
||||||
|
|
||||||
await card.getByLabel('Close the modal').click();
|
|
||||||
|
|
||||||
await expect(buttonCreateHomepage).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('it creates a doc', async ({ page, browserName }) => {
|
test('it creates a doc', async ({ page, browserName }) => {
|
||||||
const [docTitle] = await createDoc(page, 'My new doc', browserName, 1);
|
const [docTitle] = await createDoc(page, 'My new doc', browserName, 1);
|
||||||
|
|
||||||
expect(await page.locator('title').textContent()).toMatch(
|
await page.waitForFunction(
|
||||||
/My new doc - Docs/,
|
() => document.title.match(/My new doc - Docs/),
|
||||||
|
{ timeout: 5000 },
|
||||||
);
|
);
|
||||||
|
|
||||||
const header = page.locator('header').first();
|
const header = page.locator('header').first();
|
||||||
@@ -59,7 +23,8 @@ test.describe('Doc Create', () => {
|
|||||||
.getByRole('table');
|
.getByRole('table');
|
||||||
|
|
||||||
await expect(datagrid.getByLabel('Loading data')).toBeHidden();
|
await expect(datagrid.getByLabel('Loading data')).toBeHidden();
|
||||||
|
await expect(datagrid.getByText(docTitle)).toBeVisible({
|
||||||
await expect(datagrid.getByText(docTitle)).toBeVisible();
|
timeout: 5000,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,6 +5,14 @@ import { AppWrapper } from '@/tests/utils';
|
|||||||
|
|
||||||
import Page from '../pages';
|
import Page from '../pages';
|
||||||
|
|
||||||
|
jest.mock('next/navigation', () => ({
|
||||||
|
useRouter() {
|
||||||
|
return {
|
||||||
|
push: jest.fn(),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
describe('Page', () => {
|
describe('Page', () => {
|
||||||
it('checks Page rendering', () => {
|
it('checks Page rendering', () => {
|
||||||
render(<Page />, { wrapper: AppWrapper });
|
render(<Page />, { wrapper: AppWrapper });
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
export * from './useCreateDoc';
|
||||||
export * from './useDoc';
|
export * from './useDoc';
|
||||||
export * from './useDocs';
|
export * from './useDocs';
|
||||||
export * from './useUpdateDoc';
|
export * from './useUpdateDoc';
|
||||||
|
|||||||
@@ -1,33 +1,34 @@
|
|||||||
import { Button } from '@openfun/cunningham-react';
|
import { Button } from '@openfun/cunningham-react';
|
||||||
import React, { useState } from 'react';
|
import { useRouter } from 'next/navigation';
|
||||||
|
import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { Box, Card } from '@/components';
|
import { Box } from '@/components';
|
||||||
import { ModalCreateDoc } from '@/features/docs/doc-management';
|
import { useCreateDoc, useTrans } from '@/features/docs/doc-management/';
|
||||||
|
|
||||||
import { DocsGrid } from './DocsGrid';
|
import { DocsGrid } from './DocsGrid';
|
||||||
|
|
||||||
export const DocsGridContainer = () => {
|
export const DocsGridContainer = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isModalCreateOpen, setIsModalCreateOpen] = useState(false);
|
const { untitledDocument } = useTrans();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const { mutate: createDoc } = useCreateDoc({
|
||||||
|
onSuccess: (doc) => {
|
||||||
|
router.push(`/docs/${doc.id}`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleCreateDoc = () => {
|
||||||
|
createDoc({ title: untitledDocument });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box $overflow="auto">
|
<Box $overflow="auto">
|
||||||
<Card $margin="big" $padding="tiny">
|
<Box $align="flex-end" $justify="center" $margin="big">
|
||||||
<Box $align="flex-end" $justify="center">
|
<Button onClick={handleCreateDoc}>{t('Create a new document')}</Button>
|
||||||
<Button
|
</Box>
|
||||||
onClick={() => {
|
|
||||||
setIsModalCreateOpen(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t('Create a new document')}
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
</Card>
|
|
||||||
<DocsGrid />
|
<DocsGrid />
|
||||||
{isModalCreateOpen && (
|
|
||||||
<ModalCreateDoc onClose={() => setIsModalCreateOpen(false)} />
|
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user