template-saas-frontend-v2/tests/e2e/fixtures/tenant.fixture.ts
rckrdmrd eb95d0e276 Initial commit - Frontend de template-saas migrado desde monorepo
Migración desde workspace-v2/projects/template-saas/apps/frontend
Este repositorio es parte del estándar multi-repo v2

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 08:07:16 -06:00

111 lines
2.4 KiB
TypeScript

import { Page } from '@playwright/test';
// Test tenant data
export const testTenant = {
name: 'Test Company',
slug: 'test-company',
domain: 'test.example.com',
};
/**
* Create a new tenant via onboarding
*/
export async function createTenant(
page: Page,
tenantData: {
name: string;
slug?: string;
logoUrl?: string;
}
): Promise<void> {
// Assuming we're on the company step of onboarding
await page.fill('input[name="name"]', tenantData.name);
if (tenantData.slug) {
await page.fill('input[name="slug"]', tenantData.slug);
}
if (tenantData.logoUrl) {
await page.fill('input[name="logoUrl"]', tenantData.logoUrl);
}
}
/**
* Update tenant settings
*/
export async function updateTenantSettings(
page: Page,
settings: {
timezone?: string;
locale?: string;
currency?: string;
}
): Promise<void> {
await page.goto('/settings/company');
if (settings.timezone) {
await page.selectOption('select[name="timezone"]', settings.timezone);
}
if (settings.locale) {
await page.selectOption('select[name="locale"]', settings.locale);
}
if (settings.currency) {
await page.selectOption('select[name="currency"]', settings.currency);
}
await page.click('button[type="submit"]');
// Wait for success message
await page.waitForSelector('[data-testid="success-toast"]', { timeout: 5000 });
}
/**
* Invite team member
*/
export async function inviteTeamMember(
page: Page,
email: string,
role: 'admin' | 'member' | 'viewer' = 'member'
): Promise<void> {
await page.goto('/admin/team');
// Open invite modal
await page.click('[data-testid="invite-button"]');
// Fill invite form
await page.fill('input[name="email"]', email);
await page.selectOption('select[name="role"]', role);
// Submit
await page.click('[data-testid="send-invite-button"]');
// Wait for success
await page.waitForSelector('[data-testid="invite-success"]', { timeout: 5000 });
}
/**
* Get current tenant info from page
*/
export async function getCurrentTenant(page: Page): Promise<{
name: string;
slug: string;
} | null> {
try {
const tenantData = await page.evaluate(() => {
const tenantStore = (window as any).__TENANT_STORE__;
if (tenantStore) {
return {
name: tenantStore.tenant?.name,
slug: tenantStore.tenant?.slug,
};
}
return null;
});
return tenantData;
} catch {
return null;
}
}