Skip to content

Commit

Permalink
🚸(frontend) simplify invite user row logic in DocShareModal
Browse files Browse the repository at this point in the history
Refactor the endActions logic to show invite user row when searching by
email, removing the unnecessary length check for users
  • Loading branch information
PanchoutNathan authored and sampaccoud committed Jan 28, 2025
1 parent 609ff91 commit a39990d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 80 deletions.
46 changes: 23 additions & 23 deletions src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ test.beforeEach(async ({ page }) => {
});

test.describe('Doc Editor', () => {
test('it saves the doc when we quit pages', async ({ page, browserName }) => {
// eslint-disable-next-line playwright/no-skipped-test
test.skip(browserName === 'webkit', 'This test is very flaky with webkit');

// Check the first doc
const doc = await goToGridDoc(page);

await verifyDocName(page, doc);

const editor = page.locator('.ProseMirror');
await editor.click();
await editor.fill('Hello World Doc persisted 2');
await expect(editor.getByText('Hello World Doc persisted 2')).toBeVisible();

await page.goto('/');

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

await expect(editor.getByText('Hello World Doc persisted 2')).toBeVisible();
});

test('it check translations of the slash menu when changing language', async ({
page,
browserName,
Expand Down Expand Up @@ -241,29 +264,6 @@ test.describe('Doc Editor', () => {
await expect(editor.getByText('Hello World Doc persisted 1')).toBeVisible();
});

test('it saves the doc when we quit pages', async ({ page, browserName }) => {
// eslint-disable-next-line playwright/no-skipped-test
test.skip(browserName === 'webkit', 'This test is very flaky with webkit');

// Check the first doc
const doc = await goToGridDoc(page);

await verifyDocName(page, doc);

const editor = page.locator('.ProseMirror');
await editor.click();
await editor.fill('Hello World Doc persisted 2');
await expect(editor.getByText('Hello World Doc persisted 2')).toBeVisible();

await page.goto('/');

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

await expect(editor.getByText('Hello World Doc persisted 2')).toBeVisible();
});

test('it cannot edit if viewer', async ({ page }) => {
await mockedDocument(page, {
abilities: {
Expand Down
92 changes: 46 additions & 46 deletions src/frontend/apps/e2e/__tests__/app-impress/doc-visibility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,37 @@ test.describe('Doc Visibility', () => {
test.describe('Doc Visibility: Restricted', () => {
test.use({ storageState: { cookies: [], origins: [] } });

test('A doc is not accessible when not authentified.', async ({
page,
browserName,
}) => {
test('A doc is accessible when member.', async ({ page, browserName }) => {
test.slow();
await page.goto('/');
await keyCloakSignIn(page, browserName);

const [docTitle] = await createDoc(
page,
'Restricted no auth',
browserName,
1,
);
const [docTitle] = await createDoc(page, 'Restricted auth', browserName, 1);

await verifyDocName(page, docTitle);

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

const inputSearch = page.getByRole('combobox', {
name: 'Quick search input',
});

const otherBrowser = browsersName.find((b) => b !== browserName);
const username = `user@${otherBrowser}.e2e`;
await inputSearch.fill(username);
await page.getByRole('option', { name: username }).first().click();

// Choose a role
const container = page.getByTestId('doc-share-add-member-list');
await container.getByLabel('doc-role-dropdown').click();
await page.getByRole('button', { name: 'Administrator' }).click();

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

await page.locator('.c__modal__backdrop').click({
position: { x: 0, y: 0 },
});

const urlDoc = page.url();

await page
Expand All @@ -91,21 +106,27 @@ test.describe('Doc Visibility: Restricted', () => {
})
.click();

await expect(page.getByRole('button', { name: 'Sign in' })).toBeVisible();
await keyCloakSignIn(page, otherBrowser!);

await page.goto(urlDoc);

await expect(page.getByRole('textbox', { name: 'password' })).toBeVisible();
await verifyDocName(page, docTitle);
await expect(page.getByLabel('Share button')).toBeVisible();
});

test('A doc is not accessible when authentified but not member.', async ({
test('A doc is not accessible when not authentified.', async ({
page,
browserName,
}) => {
await page.goto('/');
await keyCloakSignIn(page, browserName);

const [docTitle] = await createDoc(page, 'Restricted auth', browserName, 1);
const [docTitle] = await createDoc(
page,
'Restricted no auth',
browserName,
1,
);

await verifyDocName(page, docTitle);

Expand All @@ -117,48 +138,24 @@ test.describe('Doc Visibility: Restricted', () => {
})
.click();

const otherBrowser = browsersName.find((b) => b !== browserName);

await keyCloakSignIn(page, otherBrowser!);
await expect(page.getByRole('button', { name: 'Sign in' })).toBeVisible();

await page.goto(urlDoc);

await expect(
page.getByText('You do not have permission to perform this action.'),
).toBeVisible();
await expect(page.getByRole('textbox', { name: 'password' })).toBeVisible();
});

test('A doc is accessible when member.', async ({ page, browserName }) => {
test.slow();
test('A doc is not accessible when authentified but not member.', async ({
page,
browserName,
}) => {
await page.goto('/');
await keyCloakSignIn(page, browserName);

const [docTitle] = await createDoc(page, 'Restricted auth', browserName, 1);

await verifyDocName(page, docTitle);

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

const inputSearch = page.getByRole('combobox', {
name: 'Quick search input',
});

const otherBrowser = browsersName.find((b) => b !== browserName);
const username = `user@${otherBrowser}.e2e`;
await inputSearch.fill(username);
await page.getByRole('option', { name: username }).click();

// Choose a role
const container = page.getByTestId('doc-share-add-member-list');
await container.getByLabel('doc-role-dropdown').click();
await page.getByRole('button', { name: 'Administrator' }).click();

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

await page.locator('.c__modal__backdrop').click({
position: { x: 0, y: 0 },
});

const urlDoc = page.url();

await page
Expand All @@ -167,12 +164,15 @@ test.describe('Doc Visibility: Restricted', () => {
})
.click();

const otherBrowser = browsersName.find((b) => b !== browserName);

await keyCloakSignIn(page, otherBrowser!);

await page.goto(urlDoc);

await verifyDocName(page, docTitle);
await expect(page.getByLabel('Share button')).toBeVisible();
await expect(
page.getByText('You do not have permission to perform this action.'),
).toBeVisible();
});
});

Expand Down
2 changes: 0 additions & 2 deletions src/frontend/apps/impress/.env
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
NEXT_PUBLIC_API_ORIGIN=
NEXT_PUBLIC_SW_DEACTIVATED=
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,14 @@ export const DocShareModal = ({ doc, onClose }: Props) => {
return {
groupName: t('Search user result'),
elements: users,
endActions:
isEmail && users.length === 0
? [
{
content: <DocShareModalInviteUserRow user={newUser} />,
onSelect: () => void onSelect(newUser),
},
]
: undefined,
endActions: isEmail
? [
{
content: <DocShareModalInviteUserRow user={newUser} />,
onSelect: () => void onSelect(newUser),
},
]
: undefined,
};
}, [searchUsersQuery.data, t, userQuery]);

Expand Down

0 comments on commit a39990d

Please sign in to comment.