diff --git a/openless-all/app/scripts/settings-modal-scroll-isolation.test.mjs b/openless-all/app/scripts/settings-modal-scroll-isolation.test.mjs new file mode 100644 index 00000000..b7db5568 --- /dev/null +++ b/openless-all/app/scripts/settings-modal-scroll-isolation.test.mjs @@ -0,0 +1,62 @@ +import { readFile } from 'node:fs/promises'; + +function assertEqual(actual, expected, name) { + if (actual !== expected) { + throw new Error(`${name}:期望 ${expected},实际 ${actual}`); + } +} + +function assertMatch(source, pattern, name) { + if (!pattern.test(source)) { + throw new Error(`${name}:未找到 ${pattern}`); + } +} + +const floatingShellTsx = await readFile( + new URL('../src/components/FloatingShell.tsx', import.meta.url), + 'utf-8', +); +const tokensCss = await readFile( + new URL('../src/styles/tokens.css', import.meta.url), + 'utf-8', +); + +const lockAttributeMatches = [ + ...floatingShellTsx.matchAll(/data-ol-settings-open=\{([^}]*)\}/g), +]; + +assertEqual( + lockAttributeMatches.length, + 1, + '背景滚动锁标记应只出现一次', +); + +const [lockAttributeMatch] = lockAttributeMatches; +const lockAttributeExpression = lockAttributeMatch[1]; +const lockAttributeIndex = lockAttributeMatch.index; +const backgroundScrollerIndex = floatingShellTsx.indexOf('className="ol-thinscroll', lockAttributeIndex); +const settingsModalIndex = floatingShellTsx.indexOf('