diff --git a/apps/web/tests/expected/remote-connection/anonymous-login.expected.md b/apps/web/tests/expected/remote-connection/anonymous-login.expected.md index b025d705cf..f05e5e63be 100644 --- a/apps/web/tests/expected/remote-connection/anonymous-login.expected.md +++ b/apps/web/tests/expected/remote-connection/anonymous-login.expected.md @@ -2,11 +2,12 @@ - region "连接到此 Host": - heading "连接到此 Host" [level=1] - paragraph: 请用以下任意方式验证登录 - - text: 登录令牌或链接 - - textbox "登录令牌或链接": - - /placeholder: {{application-url}}?token=xxx - - paragraph: 在已登录设备的「设置 → 远程连接」中复制链接,粘贴到此处 - - button "继续" + - form "输入登录令牌或链接": + - heading "输入登录令牌或链接" [level=2] + - paragraph: 在已登录设备的「设置 → 远程连接」中复制链接,粘贴到此处 + - textbox "输入登录令牌或链接": + - /placeholder: {{application-url}}?token=xxx + - button "继续" - region "配对此设备": - heading "配对此设备" [level=2] - paragraph: 申请后,在另一台已登录设备的“设置 → 远程连接”核对配对码并批准,此设备将自动登录。 diff --git a/apps/web/tests/expected/remote-connection/anonymous-rejected.expected.md b/apps/web/tests/expected/remote-connection/anonymous-rejected.expected.md index 753ab6999c..d19c9b18f1 100644 --- a/apps/web/tests/expected/remote-connection/anonymous-rejected.expected.md +++ b/apps/web/tests/expected/remote-connection/anonymous-rejected.expected.md @@ -2,12 +2,14 @@ - region "连接到此 Host": - heading "连接到此 Host" [level=1] - paragraph: 请用以下任意方式验证登录 - - text: 登录令牌或链接 - - textbox "登录令牌或链接" [invalid]: - - /placeholder: {{application-url}}?token=xxx - - text: {{invalid-token}} - - alert: 此登录令牌无效或已过期,请粘贴新的令牌后重试 - - button "继续" + - form "输入登录令牌或链接": + - heading "输入登录令牌或链接" [level=2] + - paragraph: 在已登录设备的「设置 → 远程连接」中复制链接,粘贴到此处 + - textbox "输入登录令牌或链接" [invalid]: + - /placeholder: {{application-url}}?token=xxx + - text: {{invalid-token}} + - alert: 此登录令牌无效或已过期,请粘贴新的令牌后重试 + - button "继续" - region "配对此设备": - heading "配对此设备" [level=2] - paragraph: 申请后,在另一台已登录设备的“设置 → 远程连接”核对配对码并批准,此设备将自动登录。 diff --git a/apps/web/tests/remote-connection.e2e.ts b/apps/web/tests/remote-connection.e2e.ts index 74cbe92a5c..f41ed45ba6 100644 --- a/apps/web/tests/remote-connection.e2e.ts +++ b/apps/web/tests/remote-connection.e2e.ts @@ -214,6 +214,30 @@ describe('web e2e: one-use QR browser login', () => { } await expectPlaceholderColor('rgb(173, 178, 184)') expect(await page.locator('#token-hint').innerText()).toBe('在已登录设备的「设置 → 远程连接」中复制链接,粘贴到此处') + const tokenHeading = page.getByRole('heading', { name: '输入登录令牌或链接', level: 2, exact: true }) + const pairingHeading = page.getByRole('heading', { name: '配对此设备', level: 2, exact: true }) + await pairingHeading.waitFor() + const methodLayout = (heading: Locator) => heading.evaluate((title) => { + const hint = title.nextElementSibling! + const control = title.parentElement!.querySelector('input,button')! + const titleBox = title.getBoundingClientRect() + const hintBox = hint.getBoundingClientRect() + const controlBox = control.getBoundingClientRect() + const typography = (element: Element) => { + const style = getComputedStyle(element) + return { size: style.fontSize, height: style.lineHeight, weight: style.fontWeight } + } + return { + title: typography(title.querySelector('label') ?? title), description: typography(hint), + titleGap: hintBox.top - titleBox.bottom, controlGap: controlBox.top - hintBox.bottom, + } + }) + const tokenLayout = await methodLayout(tokenHeading) + expect(tokenLayout).toEqual(await methodLayout(pairingHeading)) + expect(tokenLayout).toEqual({ + title: { size: '14px', height: '21px', weight: '500' }, + description: { size: '14px', height: '21px', weight: '400' }, titleGap: 12, controlGap: 12, + }) expect(await page.getByRole('button', { name: '账号菜单', exact: true }).count()).toBe(0) expect(await page.evaluate(async () => { const reply = await fetch('./', { method: 'HEAD', credentials: 'same-origin', cache: 'no-store', redirect: 'manual' }) @@ -264,6 +288,8 @@ describe('web e2e: one-use QR browser login', () => { await input.focus() expect(page.url()).toBe(secure.url) expect(await input.getAttribute('aria-invalid')).toBe('true') + expect(await page.locator('#token-hint').isVisible()).toBe(true) + expect(await methodLayout(tokenHeading)).toEqual(tokenLayout) expect(await inputAppearance()).toMatchObject({ borderColor: 'rgb(242, 90, 90)', outline: 'none', shadow: 'none' }) expect(await submit.isEnabled()).toBe(true) const [inputBox, errorBox, submitBox] = await Promise.all([ diff --git a/packages/client/remote-connection/src/login-locales.ts b/packages/client/remote-connection/src/login-locales.ts index db4eab130d..466c2d8a12 100644 --- a/packages/client/remote-connection/src/login-locales.ts +++ b/packages/client/remote-connection/src/login-locales.ts @@ -12,7 +12,7 @@ export const loginLocales = { authenticationDescription: 'Use one of the methods below to sign in.', authenticationUnavailable: 'No sign-in method is available. Contact the Host operator.', pairingScriptRequired: 'JavaScript is required to request device pairing.', - tokenLabel: 'Login token or link', + tokenLabel: 'Enter a login token or link', tokenPlaceholder: '{url}?token=xxx', tokenPlaceholderFallbackUrl: 'http://:/', tokenHint: 'On a signed-in device, copy the link from Settings → Remote connection and paste it here.', @@ -33,7 +33,7 @@ export const loginLocales = { authenticationDescription: '请用以下任意方式验证登录', authenticationUnavailable: '没有可用的登录方式,请联系 Host 管理者', pairingScriptRequired: '申请设备配对需要启用 JavaScript', - tokenLabel: '登录令牌或链接', + tokenLabel: '输入登录令牌或链接', tokenPlaceholder: '{url}?token=xxx', tokenPlaceholderFallbackUrl: 'http://:/', tokenHint: '在已登录设备的「设置 → 远程连接」中复制链接,粘贴到此处', diff --git a/packages/client/remote-connection/src/login-page.ts b/packages/client/remote-connection/src/login-page.ts index 5ca191b743..9eea5ccf2a 100644 --- a/packages/client/remote-connection/src/login-page.ts +++ b/packages/client/remote-connection/src/login-page.ts @@ -16,23 +16,22 @@ body{margin:0;min-height:100dvh} .card:not(:has(.methods)),.methods>*{box-sizing:border-box;min-width:0;padding:24px;border:.5px solid color-mix(in srgb,currentColor 16%,transparent);border-radius:var(--dsw-radius-lg,12px);background:light-dark(#fff,#232324)} h1{margin:0;font-size:20px;line-height:1.3;font-weight:500} p{margin:0;font-size:14px;line-height:1.5;overflow-wrap:anywhere} -.description,.hint,label{color:color-mix(in srgb,currentColor 72%,transparent)} -form{display:grid;grid-template-columns:minmax(0,1fr);grid-template-areas:'label' 'input' 'feedback' 'submit';gap:12px;min-width:0} -label{grid-area:label;margin-bottom:-6px;font-size:13px;font-weight:500;line-height:1.5} +.description,.hint{color:color-mix(in srgb,currentColor 72%,transparent)} +form{display:flex;flex-direction:column;gap:12px;min-width:0} +form h2{margin:0;font-size:14px;line-height:1.5;font-weight:500} +form label{font:inherit;color:inherit} input,button{box-sizing:border-box;min-width:0;min-height:44px;padding:8px 12px;font:inherit;font-size:14px;line-height:1.5;border-radius:8px} -input{grid-area:input;width:100%;line-height:22px;color:inherit;background:light-dark(#fafafa,#1b1b1c);border:.5px solid color-mix(in srgb,currentColor 16%,transparent);outline:none} +input{width:100%;line-height:22px;color:inherit;background:light-dark(#fafafa,#1b1b1c);border:.5px solid color-mix(in srgb,currentColor 16%,transparent);outline:none} input::placeholder{color:var(--dsw-alias-label-caption,light-dark(#adb2b8,#81858c));opacity:1} input:focus{border-color:var(--dsw-alias-state-business-primary,light-dark(#4176e6,#7aaaff))} input[aria-invalid='true']{border:1px solid light-dark(#ec1313,#f25a5a)} -.hint,.error{grid-area:feedback;font-size:13px;line-height:1.5} -.error{color:light-dark(#ec1313,#f25a5a)} +.error{font-size:13px;line-height:1.5;color:light-dark(#ec1313,#f25a5a)} .error:empty{display:none} .notice{display:flex;flex-direction:column;gap:8px;padding:12px;border:.5px solid color-mix(in srgb,currentColor 16%,transparent);border-radius:8px;background:light-dark(#f5f5f5,#2a2a2b)} .notice[hidden]{display:none} .notice[data-state="error"]{color:light-dark(#a10c0c,#ffb3b3);border-color:light-dark(#f5b5b5,#8c3030);background:light-dark(#fff3f3,#381e1e)} .notice a{padding:0;font-size:13px} -form:has(.error:not(:empty)) .hint{visibility:hidden} -button{grid-area:submit;cursor:pointer;font-weight:500;color:light-dark(#fff,#222);background:light-dark(#222,#eee);border:0} +button{cursor:pointer;font-weight:500;color:light-dark(#fff,#222);background:light-dark(#222,#eee);border:0} button:disabled{cursor:wait;opacity:.6} a{color:inherit;text-underline-offset:3px;padding:8px 0;font-size:14px;line-height:1.5} button:focus-visible,a:focus-visible{outline:2px solid currentColor;outline-offset:2px} diff --git a/packages/client/remote-connection/tests/login-page.client.spec.ts b/packages/client/remote-connection/tests/login-page.client.spec.ts index 472b7db46f..0a5e1256fa 100644 --- a/packages/client/remote-connection/tests/login-page.client.spec.ts +++ b/packages/client/remote-connection/tests/login-page.client.spec.ts @@ -67,8 +67,17 @@ it.each(['en-US', 'zh-CN'])('shows the anonymous Token form without Client boot const t = language.startsWith('zh') ? loginLocales.zh : loginLocales.en expect(document.title).toBe(t.authenticationTitle) expect(document.getElementById('description')?.textContent).toBe(t.authenticationDescription) - expect(document.getElementById('token-label')?.textContent).toBe(t.tokenLabel) - expect(document.getElementById('token-hint')?.textContent).toBe(t.tokenHint) + const title = document.getElementById('token-title')! + const label = document.getElementById('token-label')! + const hint = document.getElementById('token-hint')! + expect(title.tagName).toBe('H2') + expect(title.firstElementChild).toBe(label) + expect(title.textContent).toBe(t.tokenLabel) + expect(fixture.input.labels?.item(0)).toBe(label) + expect(fixture.form.getAttribute('aria-labelledby')).toBe(title.id) + expect(title.nextElementSibling).toBe(hint) + expect(hint.textContent).toBe(t.tokenHint) + expect(hint.nextElementSibling).toBe(fixture.input) expect(fixture.form.method).toBe('get') expect(fixture.form.action).toBe(new URL('/mount/', fixture.actualLocation.href).href) expect(fixture.input.type).toBe('password')