mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 17:21:41 +10:00
This PR is handles the changes required to support envelopes. The new envelope editor/signing page will be hidden during release. The core changes here is to migrate the documents and templates model to a centralized envelopes model. Even though Documents and Templates are removed, from the user perspective they will still exist as we remap envelopes to documents and templates.
194 lines
6.6 KiB
TypeScript
194 lines
6.6 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
|
|
import {
|
|
mapSecondaryIdToDocumentId,
|
|
mapSecondaryIdToTemplateId,
|
|
} from '@documenso/lib/utils/envelope';
|
|
import { prisma } from '@documenso/prisma';
|
|
import {
|
|
seedTeamDocumentWithMeta,
|
|
seedTeamTemplateWithMeta,
|
|
} from '@documenso/prisma/seed/documents';
|
|
import { seedUser } from '@documenso/prisma/seed/users';
|
|
|
|
import { apiSignin } from '../fixtures/authentication';
|
|
|
|
test('[TEAMS]: check that default team signature settings are all enabled', async ({ page }) => {
|
|
const { user, team } = await seedUser();
|
|
|
|
await apiSignin({
|
|
page,
|
|
email: user.email,
|
|
redirectPath: `/t/${team.url}/settings/document`,
|
|
});
|
|
|
|
const document = await seedTeamDocumentWithMeta(team);
|
|
|
|
// Create a document and check the settings
|
|
await page.goto(
|
|
`/t/${team.url}/documents/${mapSecondaryIdToDocumentId(document.secondaryId)}/edit`,
|
|
);
|
|
|
|
// Verify that the settings match
|
|
await page.getByRole('button', { name: 'Advanced Options' }).click();
|
|
await expect(page.getByRole('combobox').filter({ hasText: 'Type' })).toBeVisible();
|
|
await expect(page.getByRole('combobox').filter({ hasText: 'Upload' })).toBeVisible();
|
|
await expect(page.getByRole('combobox').filter({ hasText: 'Draw' })).toBeVisible();
|
|
|
|
// Go to document and check that the signatured tabs are correct.
|
|
await page.goto(`/sign/${document.recipients[0].token}`);
|
|
await page.getByTestId('signature-pad-dialog-button').click();
|
|
|
|
// Check the tab values
|
|
await expect(page.getByRole('tab', { name: 'Type' })).toBeVisible();
|
|
await expect(page.getByRole('tab', { name: 'Upload' })).toBeVisible();
|
|
await expect(page.getByRole('tab', { name: 'Draw' })).toBeVisible();
|
|
});
|
|
|
|
test('[TEAMS]: check signature modes can be disabled', async ({ page }) => {
|
|
const { user, team } = await seedUser();
|
|
|
|
await apiSignin({
|
|
page,
|
|
email: user.email,
|
|
redirectPath: `/t/${team.url}/settings/document`,
|
|
});
|
|
|
|
const allTabs = ['Type', 'Upload', 'Draw'];
|
|
const tabTest = [['Type', 'Upload', 'Draw'], ['Type', 'Upload'], ['Type']];
|
|
|
|
for (const tabs of tabTest) {
|
|
await page.goto(`/t/${team.url}/settings/document`);
|
|
|
|
// Update combobox to have the correct tabs
|
|
await page.getByTestId('signature-types-trigger').click();
|
|
|
|
await expect(page.getByRole('option', { name: 'Type' })).toBeVisible();
|
|
await expect(page.getByRole('option', { name: 'Upload' })).toBeVisible();
|
|
await expect(page.getByRole('option', { name: 'Draw' })).toBeVisible();
|
|
|
|
// Clear all selected items.
|
|
for (const tab of allTabs) {
|
|
const item = page.getByRole('option', { name: tab });
|
|
|
|
const isSelected = (await item.innerHTML()).includes('opacity-100');
|
|
|
|
if (isSelected) {
|
|
await item.click();
|
|
}
|
|
}
|
|
|
|
// Selected wanted items.
|
|
for (const tab of tabs) {
|
|
const item = page.getByRole('option', { name: tab });
|
|
await item.click();
|
|
}
|
|
|
|
await page.getByRole('button', { name: 'Update' }).first().click();
|
|
|
|
// Wait for the update to complete
|
|
const toast = page.locator('li[role="status"][data-state="open"]').first();
|
|
await expect(toast).toBeVisible();
|
|
await expect(toast.getByText('Document preferences updated', { exact: true })).toBeVisible();
|
|
|
|
const document = await seedTeamDocumentWithMeta(team);
|
|
|
|
// Go to document and check that the signature tabs are correct.
|
|
await page.goto(`/sign/${document.recipients[0].token}`);
|
|
await page.getByTestId('signature-pad-dialog-button').click();
|
|
|
|
// Wait for signature dialog to fully load
|
|
await page.waitForSelector('[role="dialog"]');
|
|
|
|
// Check the tab values
|
|
for (const tab of allTabs) {
|
|
if (tabs.includes(tab)) {
|
|
await expect(page.getByRole('tab', { name: tab })).toBeVisible();
|
|
} else {
|
|
// await expect(page.getByRole('tab', { name: tab })).not.toBeVisible();
|
|
await expect(page.getByRole('tab', { name: tab })).toHaveCount(0);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
test('[TEAMS]: check signature modes work for templates', async ({ page }) => {
|
|
const { user, team } = await seedUser();
|
|
|
|
await apiSignin({
|
|
page,
|
|
email: user.email,
|
|
redirectPath: `/t/${team.url}/settings/document`,
|
|
});
|
|
|
|
const allTabs = ['Type', 'Upload', 'Draw'];
|
|
const tabTest = [['Type', 'Upload', 'Draw'], ['Type', 'Upload'], ['Type']];
|
|
|
|
for (const tabs of tabTest) {
|
|
await page.goto(`/t/${team.url}/settings/document`);
|
|
|
|
// Update combobox to have the correct tabs
|
|
await page.getByTestId('signature-types-trigger').click();
|
|
|
|
await expect(page.getByRole('option', { name: 'Type' })).toBeVisible();
|
|
await expect(page.getByRole('option', { name: 'Upload' })).toBeVisible();
|
|
await expect(page.getByRole('option', { name: 'Draw' })).toBeVisible();
|
|
|
|
// Clear all selected items.
|
|
for (const tab of allTabs) {
|
|
const item = page.getByRole('option', { name: tab });
|
|
|
|
const isSelected = (await item.innerHTML()).includes('opacity-100');
|
|
|
|
if (isSelected) {
|
|
await item.click();
|
|
}
|
|
}
|
|
|
|
// Selected wanted items.
|
|
for (const tab of tabs) {
|
|
const item = page.getByRole('option', { name: tab });
|
|
await item.click();
|
|
}
|
|
|
|
await page.getByRole('button', { name: 'Update' }).first().click();
|
|
|
|
// Wait for finish
|
|
const toast = page.locator('li[role="status"][data-state="open"]').first();
|
|
await expect(toast).toBeVisible();
|
|
await expect(toast.getByText('Document preferences updated', { exact: true })).toBeVisible();
|
|
|
|
const template = await seedTeamTemplateWithMeta(team);
|
|
|
|
await page.goto(`/t/${team.url}/templates/${mapSecondaryIdToTemplateId(template.secondaryId)}`);
|
|
await page.getByRole('button', { name: 'Use' }).click();
|
|
|
|
// Check the send document checkbox to true
|
|
await page.getByLabel('Send document').click();
|
|
await page.getByRole('button', { name: 'Create and send' }).click();
|
|
await page.waitForTimeout(1000);
|
|
|
|
const document = await prisma.envelope.findFirst({
|
|
where: {
|
|
// Created from template
|
|
templateId: mapSecondaryIdToTemplateId(template.secondaryId),
|
|
},
|
|
include: {
|
|
documentMeta: true,
|
|
},
|
|
});
|
|
|
|
// Test kinda flaky, debug here.
|
|
// console.log({
|
|
// tabs,
|
|
// typedSignatureEnabled: document?.documentMeta?.typedSignatureEnabled,
|
|
// uploadSignatureEnabled: document?.documentMeta?.uploadSignatureEnabled,
|
|
// drawSignatureEnabled: document?.documentMeta?.drawSignatureEnabled,
|
|
// });
|
|
|
|
expect(document?.documentMeta?.typedSignatureEnabled).toEqual(tabs.includes('Type'));
|
|
expect(document?.documentMeta?.uploadSignatureEnabled).toEqual(tabs.includes('Upload'));
|
|
expect(document?.documentMeta?.drawSignatureEnabled).toEqual(tabs.includes('Draw'));
|
|
}
|
|
});
|