test: stabilize milestone login

This commit is contained in:
zhi
2026-03-15 21:57:22 +00:00
parent f5065173b3
commit a26f91c95f

View File

@@ -9,16 +9,42 @@ test.describe('Milestone Editor', () => {
test('login -> create project -> create milestone through frontend form', async ({ page }) => { test('login -> create project -> create milestone through frontend form', async ({ page }) => {
// Step 1: Login // Step 1: Login
console.log('🔐 Logging in...'); console.log('🔐 Logging in...');
page.on('requestfailed', request => {
if (request.url().includes('/auth/token')) {
console.log('Login request failed:', request.failure()?.errorText);
}
});
await page.goto(`${BASE_URL}/login`); await page.goto(`${BASE_URL}/login`);
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle');
await page.fill('input[type="text"], input[name="username"]', ADMIN_USERNAME); await page.fill('input[type="text"], input[name="username"]', ADMIN_USERNAME);
await page.fill('input[type="password"], input[name="password"]', ADMIN_PASSWORD); await page.fill('input[type="password"], input[name="password"]', ADMIN_PASSWORD);
const loginPromise = page.waitForResponse(response =>
response.url().includes('/auth/token') && response.request().method() === 'POST'
, { timeout: 10000 }).catch(() => null);
await page.click('button[type="submit"], button:has-text("Sign in")'); await page.click('button[type="submit"], button:has-text("Sign in")');
const loginResponse = await loginPromise;
if (loginResponse) {
console.log('Login response status:', loginResponse.status());
console.log('Login response:', (await loginResponse.text()).substring(0, 200));
} else {
console.log('No /auth/token response');
}
// Wait for navigation // Wait for navigation
await page.waitForURL(`${BASE_URL}/**`, { timeout: 10000 }); await page.waitForURL(`${BASE_URL}/**`, { timeout: 10000 });
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle');
const token = await page.evaluate(() => localStorage.getItem('token'));
console.log('Token after login:', token ? 'present' : 'missing');
console.log('Current URL:', page.url());
await page.waitForSelector('a:has-text("📁 Projects")', { timeout: 10000 });
console.log('✅ Logged in'); console.log('✅ Logged in');
// Step 2: Create Project // Step 2: Create Project