mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-15 11:42:15 +01:00
update e2e test setup to use user settings api endpoint
This commit is contained in:
committed by
Constantin Graf
parent
e8c8edb4d5
commit
5dcd8197dc
@@ -12,7 +12,7 @@ import {
|
|||||||
createRunningTimeEntryWithStartViaApi,
|
createRunningTimeEntryWithStartViaApi,
|
||||||
createTaskViaApi,
|
createTaskViaApi,
|
||||||
createProjectWithClientViaApi,
|
createProjectWithClientViaApi,
|
||||||
updateUserProfileViaWeb,
|
updateUserProfileViaApi,
|
||||||
updateOrganizationSettingViaApi,
|
updateOrganizationSettingViaApi,
|
||||||
} from './utils/api';
|
} from './utils/api';
|
||||||
|
|
||||||
@@ -1803,28 +1803,22 @@ test.describe('Click-Drag Selection to Create', () => {
|
|||||||
// =============================================
|
// =============================================
|
||||||
|
|
||||||
test.describe('Timezone & Localization', () => {
|
test.describe('Timezone & Localization', () => {
|
||||||
test('week start day: monday shows Mon as first column', async ({ page }) => {
|
test('week start day: monday shows Mon as first column', async ({ page, ctx }) => {
|
||||||
// Navigate to calendar first to load Inertia page props
|
await updateUserProfileViaApi(ctx, { week_start: 'monday' });
|
||||||
await goToCalendar(page);
|
await goToCalendar(page);
|
||||||
await updateUserProfileViaWeb(page, { week_start: 'monday' });
|
|
||||||
await page.reload();
|
|
||||||
await expect(page.locator('.fc')).toBeVisible();
|
await expect(page.locator('.fc')).toBeVisible();
|
||||||
|
|
||||||
const firstHeader = page.locator('.fc-col-header-cell').first();
|
const firstHeader = page.locator('.fc-col-header-cell').first();
|
||||||
await expect(firstHeader).toContainText('Mon');
|
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 goToCalendar(page);
|
||||||
await updateUserProfileViaWeb(page, { week_start: 'sunday' });
|
|
||||||
await page.reload();
|
|
||||||
await expect(page.locator('.fc')).toBeVisible();
|
await expect(page.locator('.fc')).toBeVisible();
|
||||||
|
|
||||||
const firstHeader = page.locator('.fc-col-header-cell').first();
|
const firstHeader = page.locator('.fc-col-header-cell').first();
|
||||||
await expect(firstHeader).toContainText('Sun');
|
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 }) => {
|
test('12-hour time format shows AM/PM on slot labels', async ({ page, ctx }) => {
|
||||||
|
|||||||
@@ -804,53 +804,23 @@ export async function getCurrentUserViaApi(ctx: TestContext) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateUserProfileViaWeb(
|
export async function updateUserProfileViaApi(
|
||||||
page: Page,
|
ctx: TestContext,
|
||||||
settings: { timezone?: string; week_start?: string }
|
settings: { timezone?: string; week_start?: string }
|
||||||
) {
|
) {
|
||||||
// Read user info from Inertia's data-page attribute on the root element
|
const user = await getCurrentUserViaApi(ctx);
|
||||||
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 cookies = await page.context().cookies();
|
// Only send the fields under test; the endpoint leaves omitted fields untouched.
|
||||||
const xsrfCookie = cookies.find((c) => c.name === 'XSRF-TOKEN');
|
const data: Record<string, string> = {};
|
||||||
const xsrfToken = xsrfCookie ? decodeURIComponent(xsrfCookie.value) : '';
|
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`, {
|
const response = await ctx.request.put(`${PLAYWRIGHT_BASE_URL}/api/v1/users/${user.id}`, {
|
||||||
headers: {
|
data,
|
||||||
'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,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
expect(response.status()).toBe(200);
|
expect(response.status()).toBe(200);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user