@@ -124,6 +124,12 @@ export class App {
124124 value : "1" ,
125125 url : this . url ,
126126 } ) ;
127+ // Don't show compliance notice.
128+ await page . setCookie ( {
129+ name : "MBCC" ,
130+ value : "1" ,
131+ url : this . url ,
132+ } ) ;
127133
128134 const client = await page . target ( ) . createCDPSession ( ) ;
129135 await client . send ( "Page.setDownloadBehavior" , {
@@ -1139,6 +1145,69 @@ export class App {
11391145 await actions . click ( ) ;
11401146 }
11411147
1148+ private async keyboardPress ( key : puppeteer . KeyInput ) : Promise < void > {
1149+ const keyboard = ( await this . page ) . keyboard ;
1150+ await keyboard . press ( key ) ;
1151+ }
1152+
1153+ private async getActiveElement ( ) : Promise < puppeteer . ElementHandle < Element > > {
1154+ return ( await this . page ) . evaluateHandle < ElementHandle > (
1155+ ( ) => document . activeElement
1156+ ) ;
1157+ }
1158+
1159+ private async getElementByRoleAndLabel (
1160+ role : string ,
1161+ name : string
1162+ ) : Promise < puppeteer . ElementHandle < Element > > {
1163+ return ( await this . document ( ) ) . findByRole ( role , {
1164+ name,
1165+ } ) ;
1166+ }
1167+
1168+ private async getElementByQuerySelector (
1169+ query : string
1170+ ) : Promise < puppeteer . ElementHandle < Element > > {
1171+ return ( await this . page ) . evaluateHandle < ElementHandle > (
1172+ ( query ) => document . querySelector ( query ) ,
1173+ query
1174+ ) ;
1175+ }
1176+
1177+ private async compareElementHandles (
1178+ e1 : puppeteer . ElementHandle < Element > ,
1179+ e2 : puppeteer . ElementHandle < Element >
1180+ ) : Promise < boolean > {
1181+ return ( await this . page ) . evaluate ( ( e1 , e2 ) => e1 === e2 , e1 , e2 ) ;
1182+ }
1183+
1184+ async assertFocusOnLoad ( ) : Promise < boolean > {
1185+ await this . keyboardPress ( "Tab" ) ;
1186+ const activeElement = await this . getActiveElement ( ) ;
1187+ const firstFocusableElement = await this . getElementByRoleAndLabel (
1188+ "link" ,
1189+ "visit microbit.org (opens in a new tab)"
1190+ ) ;
1191+ return this . compareElementHandles ( activeElement , firstFocusableElement ) ;
1192+ }
1193+
1194+ async assertFocusOnAreaToggle (
1195+ action : "Collapse" | "Expand" ,
1196+ area : "simulator" | "sidebar"
1197+ ) : Promise < boolean > {
1198+ await this . findAndClickButton ( `${ action } ${ area } ` ) ;
1199+ const activeElement = await this . getActiveElement ( ) ;
1200+ const proposedActiveElement =
1201+ action === "Collapse"
1202+ ? await this . getElementByRoleAndLabel ( "button" , `Expand ${ area } ` )
1203+ : await this . getElementByQuerySelector (
1204+ area === "simulator"
1205+ ? "iframe[name='Simulator']"
1206+ : "[role='tabpanel']"
1207+ ) ;
1208+ return this . compareElementHandles ( activeElement , proposedActiveElement ) ;
1209+ }
1210+
11421211 // Simulator functions
11431212 private async getSimulatorIframe ( ) : Promise < puppeteer . Frame > {
11441213 const page = await this . page ;
0 commit comments