mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 09:45:04 -05:00
A list's Add card form stayed open after a card was added, for the next card, which the reporter found unexpected. It now closes once the card - or every card of a multi-line paste - is added. Member Settings has a new switch, "Keep the Add card form open after adding a card", off by default, for who types several cards in a row. The close happens after the last title, not at submit, because addCard still reads the form between the titles of a paste; a failed add keeps the form and its text. The two new strings are translated into every locale. Low confidence: ace, ak, am, an, ary, as, ast-ES, ay, ba, bho, bi, bm, bo, br, bua, chr, ckb, co, csb, cv, dz, ee, ff, fj, fo, fur, gn, gv, ha, haw, hsb, ig, iu, kl, kok, ks, kw, lb, lg, lld, mai, mg, nah, nap, nd, nso, ny, om, or_IN, pap, ps, qu, rn, rup, rw, sah, sc, scn, sd, se, sm, sn, so, ss, st, szl, ti, tig, tlh, tn, to, tpi, ts, uz-AR, ve, ve-CC, ve-PP, vo, wa, wa-RR, wal, wo, wuu-Hans, zgh. tests/keepAddCardFormOpen6827.test.cjs pins the switch, its default and where the form is closed, with negative cases for a paste and a failure. tests/playwright/specs/keep-add-card-form-open-6827.e2e.js drives it: closed after one card and after a paste, kept open with an empty title once the switch is on. multiline-titles opens the form again for its second card, and assist-due-from-title keeps it open to check the next card's form has no leftover hint. Thanks to brlin-tw and xet7 ! Fixes #6827,
56 lines
3.7 KiB
JavaScript
56 lines
3.7 KiB
JavaScript
'use strict';
|
|
|
|
// #6827: a list's Add card form stayed open after a card was added, for the
|
|
// next card ("We keep the form opened"). It closes now once the card is added;
|
|
// keeping it open is a Member Settings switch, off by default.
|
|
// Run: node tests/keepAddCardFormOpen6827.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const read = rel => fs.readFileSync(path.join(__dirname, '..', rel), 'utf8');
|
|
let passed = 0;
|
|
const test = (name, fn) => { fn(); passed += 1; console.log(' ok -', name); };
|
|
console.log('keepAddCardFormOpen6827:');
|
|
|
|
const body = read('client/components/lists/listBody.js');
|
|
const addCard = body.slice(body.indexOf('this.addCard = async (evt) => {'), body.indexOf('this.clickOnMiniCard'));
|
|
|
|
test('a Member Settings switch, off unless explicitly on', () => {
|
|
const users = read('models/users.js');
|
|
assert.match(users, /'profile\.keepAddCardFormOpen': \{[\s\S]{0,400}type: Boolean,\n\s+optional: true,/);
|
|
assert.match(users, /hasKeepAddCardFormOpen\(\) \{\n\s+return \(this\.profile \|\| \{\}\)\.keepAddCardFormOpen === true;/);
|
|
const server = read('server/models/users.js');
|
|
assert.match(server, /async toggleKeepAddCardFormOpen\(\) \{\n\s+if \(!this\.userId\) throw new Meteor\.Error\('not-logged-in'/);
|
|
assert.match(server, /\$set: \{ 'profile\.keepAddCardFormOpen': \(user\.profile \|\| \{\}\)\.keepAddCardFormOpen !== true \}/);
|
|
const jade = read('client/components/users/userHeader.jade');
|
|
assert.match(jade, /a\.js-toggle-keep-add-card-form-open\(title="\{\{_ 'keep-add-card-form-open-description'\}\}"\)\n\s+i\.fa\.fa-plus-square\n\s+\| \{\{_ 'keep-add-card-form-open'\}\}\n\s+if isKeepAddCardFormOpen\n\s+i\.fa\.fa-check/);
|
|
assert.match(read('client/components/users/userHeader.js'),
|
|
/'click \.js-toggle-keep-add-card-form-open'\(\) \{\n\s+if \(ReactiveCache\.getCurrentUser\(\)\) Meteor\.call\('toggleKeepAddCardFormOpen'\);/);
|
|
const en = JSON.parse(read('imports/i18n/data/en.i18n.json'));
|
|
assert.ok(en['keep-add-card-form-open'] && en['keep-add-card-form-open-description']);
|
|
});
|
|
|
|
test('Add card closes its form after the cards are added, unless kept open', () => {
|
|
assert.match(body, /const keepAddCardFormOpen = \(\) => \{\n\s+const user = ReactiveCache\.getCurrentUser\(\);\n\s+return Boolean\(user && typeof user\.hasKeepAddCardFormOpen === 'function' && user\.hasKeepAddCardFormOpen\(\)\);/);
|
|
assert.match(addCard, /closeAfterAdd = titleIndex > 0 && !keepAddCardFormOpen\(\);/);
|
|
assert.match(addCard, /if \(closeAfterAdd\) \{[\s\S]{0,200}submittedForm\.querySelector\('\.js-close-inlined-form'\)\?\.click\(\);/);
|
|
// The form's own close button, which also clears the one-open-form tracker.
|
|
assert.match(read('client/components/lists/listBody.jade'), /a\.js-close-inlined-form/);
|
|
});
|
|
|
|
test('negative: not while the titles of a multi-line paste are still being added, nor after a failure', () => {
|
|
// The loop reads the form between titles; closing at submit (autoclose)
|
|
// would take it away mid-paste. So the add-card forms keep autoclose=false,
|
|
// and the decision is made after the loop, inside try - a throw skips it.
|
|
assert.strictEqual((read('client/components/lists/listBody.jade').match(/\+inlinedForm\(autoclose=false/g) || []).length, 3);
|
|
const loopEnd = addCard.indexOf('closeAfterAdd = titleIndex');
|
|
assert.ok(loopEnd > addCard.indexOf('for (const rawTitle of titles)'), 'decided after the loop');
|
|
assert.ok(loopEnd < addCard.indexOf('} catch (error) {'), 'inside try, so a failed add keeps the form and its text');
|
|
assert.ok(addCard.indexOf('if (closeAfterAdd)') > addCard.indexOf('} finally {'), 'closed after the finally re-enables it');
|
|
assert.doesNotMatch(addCard, /We keep the form opened/);
|
|
});
|
|
|
|
console.log(`\nkeepAddCardFormOpen6827: ${passed} passed`);
|