fix: e2e size helper keeps the user's other appearance choices
It sent the size alone, which replaced the admin's saved mode, contrast and color. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+11
-5
@@ -1,10 +1,16 @@
|
||||
// Saves a size mode on the logged-in user's account (needs the redmine_tonalmine plugin).
|
||||
// No size resets the account to the default appearance.
|
||||
// Saves a size mode on the logged-in user's account (needs the redmine_tonalmine plugin). The user's
|
||||
// other choices (mode, contrast, color) are kept. No size removes the size choice again.
|
||||
// The page must be loaded after the last change, since the saved choice is read from it.
|
||||
export async function setSize(page, size) {
|
||||
const status = await page.evaluate(async (body) => {
|
||||
const status = await page.evaluate(async (size) => {
|
||||
// The plugin hands the saved choice to theme.js in <head>: Tonalmine.configure({..., user: {...}})
|
||||
const script = [...document.scripts].find((s) => s.text.includes('Tonalmine.configure('));
|
||||
const prefs = JSON.parse(script.text.match(/Tonalmine\.configure\((.*)\);/s)[1]).user;
|
||||
if (size) prefs.size = size;
|
||||
else delete prefs.size;
|
||||
const headers = { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest',
|
||||
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content };
|
||||
return (await fetch('/tonalmine/appearance', { method: 'PUT', headers, body: JSON.stringify(body) })).status;
|
||||
}, size ? { size } : {});
|
||||
return (await fetch('/tonalmine/appearance', { method: 'PUT', headers, body: JSON.stringify(prefs) })).status;
|
||||
}, size);
|
||||
if (status !== 204) throw new Error(`could not save size ${size ?? 'default'} (HTTP ${status})`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user