mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
The users schema stored profile.keyboardShortcuts: false for every new user, while isKeyboardShortcuts() treats a missing value as on (keyboard shortcuts are on by default). So a new account had shortcuts off until it turned them off and on again. The schema default is now true, and a test pins every profile boolean's schema default to the default its helper reads. With no card opened, d on a hovered or selected minicard - the card the other card shortcuts act on - now opens that card and its Due date editor, instead of doing nothing until the card was opened. A card the user may not edit is not opened, and nothing happens with shortcuts off. Thanks to mimZD and xet7 ! Fixes #6755.
44 lines
2.2 KiB
JavaScript
44 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
// #6755: "shortcut not working ... i have to disable and reenable shortcuts".
|
|
// The users schema stored profile.keyboardShortcuts: false for every new user
|
|
// (defaultValue: false) while isKeyboardShortcuts() treats a missing value as
|
|
// ON (`keyboardShortcuts = true`, since "Enable keyboard shortcuts by
|
|
// default"). So new accounts had shortcuts off while the code meant them on,
|
|
// until the user toggled them off and on.
|
|
//
|
|
// This pins it for every profile boolean, not only that one: wherever a helper
|
|
// in models/users.js reads `const { name = X } = this.profile`, the schema's
|
|
// defaultValue for 'profile.name' must be the same X.
|
|
// Run: node tests/profileBooleanDefaults.test.cjs
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const users = fs.readFileSync(path.join(__dirname, '..', 'models', 'users.js'), 'utf8');
|
|
|
|
const schemaDefaults = new Map();
|
|
const schemaRe = /'profile\.(\w+)':\s*\{[^{}]*?type:\s*Boolean,[^{}]*?defaultValue:\s*(true|false)/g;
|
|
for (const m of users.matchAll(schemaRe)) schemaDefaults.set(m[1], m[2] === 'true');
|
|
|
|
const helperDefaults = [];
|
|
const helperRe = /const \{ (\w+) = (true|false) \} = this\.profile/g;
|
|
for (const m of users.matchAll(helperRe)) helperDefaults.push([m[1], m[2] === 'true']);
|
|
|
|
assert.ok(schemaDefaults.has('keyboardShortcuts'), 'the schema declares profile.keyboardShortcuts');
|
|
assert.equal(schemaDefaults.get('keyboardShortcuts'), true, 'keyboard shortcuts are on for a new user');
|
|
assert.ok(helperDefaults.some(([name]) => name === 'keyboardShortcuts'));
|
|
// Not vacuous: several profile booleans are read with a default.
|
|
assert.ok(helperDefaults.length >= 3, `helpers with a default were found (${helperDefaults.length})`);
|
|
|
|
// Negative: no profile boolean anywhere is stored with one default and read
|
|
// with the other.
|
|
for (const [name, helperDefault] of helperDefaults) {
|
|
if (!schemaDefaults.has(name)) continue;
|
|
assert.equal(schemaDefaults.get(name), helperDefault,
|
|
`profile.${name}: the schema stores ${schemaDefaults.get(name)} for a new user but the helper defaults to ${helperDefault}`);
|
|
}
|
|
|
|
console.log(`profileBooleanDefaults: ${helperDefaults.length} profile defaults agree with the schema`);
|