@@ -26,31 +26,88 @@ async function openToolsIndex(page) {
2626
2727async function installPreviewGeneratorRepoRootPicker ( page ) {
2828 await page . addInitScript ( ( ) => {
29+ class FakeFileHandle {
30+ constructor ( name , parentPath , contents = "" ) {
31+ this . kind = "file" ;
32+ this . name = name ;
33+ this . path = parentPath ? `${ parentPath } /${ name } ` : name ;
34+ this . contents = contents ;
35+ }
36+
37+ async getFile ( ) {
38+ return new File ( [ this . contents ] , this . name , { type : "text/plain" } ) ;
39+ }
40+
41+ async createWritable ( ) {
42+ return {
43+ write : async ( contents ) => {
44+ this . contents = String ( contents || "" ) ;
45+ } ,
46+ close : async ( ) => {
47+ window . __previewGeneratorV2Writes . push ( {
48+ contents : this . contents ,
49+ path : this . path
50+ } ) ;
51+ }
52+ } ;
53+ }
54+ }
55+
2956 class FakeDirectoryHandle {
30- constructor ( name ) {
57+ constructor ( name , parentPath = "" ) {
3158 this . kind = "directory" ;
3259 this . name = name ;
60+ this . path = parentPath ? `${ parentPath } /${ name } ` : name ;
3361 this . children = new Map ( ) ;
3462 }
3563
3664 addDirectory ( name ) {
37- const directory = new FakeDirectoryHandle ( name ) ;
65+ const directory = new FakeDirectoryHandle ( name , this . path ) ;
3866 this . children . set ( name , directory ) ;
3967 return directory ;
4068 }
4169
42- async getDirectoryHandle ( name ) {
70+ addFile ( name , contents = "" ) {
71+ const file = new FakeFileHandle ( name , this . path , contents ) ;
72+ this . children . set ( name , file ) ;
73+ return file ;
74+ }
75+
76+ async getDirectoryHandle ( name , options = { } ) {
4377 const child = this . children . get ( name ) ;
4478 if ( child ?. kind === "directory" ) {
4579 return child ;
4680 }
81+ if ( options . create ) {
82+ return this . addDirectory ( name ) ;
83+ }
4784 throw new Error ( `Missing directory: ${ name } ` ) ;
4885 }
86+
87+ async getFileHandle ( name , options = { } ) {
88+ const child = this . children . get ( name ) ;
89+ if ( child ?. kind === "file" ) {
90+ return child ;
91+ }
92+ if ( options . create ) {
93+ return this . addFile ( name ) ;
94+ }
95+ throw new Error ( `Missing file: ${ name } ` ) ;
96+ }
97+
98+ async * entries ( ) {
99+ for ( const entry of this . children . entries ( ) ) {
100+ yield entry ;
101+ }
102+ }
49103 }
50104
51105 const repo = new FakeDirectoryHandle ( "HTML-JavaScript-Gaming" ) ;
52- repo . addDirectory ( "games" ) ;
106+ const games = repo . addDirectory ( "games" ) ;
107+ const asteroids = games . addDirectory ( "Asteroids" ) ;
108+ asteroids . addFile ( "index.html" , "<!doctype html><title>Asteroids</title>" ) ;
53109 repo . addDirectory ( "tools" ) ;
110+ window . __previewGeneratorV2Writes = [ ] ;
54111 window . showDirectoryPicker = async ( ) => repo ;
55112 } ) ;
56113}
@@ -532,12 +589,27 @@ test.describe("Workspace Manager V2 bootstrap", () => {
532589 await expect ( page . locator ( "#log" ) ) . toContainText ( "Repo selected from manifest repoRoot: HTML-JavaScript-Gaming." ) ;
533590 await expect ( page . locator ( "#log" ) ) . toContainText ( "Pick the matching actual repo root folder before writing preview output." ) ;
534591 await expect ( page . locator ( "#log" ) ) . toContainText ( "Asset folder: assets\\images" ) ;
535- await expect ( page . locator ( "#log" ) ) . toContainText ( "Manifest preview asset: assets.image.preview.bezel" ) ;
592+ await expect ( page . locator ( "#log" ) ) . toContainText ( "Manifest preview asset: assets.image.preview.bezel (image/png)" ) ;
593+ await expect ( page . locator ( "#log" ) ) . toContainText ( "Manifest preview source: games/Asteroids/assets/images/bezel.png" ) ;
594+ await expect ( page . locator ( "#log" ) ) . toContainText ( "Generated preview target: games/Asteroids/assets/images/preview.svg" ) ;
536595 await expect ( page . locator ( "#log" ) ) . toContainText ( "Preview target: games/Asteroids/assets/images/bezel.png" ) ;
537- await expect ( page . locator ( "#log" ) ) . toContainText ( "OK Workspace preview target is valid at games/Asteroids/assets/images/bezel.png." ) ;
596+ await expect ( page . locator ( "#log" ) ) . toContainText ( "Workspace background source: assets.image.background.deluxe -> games/Asteroids/assets/images/deluxe.png" ) ;
597+ await expect ( page . locator ( "#log" ) ) . toContainText ( "Workspace background color: Space Black #020617 from palette-manager-v2 swatch." ) ;
598+ await expect ( page . locator ( "#log" ) ) . toContainText ( "OK Workspace manifest preview source is valid at games/Asteroids/assets/images/bezel.png." ) ;
538599 await page . locator ( "#pickRepoBtn" ) . click ( ) ;
539600 await expect ( page . locator ( "#repoSelectedValue" ) ) . toHaveText ( "HTML-JavaScript-Gaming" ) ;
601+ await expect ( page . locator ( "#previewTargetValue" ) ) . toHaveText ( "games/Asteroids/assets/images/preview.svg" ) ;
602+ await expect ( page . locator ( "#log" ) ) . toContainText ( "Preview target updated: games/Asteroids/assets/images/preview.svg" ) ;
540603 await expect ( page . locator ( "#executeBtn" ) ) . toBeEnabled ( ) ;
604+ await page . locator ( "#executeBtn" ) . click ( ) ;
605+ await expect ( page . locator ( "#log" ) ) . toContainText ( "OUT games\\Asteroids\\assets\\images\\preview.svg" , { timeout : 30000 } ) ;
606+ await expect ( page . locator ( "#log" ) ) . toContainText ( "Done." , { timeout : 30000 } ) ;
607+ await expect ( page . locator ( "#lastGeneratedImageMeta" ) ) . toHaveText ( "Last generated: Asteroids" ) ;
608+ const previewWrites = await page . evaluate ( ( ) => window . __previewGeneratorV2Writes ) ;
609+ expect ( previewWrites ) . toHaveLength ( 1 ) ;
610+ expect ( previewWrites [ 0 ] . path ) . toBe ( "HTML-JavaScript-Gaming/games/Asteroids/assets/images/preview.svg" ) ;
611+ expect ( previewWrites [ 0 ] . contents ) . toContain ( 'fill="#020617"' ) ;
612+ expect ( previewWrites [ 0 ] . contents ) . not . toContain ( "#ffffff" ) ;
541613 await page . locator ( "#returnToWorkspaceButton" ) . click ( ) ;
542614 await expect ( page ) . toHaveURL ( / w o r k s p a c e - m a n a g e r - v 2 \/ i n d e x \. h t m l \? h o s t C o n t e x t I d = w o r k s p a c e - m a n a g e r - v 2 - / ) ;
543615 expect ( pageErrors ) . toEqual ( [ ] ) ;
0 commit comments