feat: manage tenants and leases (#4)
This commit is contained in:
1 parent
26ab037084
commit
8603b98714
42 files changed
+3089
-18
No files matched your search
@@ -195,3 +195,106 @@ test('follows operating-system changes for the System theme', async ({ page }) =
|
||||
await page.emulateMedia({ colorScheme: 'light' });
|
||||
await expect(page.locator('html')).toHaveAttribute('data-theme', 'light');
|
||||
});
|
||||
|
||||
test('creates a tenant with an attachment and a lease with a guarantor', async ({ page }) => {
|
||||
const apartments = [
|
||||
{
|
||||
id: 'apartment-1',
|
||||
name: 'Studio République',
|
||||
address: '12 rue de la République, Lyon',
|
||||
purchasePrice: 150000,
|
||||
description: '',
|
||||
},
|
||||
];
|
||||
const tenants: Record<string, unknown>[] = [];
|
||||
const leases: Record<string, unknown>[] = [];
|
||||
|
||||
await mockUser(page, true);
|
||||
await page.route('**/api/apartments', (route) =>
|
||||
route.fulfill({ contentType: 'application/json', json: apartments }),
|
||||
);
|
||||
await page.route('**/api/tenants**', async (route) => {
|
||||
const request = route.request();
|
||||
const path = new URL(request.url()).pathname;
|
||||
if (request.method() === 'POST' && path.endsWith('/attachments')) {
|
||||
const attachment = {
|
||||
id: 'attachment-1',
|
||||
fileName: 'identite.pdf',
|
||||
contentType: 'application/pdf',
|
||||
size: 8,
|
||||
};
|
||||
(tenants[0]['attachments'] as Record<string, unknown>[]).push(attachment);
|
||||
await route.fulfill({ contentType: 'application/json', json: attachment });
|
||||
return;
|
||||
}
|
||||
if (request.method() === 'POST') {
|
||||
const tenant = { id: 'tenant-1', attachments: [], ...request.postDataJSON() };
|
||||
tenants.push(tenant);
|
||||
await route.fulfill({ contentType: 'application/json', json: tenant });
|
||||
return;
|
||||
}
|
||||
await route.fulfill({ contentType: 'application/json', json: tenants });
|
||||
});
|
||||
await page.route('**/api/leases**', async (route) => {
|
||||
const request = route.request();
|
||||
const path = new URL(request.url()).pathname;
|
||||
if (request.method() === 'GET' && path.endsWith('/pdf')) {
|
||||
await route.fulfill({
|
||||
contentType: 'application/pdf',
|
||||
headers: { 'Content-Disposition': 'attachment; filename="bail-lease-1.pdf"' },
|
||||
body: '%PDF-1.4\n%%EOF',
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (request.method() === 'POST') {
|
||||
const lease = { id: 'lease-1', ...request.postDataJSON() };
|
||||
leases.push(lease);
|
||||
await route.fulfill({ contentType: 'application/json', json: lease });
|
||||
return;
|
||||
}
|
||||
await route.fulfill({ contentType: 'application/json', json: leases });
|
||||
});
|
||||
|
||||
await page.goto('/');
|
||||
await page.getByTestId('primary-navigation').getByRole('button', { name: 'Locataires' }).click();
|
||||
await page.getByRole('button', { name: 'Ajouter un locataire' }).first().click();
|
||||
await page.getByLabel('Prénom', { exact: true }).fill('Camille');
|
||||
await page.getByLabel('Nom', { exact: true }).fill('Martin');
|
||||
await page.getByLabel('E-mail', { exact: true }).fill('camille@example.com');
|
||||
await page.getByLabel('Téléphone', { exact: true }).fill('+33612345678');
|
||||
await page.getByLabel('Adresse complète').fill('10 rue des Lilas, Lyon');
|
||||
await page.getByRole('button', { name: 'Enregistrer' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Camille Martin' })).toBeVisible();
|
||||
|
||||
await page.getByLabel('Ajouter une pièce jointe pour Camille Martin').setInputFiles({
|
||||
name: 'identite.pdf',
|
||||
mimeType: 'application/pdf',
|
||||
buffer: Buffer.from('identity'),
|
||||
});
|
||||
await expect(
|
||||
page.getByRole('button', { name: 'Télécharger la pièce jointe identite.pdf' }),
|
||||
).toBeVisible();
|
||||
|
||||
await page.getByTestId('primary-navigation').getByRole('button', { name: 'Baux' }).click();
|
||||
await page.getByRole('button', { name: 'Créer un bail' }).first().click();
|
||||
await page.getByLabel('Appartement').selectOption('apartment-1');
|
||||
await page.getByLabel('Locataire').selectOption('tenant-1');
|
||||
await page.getByLabel('Date de début').fill('2026-09-01');
|
||||
await page.getByLabel('Date de fin').fill('2027-08-31');
|
||||
await page.getByLabel('Loyer mensuel').fill('850');
|
||||
await page.getByLabel('Charges mensuelles').fill('50');
|
||||
await page.getByLabel('Dépôt de garantie').fill('850');
|
||||
await page.getByLabel('Prénom du garant').fill('Alex');
|
||||
await page.getByLabel('Nom du garant', { exact: true }).fill('Durand');
|
||||
await page.getByLabel('E-mail du garant').fill('alex@example.com');
|
||||
await page.getByRole('button', { name: 'Ajouter le garant' }).click();
|
||||
await page.getByRole('button', { name: 'Enregistrer le bail' }).click();
|
||||
|
||||
await expect(page.getByRole('heading', { name: 'Studio République' })).toBeVisible();
|
||||
await expect(page.getByText('Alex Durand')).toBeVisible();
|
||||
const downloadPromise = page.waitForEvent('download');
|
||||
await page.getByRole('button', { name: 'Télécharger le bail' }).click();
|
||||
const download = await downloadPromise;
|
||||
expect(download.suggestedFilename()).toBe('bail-lease-1.pdf');
|
||||
await expectNoHorizontalOverflow(page);
|
||||
});
|
||||
Reference in new issue
Block a user