@@ -21,7 +21,46 @@ const moduleUrl = (path, id) => `${baseUrl}/typo3/module/${path}${id === undefin
2121const margin = 12 ;
2222
2323// The uids of the records that create-records.php created
24- const { startPage } = JSON . parse ( readFileSync ( '../../var/screenshot-records.json' , 'utf8' ) ) ;
24+ const { startPage, newSite } = JSON . parse ( readFileSync ( '../../var/screenshot-records.json' , 'utf8' ) ) ;
25+
26+ // The Content > Layout module
27+ const layoutUrl = ( id ) => moduleUrl ( 'web/layout' , id ) ;
28+ // A new page on the root level of the page tree
29+ const newRootPageUrl = `${ baseUrl } /typo3/record/edit?edit[pages][0]=new` ;
30+ // The frontend of the hidden root page, at the base of its generated site
31+ // configuration. The logged in administrator sees hidden pages.
32+ const newSiteFrontend = `${ baseUrl } /autogenerated-${ newSite } /` ;
33+
34+ // A page of the page tree, which is outside of the module frame. The
35+ // top node, the root level, has the uid 0.
36+ const treeNode = ( uid ) => `#typo3-pagetree-tree .node[data-id="${ uid } "]` ;
37+ // The open context menu, which is outside of the module frame
38+ const contextMenu = '.context-menu >> visible=true' ;
39+
40+ // Opens the context menu of a page in the page tree
41+ const openPageMenu = async ( frame , uid ) => {
42+ await frame . page ( ) . locator ( `${ treeNode ( uid ) } .node-contentlabel` ) . click ( { button : 'right' } ) ;
43+ await frame . page ( ) . locator ( contextMenu ) . first ( ) . waitFor ( ) ;
44+ await frame . page ( ) . waitForTimeout ( 500 ) ;
45+ // The menu focuses its first item, which would look selected
46+ await frame . page ( ) . evaluate ( ( ) => document . activeElement ?. blur ( ) ) ;
47+ } ;
48+
49+ // Marks an element that the text names, with a frame the given number of
50+ // pixels around it. An element between close neighbours, such as a tab or
51+ // an entry of a menu, is marked inside, with a negative number, as a frame
52+ // outside of it would be cut.
53+ const outline = ( locator , offset = 3 ) => locator . evaluate ( ( element , space ) => {
54+ element . style . outline = '3px solid #ff8700' ;
55+ element . style . outlineOffset = `${ space } px` ;
56+ } , offset ) ;
57+
58+ // An entry of the open context menu
59+ const menuItem = ( label ) => `${ contextMenu } >> .context-menu-item[aria-label="${ label } "]` ;
60+
61+ // A field of a form, found by its name: the backend runs without debug
62+ // mode, which would show the field names
63+ const field = ( name ) => `.form-group:has([name$="[${ name } ]"]):not(:has(.form-group))` ;
2564
2665// The Sites > Setup module, which lists the site configurations
2766const sitesUrl = moduleUrl ( 'site/configuration' ) ;
@@ -66,6 +105,83 @@ const screenshots = {
66105 window : true ,
67106 until : '.form-section:has([name$="[dependencies]"])' ,
68107 } ,
108+ // The context menu of the root level of the page tree, with "New subpage"
109+ 'FirstProject/CreateRootPage/CreateNewPage' : {
110+ width : 1000 ,
111+ url : layoutUrl ( startPage ) ,
112+ pageTree : true ,
113+ menu : 'Content' ,
114+ prepare : async ( frame ) => {
115+ await openPageMenu ( frame , 0 ) ;
116+ await outline ( frame . page ( ) . locator ( menuItem ( 'New subpage' ) ) . first ( ) , - 3 ) ;
117+ } ,
118+ window : true ,
119+ untilOutside : contextMenu ,
120+ } ,
121+ // The form of a new page on the root level, on the tab with the checkbox
122+ // "Use as Root Page", which is checked
123+ 'FirstProject/CreateRootPage/SetRootPage' : {
124+ width : 1000 ,
125+ url : newRootPageUrl ,
126+ tab : 'Behavior' ,
127+ menu : 'Content' ,
128+ prepare : async ( frame ) => {
129+ // The title is required, and the form marks the tab of an empty one
130+ await frame . getByRole ( 'tab' , { name : / G e n e r a l / } ) . first ( ) . click ( ) ;
131+ await frame . locator ( `${ field ( 'title' ) } input[data-formengine-input-name]` ) . first ( ) . fill ( 'New site' ) ;
132+ const tab = frame . getByRole ( 'tab' , { name : 'Behavior' , exact : true } ) ;
133+ await tab . click ( ) ;
134+ await frame . locator ( `${ field ( 'is_siteroot' ) } input[type="checkbox"]` ) . first ( ) . check ( ) ;
135+ await outline ( tab , - 3 ) ;
136+ // Space between the frame and the label and the switch
137+ await outline ( frame . locator ( field ( 'is_siteroot' ) ) . first ( ) , 8 ) ;
138+ await frame . locator ( 'h1' ) . first ( ) . click ( ) ;
139+ await frame . page ( ) . waitForTimeout ( 500 ) ;
140+ } ,
141+ window : true ,
142+ until : field ( 'is_siteroot' ) ,
143+ // Below the frame around the field
144+ untilSpace : 16 ,
145+ } ,
146+ // The new root page in the page tree, hidden as every new page
147+ 'FirstProject/CreateRootPage/PageCreated' : {
148+ width : 1000 ,
149+ url : layoutUrl ( newSite ) ,
150+ pageTree : true ,
151+ menu : 'Content' ,
152+ window : true ,
153+ until : 'h1' ,
154+ } ,
155+ // The list of the root pages without a site configuration in the Sites
156+ // module
157+ 'FirstProject/CreateRootPage/PageWithoutSiteConfig' : {
158+ url : sitesUrl ,
159+ from : 'h2:has-text("Pages without a site configuration")' ,
160+ to : `table:has(${ pageWithoutSite ( startPage ) } )` ,
161+ } ,
162+ // The detailed error page of a root page whose site has no sets and no
163+ // TypoScript record: the exception and its message. The file below it
164+ // would show the path of the checkout.
165+ 'FirstProject/CreateRootPage/NoTypoScriptFound' : {
166+ url : layoutUrl ( newSite ) ,
167+ frontend : newSiteFrontend ,
168+ frontendElement : '.trace-head' ,
169+ } ,
170+ // The context menu of the hidden root page, with the pointer on "Enable"
171+ 'FirstProject/CreateRootPage/EnablePage' : {
172+ width : 1000 ,
173+ url : layoutUrl ( newSite ) ,
174+ pageTree : true ,
175+ menu : 'Content' ,
176+ hover : true ,
177+ prepare : async ( frame ) => {
178+ await openPageMenu ( frame , newSite ) ;
179+ await frame . page ( ) . locator ( menuItem ( 'Enable' ) ) . first ( ) . hover ( ) ;
180+ await frame . page ( ) . waitForTimeout ( 300 ) ;
181+ } ,
182+ window : true ,
183+ untilOutside : contextMenu ,
184+ } ,
69185} ;
70186
71187// Hides the page tree, unless the screenshot needs it, and collapses the
@@ -237,6 +353,9 @@ for (const name of names) {
237353 // The page in the frontend, cut to the element named
238354 await page . goto ( screenshot . frontend ) ;
239355 await page . waitForLoadState ( 'networkidle' ) ;
356+ if ( process . env . DUMP ) {
357+ writeFileSync ( `../../var/${ name . replaceAll ( '/' , '_' ) } -frontend.html` , await page . content ( ) ) ;
358+ }
240359 const box = await page . locator ( screenshot . frontendElement ) . first ( ) . boundingBox ( ) ;
241360 await save ( name , await page . screenshot ( {
242361 clip : { x : box . x - margin , y : box . y - margin , width : box . width + 2 * margin , height : box . height + 2 * margin } ,
@@ -250,12 +369,17 @@ for (const name of names) {
250369 }
251370 if ( screenshot . window ) {
252371 // The whole backend. It ends below the element named in "until", so the
253- // image takes no more room on the page than it needs.
372+ // image takes no more room on the page than it needs. "untilOutside"
373+ // names an element outside of the module frame, such as a context menu.
374+ // "untilSpace" is the space below the element, for a frame around it.
254375 let clip = screenshot . clip && { x : 0 , y : 0 , ...screenshot . clip } ;
255- if ( screenshot . until ) {
256- const until = await frame . locator ( screenshot . until ) . last ( ) . boundingBox ( ) ;
376+ if ( screenshot . until || screenshot . untilOutside ) {
377+ const until = screenshot . untilOutside
378+ ? await page . locator ( screenshot . untilOutside ) . last ( ) . boundingBox ( )
379+ : await frame . locator ( screenshot . until ) . last ( ) . boundingBox ( ) ;
257380 const viewport = page . viewportSize ( ) ;
258- clip = { x : 0 , y : 0 , width : viewport . width , height : Math . min ( until . y + until . height + 4 , viewport . height ) } ;
381+ const space = screenshot . untilSpace ?? 4 ;
382+ clip = { x : 0 , y : 0 , width : viewport . width , height : Math . min ( until . y + until . height + space , viewport . height ) } ;
259383 }
260384 await save ( name , await page . screenshot ( { clip } ) ) ;
261385 continue ;
0 commit comments