CI / Build & Quality Checks (pull_request) Successful in 3m24s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 16s
CI / Playwright smoke (e2e) (pull_request) Failing after 18m15s
Where the on-device Translator/LanguageDetector APIs are missing, Settings said to use Chrome/Edge "or the Lotus desktop app", but the Linux and macOS apps (WebKit) lack them too, and showed the advice to people already in the app. Word it by platform. (The per-message Translate action was already hidden where unsupported.) Fixes #349 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
63 lines
2.4 KiB
TypeScript
63 lines
2.4 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
translationUnavailableText,
|
|
normalizeLang,
|
|
sameLanguage,
|
|
languageName,
|
|
isSupportedTargetLang,
|
|
TRANSLATE_TARGET_LANGUAGES,
|
|
} from './langUtils';
|
|
|
|
test('normalizeLang: base subtag, lowercased', () => {
|
|
assert.equal(normalizeLang('en-US'), 'en');
|
|
assert.equal(normalizeLang('ZH'), 'zh');
|
|
assert.equal(normalizeLang('pt_BR'), 'pt');
|
|
assert.equal(normalizeLang(' De '), 'de');
|
|
assert.equal(normalizeLang(''), '');
|
|
assert.equal(normalizeLang(undefined), '');
|
|
assert.equal(normalizeLang(null), '');
|
|
});
|
|
|
|
test('normalizeLang: keeps Chinese script subtag', () => {
|
|
assert.equal(normalizeLang('zh-Hant'), 'zh-hant');
|
|
assert.equal(normalizeLang('zh-Hans-CN'), 'zh-hans');
|
|
assert.equal(normalizeLang('zh-CN'), 'zh'); // region-only collapses to base
|
|
});
|
|
|
|
test('sameLanguage: compares normalized bases', () => {
|
|
assert.equal(sameLanguage('en', 'en-US'), true);
|
|
assert.equal(sameLanguage('EN', 'en'), true);
|
|
assert.equal(sameLanguage('en', 'de'), false);
|
|
assert.equal(sameLanguage('', 'en'), false); // empty is never "same"
|
|
assert.equal(sameLanguage(undefined, undefined), false);
|
|
});
|
|
|
|
test('languageName: resolves common codes', () => {
|
|
// Intl.DisplayNames is available in node; assert it returns a real name (not
|
|
// the bare code) for a known language.
|
|
const de = languageName('de');
|
|
assert.ok(de.length > 0 && de.toLowerCase() !== 'de');
|
|
// Unknown/garbage code falls back to the code itself.
|
|
assert.equal(languageName('zz-not-a-lang'), 'zz-not-a-lang'.split('-')[0]);
|
|
});
|
|
|
|
test('isSupportedTargetLang: curated membership', () => {
|
|
assert.equal(isSupportedTargetLang('en'), true);
|
|
assert.equal(isSupportedTargetLang('DE'), true);
|
|
assert.equal(isSupportedTargetLang('pt-BR'), true);
|
|
assert.equal(isSupportedTargetLang('xx'), false);
|
|
});
|
|
|
|
test('curated list: unique codes, English present', () => {
|
|
const codes = TRANSLATE_TARGET_LANGUAGES.map((l) => l.code);
|
|
assert.equal(new Set(codes).size, codes.length);
|
|
assert.ok(codes.includes('en'));
|
|
});
|
|
|
|
test('translationUnavailableText: no "use the desktop app" inside the desktop app (#349)', () => {
|
|
assert.doesNotMatch(translationUnavailableText(true), /desktop app\.$|Lotus desktop app/);
|
|
assert.match(translationUnavailableText(true), /this version of the desktop app/);
|
|
assert.match(translationUnavailableText(false), /this browser/);
|
|
});
|