Files
SHiNE-server/shine-UI/tests/password-auth-ui.test.mjs
T

69 lines
3.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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/);
});