Улучшить ввод пароля при входе и регистрации

This commit is contained in:
AidarKC
2026-11-21 17:14:46 +03:00
parent 8ac8f04128
commit 653015b2e7
11 changed files with 351 additions and 93 deletions
+68
View File
@@ -0,0 +1,68 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
const read = file => fs.readFileSync(new URL(file, import.meta.url), 'utf8');
const registration = read('../js/pages/register-view.js');
const login = read('../js/pages/login-password-view.js');
const field = read('../js/components/visible-password-field.js');
const overlay = read('../js/components/secret-generation-overlay.js');
const ru = JSON.parse(read('../js/i18n/locales/ru.json'));
const en = JSON.parse(read('../js/i18n/locales/en.json'));
test('регистрация: один символ разрешён, счётчик только здесь, максимум 256', () => {
assert.match(registration, /value\.length < 1/);
assert.doesNotMatch(registration, /value\.length < (?:10|12)/);
assert.match(registration, /screens\.register_view\.password_counter/);
assert.doesNotMatch(login, /password_counter/);
assert.match(read('../js/services/password-words.js'), /PASSWORD_MAX_LENGTH = 256/);
});
test('обе формы используют многострочное парольное поле с видимостью', () => {
assert.match(registration, /createExpandablePasswordTextarea\(\)/);
assert.match(login, /createExpandablePasswordTextarea\(\)/);
assert.match(field, /input\.rows = 1/);
assert.match(field, /3 \* lineHeight/);
assert.match(field, /auth-password-field--masked/);
assert.match(field, /input\.updatePasswordMask\(\)/);
});
test('одна заставка, без процента и прогресса в обоих сценариях', () => {
assert.match(login, /createSecretGenerationOverlay\(\)/);
assert.match(registration, /createSecretGenerationOverlay\(\)/);
assert.match(registration, /keyGeneration\.show\(\)/);
assert.match(login, /keyGeneration\.show\(\)/);
assert.doesNotMatch(login, /onProgress|percent|\.progress/);
assert.doesNotMatch(overlay, /percent|progress/);
assert.equal(ru.components.secret_generation_overlay.title, 'Генерируем ваши цифровые ключи…');
assert.match(ru.components.secret_generation_overlay.description, /логина и пароля/);
assert.ok(en.components.secret_generation_overlay.title);
});
test('32 символа на строку без реального перевода строки в пароле', () => {
assert.match(field, /input\.cols = 32/);
assert.match(field, /input\.wrap = 'soft'/);
assert.match(field, /auth-password-field--multiline/);
const css = read('../styles/features/preauth.css');
assert.match(css, /32ch \+ 64px/);
assert.match(css, /auth-password-field--multiline/);
});
test('после успеха очищается видимое поле, не рабочие ключи', () => {
assert.match(field, /input\.clearPasswordField = \(\) =>/);
assert.match(field, /input\.updatePasswordMask\?\.\(\)/);
assert.match(registration, /draft\.preGeneratedKeyBundle = bundle;[\s\S]*?input\.clearPasswordField\(\);[\s\S]*?navigate\(/);
assert.match(registration, /input\.value = ''/);
assert.doesNotMatch(registration, /input\.value = draft\.password/);
assert.match(login, /state\.loginDraft\.password = '';[\s\S]*?passwordInput\.clearPasswordField\(\)/);
assert.match(ru.components.secret_generation_overlay.description, /на этом устройстве/);
assert.match(en.components.secret_generation_overlay.description, /on this device/);
});
test('текст регистрации на двух языках и определённое предупреждение', () => {
assert.match(ru.screens.register_view.text_038, /будет утрачен навсегда/);
assert.doesNotMatch(ru.screens.register_view.text_038, /может быть утрачен/);
assert.match(ru.screens.register_view.text_036, /12–16/);
assert.match(ru.screens.register_view.text_035, /кошелькам/);
assert.match(en.screens.register_view.text_038, /lost forever/);
});
@@ -26,7 +26,10 @@ test('пароль допускает один символ, а email можно
const email = read('../js/pages/registration-email-view.js');
assert.match(registration, /value\.length < 1/);
assert.doesNotMatch(registration, /value\.length < 12/);
assert.match(registration, /input\.type = 'text'/);
assert.match(registration, /createExpandablePasswordTextarea\(\)/);
const passwordField = read('../js/components/visible-password-field.js');
assert.match(passwordField, /createExpandablePasswordTextarea/);
assert.match(passwordField, /input\.tagName === 'TEXTAREA'/);
assert.match(email, /let emailRequestId = 0/);
assert.match(email, /requestId !== emailRequestId/);
assert.match(email, /emailRequestId \+= 1/);