Skip to content

Commit

Permalink
♻️(frontend) add versions in the panel editor
Browse files Browse the repository at this point in the history
We add the features version to the panel editor.
We had to refactor the panel to be able to
have the version with the table of content in
the same panel.
  • Loading branch information
AntoLC committed Sep 30, 2024
1 parent d389028 commit 87bfb70
Show file tree
Hide file tree
Showing 20 changed files with 599 additions and 288 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to
## Added

- ✨(ci) add security scan #291
- ✨(frontend) Activate versions feature #240

## Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from '@playwright/test';

import { createDoc } from './common';
import { createDoc, goToGridDoc } from './common';

test.beforeEach(async ({ page }) => {
await page.goto('/');
Expand Down Expand Up @@ -33,6 +33,7 @@ test.describe('Doc Table Content', () => {
await editor.getByText('Hello').dblclick();
await page.getByRole('button', { name: 'Strike' }).click();

await page.locator('.bn-block-outer').first().click();
await page.locator('.bn-block-outer').last().click();

// Create space to fill the viewport
Expand Down Expand Up @@ -92,4 +93,45 @@ test.describe('Doc Table Content', () => {
await expect(editor.getByText('Hello World')).not.toBeInViewport();
await expect(superW).toHaveAttribute('aria-selected', 'true');
});

test('it checks that table contents panel is opened automaticaly if more that 2 headings', async ({
page,
browserName,
}) => {
const [randomDoc] = await createDoc(
page,
'doc-table-content',
browserName,
1,
);

await expect(page.locator('h2').getByText(randomDoc)).toBeVisible();
await expect(page.getByLabel('Open the panel')).toBeHidden();

const editor = page.locator('.ProseMirror');

await editor.locator('.bn-block-outer').last().fill('/');
await page.getByText('Heading 1').click();
await page.keyboard.type('Hello World', { delay: 100 });

await page.keyboard.press('Enter');

await editor.locator('.bn-block-outer').last().fill('/');
await page.getByText('Heading 2').click();
await page.keyboard.type('Super World', { delay: 100 });

await goToGridDoc(page, {
title: randomDoc,
});

await expect(page.getByLabel('Close the panel')).toBeVisible();

const panel = page.getByLabel('Document panel');
await expect(panel.getByText('Hello World')).toBeVisible();
await expect(panel.getByText('Super World')).toBeVisible();

await page.getByLabel('Close the panel').click();

await expect(panel).toHaveAttribute('aria-hidden', 'true');
});
});
205 changes: 205 additions & 0 deletions src/frontend/apps/e2e/__tests__/app-impress/doc-version.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
import { expect, test } from '@playwright/test';

import { createDoc, goToGridDoc, mockedDocument } from './common';

test.beforeEach(async ({ page }) => {
await page.goto('/');
});

test.describe('Doc Version', () => {
test('it displays the doc versions', async ({ page, browserName }) => {
const [randomDoc] = await createDoc(page, 'doc-version', browserName, 1);

await expect(page.locator('h2').getByText(randomDoc)).toBeVisible();

await page.getByLabel('Open the document options').click();
await page
.getByRole('button', {
name: 'Version history',
})
.click();

const panel = page.getByLabel('Document panel');

await expect(panel.getByText('Current version')).toBeVisible();
expect(await panel.locator('li').count()).toBe(1);

await page.locator('.ProseMirror.bn-editor').click();
await page.locator('.ProseMirror.bn-editor').last().fill('Hello World');

await goToGridDoc(page, {
title: randomDoc,
});

await expect(page.getByText('Hello World')).toBeVisible();

await page
.locator('.ProseMirror .bn-block')
.getByText('Hello World')
.fill('It will create a version');

await goToGridDoc(page, {
title: randomDoc,
});

await expect(page.getByText('Hello World')).toBeHidden();
await expect(page.getByText('It will create a version')).toBeVisible();

await page.getByLabel('Open the document options').click();
await page
.getByRole('button', {
name: 'Version history',
})
.click();

await expect(panel.getByText('Current version')).toBeVisible();
expect(await panel.locator('li').count()).toBe(2);

await panel.locator('li').nth(1).click();
await expect(
page.getByText('Read only, you cannot edit document versions.'),
).toBeVisible();
await expect(page.getByText('Hello World')).toBeVisible();
await expect(page.getByText('It will create a version')).toBeHidden();

await panel.getByText('Current version').click();
await expect(page.getByText('Hello World')).toBeHidden();
await expect(page.getByText('It will create a version')).toBeVisible();
});

test('it does not display the doc versions if not allowed', async ({
page,
}) => {
await mockedDocument(page, {
abilities: {
versions_list: false,
partial_update: true,
},
});

await goToGridDoc(page);

await expect(page.locator('h2').getByText('Mocked document')).toBeVisible();

await page.getByLabel('Open the document options').click();
await expect(
page.getByRole('button', { name: 'Version history' }),
).toBeHidden();

await page.getByRole('button', { name: 'Table of content' }).click();

await expect(
page.getByLabel('Document panel').getByText('Versions'),
).toBeHidden();
});

test('it restores the doc version', async ({ page, browserName }) => {
const [randomDoc] = await createDoc(page, 'doc-version', browserName, 1);

await expect(page.locator('h2').getByText(randomDoc)).toBeVisible();

await page.locator('.bn-block-outer').last().click();
await page.locator('.bn-block-outer').last().fill('Hello');

await goToGridDoc(page, {
title: randomDoc,
});

await expect(page.getByText('Hello')).toBeVisible();
await page.locator('.bn-block-outer').last().click();
await page.keyboard.press('Enter');
await page.locator('.bn-block-outer').last().fill('World');

await goToGridDoc(page, {
title: randomDoc,
});

await expect(page.getByText('World')).toBeVisible();

await page.getByLabel('Open the document options').click();
await page
.getByRole('button', {
name: 'Version history',
})
.click();

const panel = page.getByLabel('Document panel');
await panel.locator('li').nth(1).click();
await expect(page.getByText('World')).toBeHidden();

await panel.getByLabel('Open the version options').click();
await page.getByText('Restore the version').click();

await expect(page.getByText('Restore this version?')).toBeVisible();

await page
.getByRole('button', {
name: 'Restore',
})
.click();

await expect(panel.locator('li')).toHaveCount(3);

await panel.getByText('Current version').click();
await expect(page.getByText('Hello')).toBeVisible();
await expect(page.getByText('World')).toBeHidden();
});

test('it restores the doc version from button title', async ({
page,
browserName,
}) => {
const [randomDoc] = await createDoc(page, 'doc-version', browserName, 1);

await expect(page.locator('h2').getByText(randomDoc)).toBeVisible();

await page.locator('.bn-block-outer').last().click();
await page.locator('.bn-block-outer').last().fill('Hello');

await goToGridDoc(page, {
title: randomDoc,
});

await expect(page.getByText('Hello')).toBeVisible();
await page.locator('.bn-block-outer').last().click();
await page.keyboard.press('Enter');
await page.locator('.bn-block-outer').last().fill('World');

await goToGridDoc(page, {
title: randomDoc,
});

await expect(page.getByText('World')).toBeVisible();

await page.getByLabel('Open the document options').click();
await page
.getByRole('button', {
name: 'Version history',
})
.click();

const panel = page.getByLabel('Document panel');
await panel.locator('li').nth(1).click();
await expect(page.getByText('World')).toBeHidden();

await page
.getByRole('button', {
name: 'Restore this version',
})
.click();

await expect(page.getByText('Restore this version?')).toBeVisible();

await page
.getByRole('button', {
name: 'Restore',
})
.click();

await expect(panel.locator('li')).toHaveCount(3);

await panel.getByText('Current version').click();
await expect(page.getByText('Hello')).toBeVisible();
await expect(page.getByText('World')).toBeHidden();
});
});
106 changes: 0 additions & 106 deletions src/frontend/apps/impress/src/components/Panel.tsx

This file was deleted.

Loading

0 comments on commit 87bfb70

Please sign in to comment.