mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
A) Import "map members": clicking a searched user threw `TypeError: Cannot read properties of undefined (reading '_id')` at `click .js-select-import`. The handler read `Template.currentData()._id`, which is undefined when the click lands on a CHILD of the anchor (the avatar or the name span). Read the WeKan user id from the anchor's `data-id` (event.currentTarget) instead, and guard it — robust regardless of which inner node was clicked. B) Admin Panel / People: saving an IMPORTED (placeholder) user as an active person with an email threw `TypeError: Cannot read properties of undefined (reading '0')`. The profile submit handler read `user.emails[0].verified` (and `.address`), but an imported placeholder user (and some SSO users) have no `emails` array at all. Read the primary email defensively (missing OR empty array) via a `primaryEmail` guard. Tests: tests/importMapUserFixes.test.cjs; tests/importMemberMapping.test.cjs updated for the data-id mapping. Thanks to AmigaAbattoir and xet7 ! Fixes #6508,
68 lines
3.6 KiB
JavaScript
68 lines
3.6 KiB
JavaScript
'use strict';
|
|
|
|
// Guards for the JSON/board import "Assign members" (map members) step.
|
|
//
|
|
// A user reported (board migration from an old WeKan): in the "Select member" popup,
|
|
// typed suggestions appear but cannot be selected — neither clicking nor Enter assigns
|
|
// the user. Root cause: the click handler mapped `Template.currentData().__originalId`,
|
|
// a field that is NEVER set on the search results (they are plain WeKan user docs with
|
|
// `_id`), so it mapped `undefined` and silently did nothing. Fixed to map `._id`, plus
|
|
// Enter now selects the first result. Member mapping stays OPTIONAL: both a step-1
|
|
// "import without mapping" and an in-step "skip mapping" button import immediately.
|
|
//
|
|
// Run: node tests/importMemberMapping.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
const read = rel => fs.readFileSync(path.join(__dirname, '..', rel), 'utf8');
|
|
|
|
console.log('importMemberMapping:');
|
|
|
|
const js = read('client/components/import/import.js');
|
|
const jade = read('client/components/import/import.jade');
|
|
|
|
test('selecting a searched user maps its _id (not the never-set __originalId)', () => {
|
|
assert.ok(!/\.__originalId\b/.test(js), 'the bogus .__originalId property access must be gone');
|
|
// The click handler maps the clicked user document by _id.
|
|
const clickIdx = js.indexOf("'click .js-select-import'");
|
|
assert.ok(clickIdx > -1, 'the select-import click handler exists');
|
|
const clickBlock = js.slice(clickIdx, clickIdx + 1000);
|
|
assert.ok(/mapSelectedMember|importMapToUser/.test(clickBlock), 'the click maps the selected member');
|
|
// #6508: read the _id from the anchor's data-id (robust to a click on a child
|
|
// node), not Template.currentData() which is undefined there and threw.
|
|
assert.ok(/getAttribute\('data-id'\)/.test(clickBlock), 'maps the search result by its data-id');
|
|
assert.ok(!/Template\.currentData\(\)\._id/.test(js), 'must not read _id from Template.currentData() (child-click undefined)');
|
|
});
|
|
|
|
test('Enter selects the first search result (keyboard, no mouse needed)', () => {
|
|
assert.ok(/'keydown \.js-search-member-input'/.test(js), 'a keydown handler exists on the search input');
|
|
const kd = js.slice(js.indexOf("'keydown .js-search-member-input'"));
|
|
assert.ok(/keyCode === 13/.test(kd), 'Enter (13) is handled');
|
|
assert.ok(/results\[0\]\._id/.test(kd), 'Enter maps the first result by _id');
|
|
});
|
|
|
|
test('the search-result template binds each user by _id', () => {
|
|
assert.ok(/a\.name\.js-select-import\(title=.*data-id="\{\{_id\}\}"/.test(jade),
|
|
'each search result carries its user _id');
|
|
});
|
|
|
|
test('member mapping is OPTIONAL: skip buttons import immediately', () => {
|
|
// Step 1 (textarea): import without mapping at all.
|
|
assert.ok(/js-import-without-mapping/.test(jade), 'step-1 "import without mapping" button exists');
|
|
assert.ok(/'click \.js-import-without-mapping'/.test(js), 'its handler exists');
|
|
assert.ok(/importData\(evt, Session\.get\('importSource'\), true\)/.test(js),
|
|
'import without mapping calls importData with skipMapping=true');
|
|
// Map step: skip remaining mapping and import now.
|
|
assert.ok(/js-import-skip-mapping/.test(jade), 'in-step "skip mapping" button exists');
|
|
assert.ok(/'click \.js-import-skip-mapping'/.test(js), 'its handler exists');
|
|
// Both surfaces use the same clear label.
|
|
const en = JSON.parse(read('imports/i18n/data/en.i18n.json'));
|
|
assert.ok(typeof en['import-without-mapping-members'] === 'string', 'label i18n key exists');
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|