From a4c400ef4e72a96f70ae07fa3da05f2ed9a8315a Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Tue, 9 Jun 2026 16:13:09 +0200 Subject: [PATCH] update e2e test setup to use user settings api endpoint --- e2e/calendar.spec.ts | 16 ++++--------- e2e/utils/api.ts | 56 ++++++++++---------------------------------- 2 files changed, 18 insertions(+), 54 deletions(-) diff --git a/e2e/calendar.spec.ts b/e2e/calendar.spec.ts index 68c61814..ad063a8c 100644 --- a/e2e/calendar.spec.ts +++ b/e2e/calendar.spec.ts @@ -12,7 +12,7 @@ import { createRunningTimeEntryWithStartViaApi, createTaskViaApi, createProjectWithClientViaApi, - updateUserProfileViaWeb, + updateUserProfileViaApi, updateOrganizationSettingViaApi, } from './utils/api'; @@ -1803,28 +1803,22 @@ test.describe('Click-Drag Selection to Create', () => { // ============================================= test.describe('Timezone & Localization', () => { - test('week start day: monday shows Mon as first column', async ({ page }) => { - // Navigate to calendar first to load Inertia page props + test('week start day: monday shows Mon as first column', async ({ page, ctx }) => { + await updateUserProfileViaApi(ctx, { week_start: 'monday' }); await goToCalendar(page); - await updateUserProfileViaWeb(page, { week_start: 'monday' }); - await page.reload(); await expect(page.locator('.fc')).toBeVisible(); const firstHeader = page.locator('.fc-col-header-cell').first(); await expect(firstHeader).toContainText('Mon'); }); - test('week start day: sunday shows Sun as first column', async ({ page }) => { + test('week start day: sunday shows Sun as first column', async ({ page, ctx }) => { + await updateUserProfileViaApi(ctx, { week_start: 'sunday' }); await goToCalendar(page); - await updateUserProfileViaWeb(page, { week_start: 'sunday' }); - await page.reload(); await expect(page.locator('.fc')).toBeVisible(); const firstHeader = page.locator('.fc-col-header-cell').first(); await expect(firstHeader).toContainText('Sun'); - - // Reset to monday for other tests - await updateUserProfileViaWeb(page, { week_start: 'monday' }); }); test('12-hour time format shows AM/PM on slot labels', async ({ page, ctx }) => { diff --git a/e2e/utils/api.ts b/e2e/utils/api.ts index dc8dd312..e693529e 100644 --- a/e2e/utils/api.ts +++ b/e2e/utils/api.ts @@ -804,53 +804,23 @@ export async function getCurrentUserViaApi(ctx: TestContext) { }; } -export async function updateUserProfileViaWeb( - page: Page, +export async function updateUserProfileViaApi( + ctx: TestContext, settings: { timezone?: string; week_start?: string } ) { - // Read user info from Inertia's data-page attribute on the root element - const userInfo = await page.evaluate(() => { - // Try Inertia's data-page attribute (stores initial page props as JSON) - const appEl = document.getElementById('app'); - if (appEl) { - const dataPage = appEl.getAttribute('data-page'); - if (dataPage) { - try { - const parsed = JSON.parse(dataPage); - const user = parsed?.props?.auth?.user; - if (user) { - return { - name: user.name, - email: user.email, - timezone: user.timezone, - week_start: user.week_start, - }; - } - } catch { - // JSON parse failed - } - } - } - return null; - }); - if (!userInfo) throw new Error('Could not read user info from Inertia data-page attribute'); + const user = await getCurrentUserViaApi(ctx); - const cookies = await page.context().cookies(); - const xsrfCookie = cookies.find((c) => c.name === 'XSRF-TOKEN'); - const xsrfToken = xsrfCookie ? decodeURIComponent(xsrfCookie.value) : ''; + // Only send the fields under test; the endpoint leaves omitted fields untouched. + const data: Record = {}; + if (settings.timezone !== undefined) { + data.timezone = settings.timezone; + } + if (settings.week_start !== undefined) { + data.week_start = settings.week_start; + } - const response = await page.request.put(`${PLAYWRIGHT_BASE_URL}/user/profile-information`, { - headers: { - 'X-XSRF-TOKEN': xsrfToken, - 'Content-Type': 'application/json', - Accept: 'application/json', - }, - data: { - name: userInfo.name, - email: userInfo.email, - timezone: settings.timezone ?? userInfo.timezone, - week_start: settings.week_start ?? userInfo.week_start, - }, + const response = await ctx.request.put(`${PLAYWRIGHT_BASE_URL}/api/v1/users/${user.id}`, { + data, }); expect(response.status()).toBe(200); }