11// Control UI tests cover GitHub link hover card behavior.
2+ import { mkdir } from "node:fs/promises" ;
3+ import path from "node:path" ;
24import { chromium , type Browser , type BrowserContext , type Locator } from "playwright" ;
35import { afterAll , afterEach , beforeAll , describe , expect , it } from "vitest" ;
46import {
@@ -119,8 +121,8 @@ describeControlUiE2e("GitHub link hover cards", () => {
119121 {
120122 type : "text" ,
121123 text : [
122- "Review [#99816]( https://github.com/openclaw/openclaw/pull/99816) ," ,
123- "then [#99815]( https://github.com/openclaw/openclaw/issues/99815) ." ,
124+ "Review https://github.com/openclaw/openclaw/pull/99816," ,
125+ "then https://github.com/openclaw/openclaw/issues/99815." ,
124126 "A [missing item](https://github.com/openclaw/openclaw/issues/999999) stays usable." ,
125127 "The [repository](https://github.com/openclaw/openclaw) has no item preview." ,
126128 "Styling notes live in [the docs](https://docs.openclaw.ai/web/control-ui)." ,
@@ -130,11 +132,52 @@ describeControlUiE2e("GitHub link hover cards", () => {
130132 role : "assistant" ,
131133 timestamp : Date . now ( ) ,
132134 } ,
135+ {
136+ content : [
137+ {
138+ type : "text" ,
139+ text : "Narrow reference https://github.com/a-very-long-organization-name/a-very-long-repository-name/issues/99817" ,
140+ } ,
141+ ] ,
142+ role : "assistant" ,
143+ timestamp : Date . now ( ) ,
144+ } ,
133145 ] ,
134146 } ) ;
135147 await page . goto ( `${ server . baseUrl } chat` ) ;
136148
137- const pullLink = page . getByRole ( "link" , { name : "#99816" } ) ;
149+ const message = page . locator ( ".chat-text" ) . filter ( { hasText : "Review" } ) ;
150+ const artifactDir = process . env . OPENCLAW_UI_E2E_ARTIFACT_DIR ?. trim ( ) ;
151+ if ( artifactDir ) {
152+ await mkdir ( artifactDir , { recursive : true } ) ;
153+ await message . screenshot ( { path : path . join ( artifactDir , "github-references-light.png" ) } ) ;
154+ await page . emulateMedia ( { colorScheme : "dark" } ) ;
155+ await expect . poll ( ( ) => page . locator ( "html" ) . getAttribute ( "data-theme-mode" ) ) . toBe ( "dark" ) ;
156+ await message . screenshot ( { path : path . join ( artifactDir , "github-references-dark.png" ) } ) ;
157+ await page . emulateMedia ( { colorScheme : "light" } ) ;
158+ await expect . poll ( ( ) => page . locator ( "html" ) . getAttribute ( "data-theme-mode" ) ) . toBe ( "light" ) ;
159+ }
160+
161+ const longLink = page . getByRole ( "link" , {
162+ name : "a-very-long-organization-name/a-very-long-repository-name#99817" ,
163+ } ) ;
164+ await page . setViewportSize ( { height : 800 , width : 360 } ) ;
165+ expect ( await longLink . evaluate ( ( element ) => getComputedStyle ( element ) . lineBreak ) ) . toBe (
166+ "anywhere" ,
167+ ) ;
168+ const longMessageBox = await longLink
169+ . locator ( "xpath=ancestor::*[contains(@class, 'chat-text')]" )
170+ . boundingBox ( ) ;
171+ const longLinkBox = await longLink . boundingBox ( ) ;
172+ expect ( longMessageBox ) . not . toBeNull ( ) ;
173+ expect ( longLinkBox ) . not . toBeNull ( ) ;
174+ expect ( longLinkBox ! . x ) . toBeGreaterThanOrEqual ( longMessageBox ! . x ) ;
175+ expect ( longLinkBox ! . x + longLinkBox ! . width ) . toBeLessThanOrEqual (
176+ longMessageBox ! . x + longMessageBox ! . width ,
177+ ) ;
178+ await page . setViewportSize ( { height : 800 , width : 1180 } ) ;
179+
180+ const pullLink = page . getByRole ( "link" , { name : "openclaw/openclaw#99816" } ) ;
138181
139182 // The mark carries the link signal at rest, so the underline only returns on
140183 // hover. Non-GitHub links keep the base underline, which keeps the rule scoped.
@@ -160,7 +203,7 @@ describeControlUiE2e("GitHub link hover cards", () => {
160203 expect ( pullBox ! . x + pullBox ! . width ) . toBeLessThanOrEqual ( 1180 ) ;
161204 expect ( pullBox ! . y + pullBox ! . height ) . toBeLessThanOrEqual ( 800 ) ;
162205
163- const issueLink = page . getByRole ( "link" , { name : "#99815" } ) ;
206+ const issueLink = page . getByRole ( "link" , { name : "openclaw/openclaw #99815" } ) ;
164207 await issueLink . hover ( ) ;
165208 await expectText ( card , "Keep hover previews compact" ) ;
166209 await expectText ( card , "octocat" ) ;
@@ -175,7 +218,7 @@ describeControlUiE2e("GitHub link hover cards", () => {
175218 expect ( ( await gateway . getRequests ( "controlUi.githubPreview" ) ) . length ) . toBe ( 2 ) ;
176219
177220 await page . mouse . move ( 1 , 1 ) ;
178- await page . getByRole ( "link" , { name : "repository" } ) . hover ( ) ;
221+ await page . getByRole ( "link" , { exact : true , name : "repository" } ) . hover ( ) ;
179222 await page . clock . runFor ( 300 ) ;
180223 await expect . poll ( ( ) => card . count ( ) ) . toBe ( 0 ) ;
181224
0 commit comments