@@ -4,10 +4,8 @@ import {
44 removeStylesheetRulesFromPage ,
55} from './domUtils' ;
66
7- export async function clearTestPage ( testController : TestController ) : Promise < void > {
8- const shadowDom = process . env . shadowDom === 'true' ;
9-
10- const clearTestPageFn = ClientFunction ( ( ) => {
7+ export async function clearTestPage ( t : TestController ) : Promise < void > {
8+ await ClientFunction ( ( ) => {
119 const widgetSelector = '.dx-widget' ;
1210 const $elements = $ ( widgetSelector )
1311 . filter ( ( _ , element ) => $ ( element ) . parents ( widgetSelector ) . length === 0 ) ;
@@ -23,6 +21,9 @@ export async function clearTestPage(testController: TestController): Promise<voi
2321 $widgetElement . empty ( ) ;
2422 } ) ;
2523
24+ const element = document . getElementById ( 'focusable-start' ) ;
25+ element ?. remove ( ) ;
26+
2627 const body = document . querySelector ( 'body' ) ;
2728 if ( body ) {
2829 body . innerHTML = '' ;
@@ -40,29 +41,58 @@ export async function clearTestPage(testController: TestController): Promise<voi
4041 ` ;
4142
4243 body ?. prepend ( temp . firstElementChild ! ) ;
43- } , {
44- dependencies : {
45- shadowDom,
46- } ,
47- } ) ;
44+ } ) . with ( { boundTestRun : t } ) ( ) ;
4845
49- await clearTestPageFn . with ( { boundTestRun : testController } ) ( ) ;
50- await removeStylesheetRulesFromPage . with ( { boundTestRun : testController } ) ( ) ;
46+ await removeStylesheetRulesFromPage . with ( { boundTestRun : t } ) ( ) ;
5147}
5248
5349export async function loadAxeCore ( t : TestController ) : Promise < void > {
54- await t . eval ( ( ) => new Promise < void > ( ( resolve , reject ) => {
50+ await ClientFunction ( ( ) => new Promise < void > ( ( resolve , reject ) => {
5551 // @ts -expect-error ts-error
5652 if ( window . axe ) {
5753 resolve ( ) ;
5854 return ;
5955 }
6056
6157 const script = document . createElement ( 'script' ) ;
58+ script . id = 'axe-core-script' ;
6259 script . src = '../../../node_modules/axe-core/axe.min.js' ;
6360 // @ts -expect-error ts-error
6461 script . onload = resolve ;
6562 script . onerror = reject ;
6663 document . head . appendChild ( script ) ;
67- } ) ) ;
64+ } ) ) . with ( { boundTestRun : t } ) ( ) ;
65+ }
66+
67+ export async function loadShadowDomExtension ( t : TestController ) : Promise < void > {
68+ await ClientFunction ( ( ) => new Promise < void > ( ( resolve , reject ) => {
69+ if ( document . getElementById ( 'shadow-dom-extension-script' ) ) {
70+ resolve ( ) ;
71+ return ;
72+ }
73+
74+ const script = document . createElement ( 'script' ) ;
75+ script . id = 'shadow-dom-extension-script' ;
76+ script . src = '../../helpers/shadowDom/shadowDomExtension.js' ;
77+ // @ts -expect-error ts-error
78+ script . onload = resolve ;
79+ script . onerror = reject ;
80+ document . head . appendChild ( script ) ;
81+ } ) ) . with ( { boundTestRun : t } ) ( ) ;
6882}
83+
84+ export const addShadowRootTree = async ( t : TestController ) : Promise < void > => {
85+ await ClientFunction ( ( ) => {
86+ const root = document . querySelector ( '#parentContainer' ) as HTMLElement ;
87+ const { childNodes } = root ;
88+
89+ if ( ! root . shadowRoot ) {
90+ root . attachShadow ( { mode : 'open' } ) ;
91+ }
92+
93+ const shadowContainer = document . createElement ( 'div' ) ;
94+ shadowContainer . append ( ...Array . from ( childNodes ) ) ;
95+
96+ root . shadowRoot ! . appendChild ( shadowContainer ) ;
97+ } ) . with ( { boundTestRun : t } ) ( ) ;
98+ } ;
0 commit comments