aria-ease 7.0.1 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/ComboboxComponentStrategy-DHZS4NW6.js +5 -0
  2. package/dist/MenuComponentStrategy-L3QXLC6S.js +5 -0
  3. package/dist/RelativeTargetResolver-PDJM3ZJI.js +1 -0
  4. package/dist/TabsComponentStrategy-LKV6D2B7.js +1 -0
  5. package/dist/chunk-WIWSYIGK.js +1 -0
  6. package/dist/cli.cjs +61 -61
  7. package/dist/cli.js +1 -1
  8. package/dist/contractTestRunnerPlaywright-2CEH3GPM.js +46 -0
  9. package/dist/contractTestRunnerPlaywright-RUKMUY5P.js +46 -0
  10. package/dist/index.cjs +41 -41
  11. package/dist/index.d.cts +35 -11
  12. package/dist/index.d.ts +35 -11
  13. package/dist/index.js +14 -14
  14. package/dist/src/utils/test/ComboboxComponentStrategy-5AWO63DA.js +5 -0
  15. package/dist/src/utils/test/MenuComponentStrategy-QHVBLUBR.js +5 -0
  16. package/dist/src/utils/test/RelativeTargetResolver-5SIQLWPN.js +1 -0
  17. package/dist/src/utils/test/TabsComponentStrategy-DTQQUCK2.js +1 -0
  18. package/dist/src/utils/test/chunk-WIWSYIGK.js +1 -0
  19. package/dist/src/utils/test/contractTestRunnerPlaywright-LUWM3RIL.js +46 -0
  20. package/dist/src/utils/test/dsl/index.cjs +1 -1
  21. package/dist/src/utils/test/dsl/index.d.cts +35 -11
  22. package/dist/src/utils/test/dsl/index.d.ts +35 -11
  23. package/dist/src/utils/test/dsl/index.js +1 -1
  24. package/dist/src/utils/test/index.cjs +36 -36
  25. package/dist/src/utils/test/index.js +1 -1
  26. package/dist/{test-VXSCSKV5.js → test-PCRWMQUO.js} +1 -1
  27. package/package.json +2 -2
  28. package/dist/ComboboxComponentStrategy-YSYLR2U5.js +0 -5
  29. package/dist/MenuComponentStrategy-C22BZEBH.js +0 -5
  30. package/dist/RelativeTargetResolver-T4P25J2M.js +0 -1
  31. package/dist/TabsComponentStrategy-ADEEFJXM.js +0 -1
  32. package/dist/chunk-BHNO4ZI3.js +0 -1
  33. package/dist/contractTestRunnerPlaywright-FOCQTM4L.js +0 -46
  34. package/dist/contractTestRunnerPlaywright-QPU6HZXG.js +0 -46
  35. package/dist/src/utils/test/ComboboxComponentStrategy-SICWLI27.js +0 -5
  36. package/dist/src/utils/test/MenuComponentStrategy-R4VPAHDE.js +0 -5
  37. package/dist/src/utils/test/RelativeTargetResolver-UQQMZHI6.js +0 -1
  38. package/dist/src/utils/test/TabsComponentStrategy-L2PYNEW6.js +0 -1
  39. package/dist/src/utils/test/chunk-BHNO4ZI3.js +0 -1
  40. package/dist/src/utils/test/contractTestRunnerPlaywright-YZCMF64Q.js +0 -46
@@ -0,0 +1,46 @@
1
+ import {d,a,c,e}from'./chunk-APUMBDOT.js';import {a as a$1}from'./chunk-WIWSYIGK.js';import {readFileSync}from'fs';import ge from'path';import {pathToFileURL}from'url';import {expect}from'@playwright/test';var ne=class{builtInStrategies=new Map;constructor(){this.registerBuiltInStrategies();}registerBuiltInStrategies(){this.builtInStrategies.set("menu",()=>import('./MenuComponentStrategy-QHVBLUBR.js').then(t=>t.MenuComponentStrategy)),this.builtInStrategies.set("accordion",()=>import('./AccordionComponentStrategy-X2GSQ5KT.js').then(t=>t.AccordionComponentStrategy)),this.builtInStrategies.set("combobox",()=>import('./ComboboxComponentStrategy-5AWO63DA.js').then(t=>t.ComboboxComponentStrategy)),this.builtInStrategies.set("tabs",()=>import('./TabsComponentStrategy-DTQQUCK2.js').then(t=>t.TabsComponentStrategy));}async loadStrategy(t,s,r){try{if(s)try{let n=ge.isAbsolute(s)?s:ge.resolve(r||process.cwd(),s),u=await import(pathToFileURL(n).href),i=u.default||u;if(!i)throw new Error(`No default export found in ${s}`);return i}catch(n){throw new Error(`Failed to load custom strategy from ${s}: ${n instanceof Error?n.message:String(n)}`)}let o=this.builtInStrategies.get(t);return o?o():null}catch(o){throw new Error(`Strategy loading failed for ${t}: ${o instanceof Error?o.message:String(o)}`)}}has(t,s){return !!s||this.builtInStrategies.has(t)}};var oe=class{static strategyRegistry=new ne;static isComponentConfig(t){return typeof t=="object"&&t!==null}static async detect(t,s,r=400,o=400,n){let u=this.isComponentConfig(s)?s:void 0,i=u?.contractPath;if(!i)throw new Error(`Contract path not found for component: ${t}`);let R=(()=>{if(ge.isAbsolute(i))return i;if(n){let re=ge.resolve(n,i);try{return readFileSync(re,"utf-8"),re}catch{}}let X=ge.resolve(process.cwd(),i);try{return readFileSync(X,"utf-8"),X}catch{return new URL(i,import.meta.url).pathname}})(),C=readFileSync(R,"utf-8"),ee=JSON.parse(C).selectors,_=await this.strategyRegistry.loadStrategy(t,u?.strategyPath,n);if(!_)return null;let z=ee.main;return t==="tabs"?new _(z,ee):new _(z,ee,r,o)}};var ae=class{startTime=0;componentName="";staticPasses=0;staticFailures=0;staticWarnings=0;dynamicResults=[];totalTests=0;skipped=0;warnings=0;isPlaywright=false;isCustomContract=false;apgUrl="https://www.w3.org/WAI/ARIA/apg/";hasPrintedStaticSection=false;hasPrintedDynamicSection=false;constructor(t=false,s=false){this.isPlaywright=t,this.isCustomContract=s;}log(t){process.stderr.write(t+`
2
+ `);}start(t,s,r){this.startTime=Date.now(),this.componentName=t,this.totalTests=s,this.hasPrintedStaticSection=false,this.hasPrintedDynamicSection=false,r&&(this.apgUrl=r);let o="Playwright (Real Browser)";this.log(`
3
+ ${"\u2550".repeat(60)}`),this.log(`\u{1F50D} Testing ${t.charAt(0).toUpperCase()+t.slice(1)} Component - ${o}`),this.log(`${"\u2550".repeat(60)}
4
+ `);}reportStatic(t,s,r=0){this.staticPasses=t,this.staticFailures=s,this.staticWarnings=r;}reportStaticTest(t,s,r,o){this.hasPrintedStaticSection||(this.log(`${"\u2500".repeat(60)}`),this.log("\u{1F9EA} Static Assertions"),this.log(`${"\u2500".repeat(60)}`),this.hasPrintedStaticSection=true);let n=s==="pass"?"\u2713":s==="warn"?"\u26A0":s==="skip"?"\u25CB":"\u2717";this.log(` ${n} ${t}`),o&&this.log(` \u21B3 level=${o}`),(s==="fail"||s==="warn"||s==="skip")&&r&&this.log(` \u21B3 ${r}`);}reportTest(t,s,r){this.hasPrintedDynamicSection||(this.log(""),this.log(`${"\u2500".repeat(60)}`),this.log("\u2328\uFE0F Dynamic Interaction Tests"),this.log(`${"\u2500".repeat(60)}`),this.hasPrintedDynamicSection=true);let o={description:t.description,status:s,failureMessage:r,level:t.level};s==="skip"&&(o.skipReason="Requires real browser (addEventListener events)"),this.dynamicResults.push(o);let n={pass:"\u2713",fail:"\u2717",warn:"\u26A0",skip:"\u25CB"},u=t.level?`[${t.level.toUpperCase()}] `:"";this.log(` ${n[s]} ${u}${t.description}`),s==="skip"&&!this.isPlaywright&&this.log(" \u21B3 Skipped (runs only in Playwright)"),s==="fail"&&r&&this.log(` \u21B3 ${r}`),s==="warn"&&r&&this.log(` \u21B3 ${r}`),s==="skip"&&r&&this.log(` \u21B3 ${r}`);}reportFailures(t){t.length!==0&&(this.log(`
5
+ ${"\u2500".repeat(60)}`),this.log(`\u274C Failures (${t.length}):
6
+ `),t.forEach((s,r)=>{this.log(`${r+1}. ${s}`),s.includes("aria-")?this.log(" \u{1F4A1} Add the missing ARIA attribute to improve screen reader support"):s.includes("focus")?this.log(" \u{1F4A1} Check keyboard event handlers and focus management"):s.includes("visible")&&this.log(" \u{1F4A1} Verify display/visibility styles and state management"),this.log("");}));}reportWarnings(){let t=this.dynamicResults.filter(s=>s.status==="warn");t.length===0&&this.staticWarnings===0||(this.log(`
7
+ ${"\u2500".repeat(60)}`),this.log(`\u26A0\uFE0F Warnings (${this.staticWarnings+t.length}):
8
+ `),this.log(`These checks are failing but treated as warnings under the active strictness mode.
9
+ `),t.forEach((s,r)=>{this.log(`${r+1}. ${s.description}`),s.failureMessage&&this.log(` \u21B3 ${s.failureMessage}`),s.level&&this.log(` \u21B3 level=${s.level}`);}),this.apgUrl&&this.log(`
10
+ Reference: ${this.apgUrl}
11
+ `));}reportSkipped(){if(this.skipped===0||this.isPlaywright)return;let t=this.dynamicResults.filter(s=>s.status==="skip");this.log(`
12
+ ${"\u2500".repeat(60)}`),this.log(`\u2139\uFE0F Skipped Tests (${this.skipped}):
13
+ `),this.log("These tests use native keyboard events via addEventListener,"),this.log(`which only run in Playwright (real browser).
14
+ `),t.forEach((s,r)=>{this.log(`${r+1}. ${s.description}`);}),this.log(`
15
+ \u{1F4A1} Run with Playwright for full validation:`),this.log(` testUiComponent('${this.componentName}', null, 'http://localhost:5173/test-harness?component=component_name')
16
+ `);}summary(t){let s=Date.now()-this.startTime,r=this.dynamicResults.filter(A=>A.status==="pass").length,o=this.dynamicResults.filter(A=>A.status==="fail").length,n=this.dynamicResults.filter(A=>A.status==="warn").length;this.skipped=this.dynamicResults.filter(A=>A.status==="skip").length,this.warnings=this.staticWarnings+n;let u=this.staticPasses+r,i=this.staticFailures+o,R=u+i+this.warnings,C=()=>{let A=`${this.componentName.charAt(0).toUpperCase()}${this.componentName.slice(1)}`;return this.isCustomContract?`${A} component validates against your custom accessibility policy \u2713`:`${A} component meets Aria-Ease baseline WAI-ARIA expectations \u2713`};return t.length>0&&this.reportFailures(t),this.reportWarnings(),this.reportSkipped(),this.log(`
17
+ ${"\u2550".repeat(60)}`),this.log(`\u{1F4CA} Summary
18
+ `),i===0&&this.skipped===0&&this.warnings===0?(this.log(`\u2705 All ${R} tests passed!`),this.log(` ${C()}`)):i===0?(this.log(`\u2705 ${u}/${R} tests passed`),this.skipped>0&&this.log(`\u25CB ${this.skipped} tests skipped`),this.warnings>0&&this.log(`\u26A0\uFE0F ${this.warnings} warning${this.warnings>1?"s":""}`),this.log(` ${C()}`)):(this.log(`\u274C ${i} test${i>1?"s":""} failed`),this.log(`\u2705 ${u} test${u>1?"s":""} passed`),this.warnings>0&&this.log(`\u26A0\uFE0F ${this.warnings} warning${this.warnings>1?"s":""}`),this.skipped>0&&this.log(`\u25CB ${this.skipped} test${this.skipped>1?"s":""} skipped`)),this.log(`\u23F1\uFE0F Duration: ${s}ms`),this.log(`${"\u2550".repeat(60)}
19
+ `),i>0?(this.log("\u{1F527} Next Steps:"),this.log(" 1. Review the failures above"),this.log(" 2. Fix ARIA attributes and keyboard handlers"),this.log(` 3. Re-run tests to verify fixes
20
+ `)):!this.isPlaywright&&this.skipped>0&&this.log(`\u2728 Optional: Run Playwright tests for complete validation
21
+ `),{passes:u,failures:i,skipped:this.skipped,duration:s}}error(t,s){this.log(`
22
+ \u274C Error: ${t}`),s&&this.log(` Context: ${s}`),this.log("");}};var N=class{constructor(t,s,r=400){this.page=t;this.selectors=s;this.timeoutMs=r;}isBrowserClosedError(t){return t instanceof Error&&t.message.includes("Target page, context or browser has been closed")}async focus(t,s,r){try{if(t==="virtual"&&r){let n=this.selectors.main;if(!n)return {success:!1,error:"Main selector not defined for virtual focus."};let u=this.page.locator(n).first();return await u.count()?(await u.evaluate((R,C)=>{R.setAttribute("aria-activedescendant",C);},r),{success:!0}):{success:!1,error:"Main element not found for virtual focus."}}if(t==="relative"&&s){let n=this.selectors.relative;if(!n)return {success:!1,error:"Relative selector not defined for focus action."};let u=await a$1.resolve(this.page,n,s);return u?(await u.focus({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Could not resolve relative target ${s} for focus.`}}let o=this.selectors[t];return o?(await this.page.locator(o).first().focus({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Selector for focus target ${t} not found.`}}catch(o){return this.isBrowserClosedError(o)?{success:false,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:true}:{success:false,error:`Failed to focus ${t}: ${o instanceof Error?o.message:String(o)}`}}}async type(t,s){try{let r=this.selectors[t];return r?(await this.page.locator(r).first().fill(s,{timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Selector for type target ${t} not found.`}}catch(r){return this.isBrowserClosedError(r)?{success:false,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:true}:{success:false,error:`Failed to type into ${t}: ${r instanceof Error?r.message:String(r)}`}}}async click(t,s){try{if(t==="document")return await this.page.mouse.click(10,10),{success:!0};if(t==="relative"&&s){let o=this.selectors.relative;if(!o)return {success:!1,error:"Relative selector not defined for click action."};let n=await a$1.resolve(this.page,o,s);return n?(await n.click({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Could not resolve relative target ${s} for click.`}}let r=this.selectors[t];return r?(await this.page.locator(r).first().click({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Selector for action target ${t} not found.`}}catch(r){return this.isBrowserClosedError(r)?{success:false,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:true}:{success:false,error:`Failed to click ${t}: ${r instanceof Error?r.message:String(r)}`}}}async keypress(t,s,r){try{let n={Space:"Space",Enter:"Enter",Escape:"Escape","Arrow Up":"ArrowUp","Arrow Down":"ArrowDown","Arrow Left":"ArrowLeft","Arrow Right":"ArrowRight",Home:"Home",End:"End",Tab:"Tab"}[s]||s;if(n==="Space"?n=" ":n.includes(" ")&&(n=n.replace(/ /g,"")),t==="relative"){if(r==null)return {success:!1,error:"relativeTarget must be provided for relative keypress."};let C=this.selectors.relative;if(!C)return {success:!1,error:"Relative selector not defined for keypress action."};let A=await a$1.resolve(this.page,C,r);return A?(await A.press(n,{timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Could not resolve relative target ${r} for keypress.`}}let u=this.selectors[t];if(!u)return {success:!1,error:`Selector for keypress target ${t} not found.`};let i=this.page.locator(u).first();return await i.count()===0?{success:!1,error:`${t} element not found.`,shouldBreak:!0}:(await i.press(n,{timeout:this.timeoutMs}),{success:!0})}catch(o){return this.isBrowserClosedError(o)?{success:false,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:true}:{success:false,error:`Failed to press ${s} on ${t}: ${o instanceof Error?o.message:String(o)}`}}}async hover(t,s){try{if(t==="relative"&&s){let o=this.selectors.relative;if(!o)return {success:!1,error:"Relative selector not defined for hover action."};let n=await a$1.resolve(this.page,o,s);return n?(await n.hover({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Could not resolve relative target ${s} for hover.`}}let r=this.selectors[t];return r?(await this.page.locator(r).first().hover({timeout:this.timeoutMs}),{success:!0}):{success:!1,error:`Selector for hover target ${t} not found.`}}catch(r){return this.isBrowserClosedError(r)?{success:false,error:"CRITICAL: Browser/page closed during test execution. Remaining actions skipped.",shouldBreak:true}:{success:false,error:`Failed to hover ${t}: ${r instanceof Error?r.message:String(r)}`}}}};var se=class{constructor(t,s,r=400){this.page=t;this.selectors=s;this.timeoutMs=r;}async resolveTarget(t,s,r){try{if(t==="relative"){let n=r?this.selectors[r]:this.selectors.relative;if(!n)return {target:null,error:"Relative selector is not defined in the contract."};if(!s)return {target:null,error:"Relative target or expected value is not defined."};let u=await a$1.resolve(this.page,n,s);return u?{target:u}:{target:null,error:`Target ${t} not found.`}}let o=this.selectors[t];return o?{target:this.page.locator(o).first()}:{target:null,error:`Selector for assertion target ${t} not found.`}}catch(o){return {target:null,error:`Failed to resolve target ${t}: ${o instanceof Error?o.message:String(o)}`}}}async validateVisibility(t,s,r,o,n){try{return r?(await expect(t).toBeVisible({timeout:this.timeoutMs}),{success:!0,passMessage:`${s} is visible as expected. Test: "${n}".`}):(await expect(t).toBeHidden({timeout:this.timeoutMs}),{success:!0,passMessage:`${s} is not visible as expected. Test: "${n}".`})}catch{let u=this.selectors[s]||"",i=await this.page.evaluate(R=>{let C=R?document.querySelector(R):null;if(!C)return "element not found";let A=window.getComputedStyle(C);return `display:${A.display}, visibility:${A.visibility}, opacity:${A.opacity}`},u);return r?{success:false,failMessage:`${o} (actual: ${i})`}:{success:false,failMessage:`${o} ${s} is still visible (actual: ${i}).`}}}async validateAttribute(t,s,r,o,n,u){if(o==="!empty"){let C=await t.getAttribute(r);return C&&C.trim()!==""?{success:true,passMessage:`${s} has non-empty "${r}". Test: "${u}".`}:{success:false,failMessage:`${n} ${s} "${r}" should not be empty, found "${C}".`}}if(typeof o!="string")throw console.error("[AssertionRunner] expectedValue is not a string:",o),new Error(`AssertionRunner: expectedValue for attribute assertion must be a string, but got: ${JSON.stringify(o)}`);let i=o.split(" | ").map(C=>C.trim()),R=await t.getAttribute(r);return R!==null&&i.includes(R)?{success:true,passMessage:`${s} has expected "${r}". Test: "${u}".`}:{success:false,failMessage:`${n} ${s} "${r}" should be "${o}", found "${R}".`}}async validateValue(t,s,r,o,n){let u=await t.inputValue().catch(()=>"");return r==="!empty"?u&&u.trim()!==""?{success:true,passMessage:`${s} has non-empty value. Test: "${n}".`}:{success:false,failMessage:`${o} ${s} value should not be empty, found "${u}".`}:r===""?u===""?{success:true,passMessage:`${s} has empty value. Test: "${n}".`}:{success:false,failMessage:`${o} ${s} value should be empty, found "${u}".`}:u===r?{success:true,passMessage:`${s} has expected value. Test: "${n}".`}:{success:false,failMessage:`${o} ${s} value should be "${r}", found "${u}".`}}async validateFocus(t,s,r,o,n){try{return r?(await expect(t).toBeFocused({timeout:this.timeoutMs}),{success:!0,passMessage:`${s} has focus as expected. Test: "${n}".`}):(await expect(t).not.toBeFocused({timeout:this.timeoutMs}),{success:!0,passMessage:`${s} does not have focus as expected. Test: "${n}".`})}catch{let u=await this.page.evaluate(()=>{let i=document.activeElement;return i?`${i.tagName}#${i.id||"no-id"}.${i.className||"no-class"}`:"no element focused"});return {success:false,failMessage:`${o} (actual focus: ${u})`}}}async validateRole(t,s,r,o,n){let u=await t.getAttribute("role");return u===r?{success:true,passMessage:`${s} has role "${r}". Test: "${n}".`}:{success:false,failMessage:`${o} Expected role "${r}", found "${u}".`}}async validate(t,s){if(this.page.isClosed())return {success:false,failMessage:"CRITICAL: Browser/page closed before completing all tests. Increase test timeout or reduce test complexity."};let r=null,o;if(t.controlledBy){let n=t.controlledBy,u=this.selectors[n.target];if(!u)return {success:false,failMessage:`Selector for controlledBy.target '${n.target}' not found.`,target:null};let i=null;if(n.relativeTarget?i=await a$1.resolve(this.page,u,n.relativeTarget):i=this.page.locator(u).first(),!i)return {success:false,failMessage:"Controlling element for controlledBy not found.",target:null};let R=n.attribute||"aria-controls",C=await i.getAttribute(R);if(!C)return {success:false,failMessage:`Controlling element does not have attribute '${R}'.`,target:null};if(r=this.page.locator(`#${C}`),!r||await r.count()===0)return {success:false,failMessage:`Controlled element with id '${C}' not found.`,target:null}}else {let n=await this.resolveTarget(t.target,t.relativeTarget||t.expectedValue,t.selectorKey);if(r=n.target,o=n.error,o||!r)return {success:false,failMessage:o||`Target ${t.target} not found.`,target:null}}if(t.target==="input"&&t.attribute==="aria-activedescendant"&&t.expectedValue==="!empty"&&t.relativeTarget&&t.selectorKey){let n=await a$1.resolve(this.page,this.selectors[t.selectorKey],t.relativeTarget),u=n?await n.getAttribute("id"):null,i=await r.getAttribute("aria-activedescendant");return u&&i===u?{success:true,passMessage:`input[aria-activedescendant] matches id of ${t.relativeTarget}(${t.selectorKey}). Test: "${s}".`}:{success:false,failMessage:`input[aria-activedescendant] should match id of ${t.relativeTarget}(${t.selectorKey}), found "${i}".`}}switch(t.assertion){case "toBeVisible":return this.validateVisibility(r,t.target,true,t.failureMessage||"",s);case "notToBeVisible":return this.validateVisibility(r,t.target,false,t.failureMessage||"",s);case "toHaveAttribute":return t.attribute&&t.expectedValue!==void 0?this.validateAttribute(r,t.target,t.attribute,t.expectedValue,t.failureMessage||"",s):{success:false,failMessage:"Missing attribute or expectedValue for toHaveAttribute assertion"};case "toHaveValue":return t.expectedValue!==void 0?this.validateValue(r,t.target,t.expectedValue,t.failureMessage||"",s):{success:false,failMessage:"Missing expectedValue for toHaveValue assertion"};case "toHaveFocus":return this.validateFocus(r,t.target,true,t.failureMessage||"",s);case "notToHaveFocus":return this.validateFocus(r,t.target,false,t.failureMessage||"",s);case "toHaveRole":return t.expectedValue!==void 0?this.validateRole(r,t.target,t.expectedValue,t.failureMessage||"",s):{success:false,failMessage:"Missing expectedValue for toHaveRole assertion"};default:return {success:false,failMessage:`Unknown assertion type: ${t.assertion}`}}}};async function tt(M,t,s,r,o){let n=r?.test?.components?.find(d=>d.name===M),u=!!n?.contractPath,i=new ae(true,u),R={actionTimeoutMs:400,assertionTimeoutMs:400,navigationTimeoutMs:3e4,componentReadyTimeoutMs:5e3},C=r?.test?.disableTimeouts===true,ee=n?.disableTimeouts===true||C,_=(d,H,O)=>{if(ee)return 0;let F=d??H;return typeof F!="number"||!Number.isFinite(F)||F<0?O:F},z=_(n?.actionTimeoutMs,r?.test?.actionTimeoutMs,R.actionTimeoutMs),X=_(n?.assertionTimeoutMs,r?.test?.assertionTimeoutMs,R.assertionTimeoutMs),re=_(n?.navigationTimeoutMs,r?.test?.navigationTimeoutMs,R.navigationTimeoutMs),le=_(n?.componentReadyTimeoutMs,r?.test?.componentReadyTimeoutMs,R.componentReadyTimeoutMs),me=d(s),Y=n?.contractPath;if(!Y)throw new Error(`Contract path not found for component: ${M}`);let Re=(()=>{if(ge.isAbsolute(Y))return Y;if(o){let H=ge.resolve(o,Y);try{return readFileSync(H,"utf-8"),H}catch{}}let d=ge.resolve(process.cwd(),Y);try{return readFileSync(d,"utf-8"),d}catch{return new URL(Y,import.meta.url).pathname}})(),Ae=readFileSync(Re,"utf-8"),b=JSON.parse(Ae),Me=(b.relationships?.length||0)+(b.static[0]?.assertions.length||0)+b.dynamic.length,Ee=b.meta?.source?.apg,V=[],K=[],q=[],x=[],y=null,E=(d,H)=>{let O=c(H),F=e(O,me);if(F==="error")return V.push(d),{status:"fail",level:O,detail:d};if(F==="warning")return K.push(d),{status:"warn",level:O,detail:d};let D=`${d} (ignored by strictness=${me}, level=${O})`;return x.push(D),{status:"skip",level:O,detail:D}};try{if(y=await a(),t){try{await y.goto(t,{waitUntil:"domcontentloaded",timeout:re});}catch(e){throw new Error(`Failed to navigate to ${t}. Ensure dev server is running and accessible. Original error: ${e instanceof Error?e.message:String(e)}`)}await y.addStyleTag({content:"* { transition: none !important; animation: none !important; }"});}let d=await oe.detect(M,n,z,X,o);if(!d)throw new Error(`Unsupported component: ${M}`);let H=d.getMainSelector();if(!H)throw new Error(`CRITICAL: No selector found in contract for ${M}`);try{await y.locator(H).first().waitFor({state:"attached",timeout:le});}catch(e){throw new Error(`
23
+ \u274C CRITICAL: Component not found on page!
24
+ This usually means:
25
+ - The component didn't render
26
+ - The URL is incorrect
27
+ - The component selector '${H}' in the contract is wrong
28
+ - Original error: ${e}`)}i.start(M,Me,Ee),M==="menu"&&b.selectors.main&&await y.locator(b.selectors.main).first().waitFor({state:"visible",timeout:le}).catch(()=>{});let O=M==="menu"&&b.selectors.submenuTrigger?await y.locator(b.selectors.submenuTrigger).count()>0:!1,F=e=>e.type==="aria-reference"&&[e.from,e.to].some(p=>["submenu","submenuTrigger","submenuItems"].includes(p||""))||e.type==="contains"&&[e.parent,e.child].some(p=>["submenu","submenuTrigger","submenuItems"].includes(p||"")),D=0,P=0,I=0;for(let e of b.relationships||[]){if(d&&typeof d.resetState=="function")try{await d.resetState(y);}catch(g){K.push(`Warning: resetState failed before relationship test: ${g instanceof Error?g.message:String(g)}`);}let p=c(e.level);if(Array.isArray(e.setup)&&e.setup.length>0){let w=function(l){return h.includes(l)};var ve=w;let g=new N(y,b.selectors,z),S=e.type==="aria-reference"?`${e.from}.${e.attribute} references ${e.to}`:`${e.parent} contains ${e.child}`,h=["focus","type","click","keypress","hover"],m=l=>({...l,type:w(l.type)?l.type:"click"}),$=e.setup.map(m),k=await ue($,g,d,y,S,["submenu","submenuTrigger","submenuItems"]);if(k.skip){x.push(k.message||"Setup action skipped"),i.reportStaticTest(S,"skip",k.message,p);continue}if(!k.success){let l=`Relationship setup failed: ${k.error}`,c=E(l,e.level);c.status==="fail"&&(P+=1),c.status==="warn"&&(I+=1),i.reportStaticTest(S,c.status,c.detail,c.level);continue}}if(M==="menu"&&!O&&F(e)){let S=e.type==="aria-reference"?`${e.from}.${e.attribute} references ${e.to}`:`${e.parent} contains ${e.child}`,h="Skipping submenu relationship assertion: no submenu capability detected in rendered component.";x.push(h),i.reportStaticTest(S,"skip",h,p);continue}if(e.type==="aria-reference"){let g=`${e.from}.${e.attribute} references ${e.to}`,S=b.selectors[e.from],h=b.selectors[e.to];if(!S||!h){let f=E(`Relationship selector missing: from="${e.from}" or to="${e.to}" not found in selectors.`,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(g,f.status,f.detail,f.level);continue}let w=y.locator(S).first(),m=y.locator(h).first(),$=await w.count()>0,k=await m.count()>0;if(!$||!k){if(M==="menu"&&F(e)){let B="Skipping submenu relationship assertion in static phase: submenu elements are not present until submenu is opened.";x.push(B),i.reportStaticTest(g,"skip",B,p);continue}let f=E(`Relationship target not found: ${$?e.to:e.from}.`,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(g,f.status,f.detail,f.level);continue}let l=await w.getAttribute(e.attribute),c=await m.getAttribute("id");if(!c){let f=E(`Relationship target "${e.to}" must have an id for ${e.attribute} validation.`,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(g,f.status,f.detail,f.level);continue}if(!(l||"").split(/\s+/).filter(Boolean).includes(c)){let f=E(`Expected ${e.from} ${e.attribute} to reference id "${c}", found "${l||""}".`,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(g,f.status,f.detail,f.level);continue}q.push(`Relationship valid: ${e.from}.${e.attribute} -> ${e.to} (id=${c}).`),D+=1,i.reportStaticTest(g,"pass",void 0,p);continue}if(e.type==="contains"){let g=`${e.parent} contains ${e.child}`,S=b.selectors[e.parent],h=b.selectors[e.child];if(!S||!h){let l=E(`Relationship selector missing: parent="${e.parent}" or child="${e.child}" not found in selectors.`,e.level);l.status==="fail"&&(P+=1),l.status==="warn"&&(I+=1),i.reportStaticTest(g,l.status,l.detail,l.level);continue}let w=y.locator(S).first();if(!(await w.count()>0)){if(M==="menu"&&F(e)){let c="Skipping submenu relationship assertion in static phase: submenu container is not present until submenu is opened.";x.push(c),i.reportStaticTest(g,"skip",c,p);continue}let l=E(`Relationship parent target not found: ${e.parent}.`,e.level);l.status==="fail"&&(P+=1),l.status==="warn"&&(I+=1),i.reportStaticTest(g,l.status,l.detail,l.level);continue}if(await w.locator(h).count()<1){if(M==="menu"&&F(e)){let c="Skipping submenu relationship assertion in static phase: submenu descendants are not present until submenu is opened.";x.push(c),i.reportStaticTest(g,"skip",c,p);continue}let l=E(`Expected ${e.parent} to contain descendant matching selector for ${e.child}.`,e.level);l.status==="fail"&&(P+=1),l.status==="warn"&&(I+=1),i.reportStaticTest(g,l.status,l.detail,l.level);continue}q.push(`Relationship valid: ${e.parent} contains ${e.child}.`),D+=1,i.reportStaticTest(g,"pass",void 0,p);}}async function ye(e,p,g,S={}){if(!e||typeof e!="object"||!("ref"in e))return e;let h;if(e.ref==="relative"){if(!e.relativeTarget||!S.relativeBaseSelector)return;let w=g.locator(S.relativeBaseSelector),m=await w.count(),$=0;if(e.relativeTarget==="first"?$=0:e.relativeTarget==="second"?$=1:e.relativeTarget==="last"?$=m-1:isNaN(Number(e.relativeTarget))?$=0:$=Number(e.relativeTarget),$<0||$>=m)return;let k=w.nth($);return await we(k,e.property||e.attribute)}else {if(h=p[e.ref],!h)throw new Error(`Selector for ref '${e.ref}' not found in contract selectors.`);let w=g.locator(h).first();return await we(w,e.property||e.attribute)}}async function we(e,p){if(e)return !p||p==="id"?await e.getAttribute("id")??void 0:p==="class"?await e.getAttribute("class")??void 0:p==="textContent"?await e.evaluate(g=>g.textContent??void 0):p.startsWith("aria-")?await e.getAttribute(p)??void 0:p.endsWith("*")?await e.evaluate(S=>{let h=[];for(let w of Array.from(S.attributes))w.name.startsWith("aria-")&&h.push(`${w.name}=${w.value}`);return h.join(";")}):await e.getAttribute(p)??void 0}let xe=new se(y,b.selectors,X);async function ue(e,p,g,S,h,w=[]){if(!Array.isArray(e)||e.length===0)return {success:!0};g&&typeof g.resetState=="function"&&await g.resetState(S);for(let m of e){let $={success:!0};try{if(m.type==="focus")m.target==="relative"&&m.relativeTarget?$=await p.focus("relative",m.relativeTarget):$=await p.focus(m.target);else if(m.type==="type"&&m.value)$=await p.type(m.target,m.value);else if(m.type==="click")$=await p.click(m.target,m.relativeTarget);else if(m.type==="keypress"&&m.key)$=await p.keypress(m.target,m.key,m.relativeTarget);else if(m.type==="hover")$=await p.hover(m.target,m.relativeTarget);else continue}catch(k){$={success:!1,error:k instanceof Error?k.message:String(k)};}if(!$.success){let k=$.error||"Setup action failed";return w.some(c=>h.includes(c)||k.includes(c))?{success:!1,skip:!0,message:`Skipping test - capability not present: ${k}`}:{success:!1,error:k}}}return {success:!0}}for(let e of b.static[0]?.assertions||[]){if(d&&typeof d.resetState=="function")try{await d.resetState(y);}catch(l){K.push(`Warning: resetState failed before static test: ${l instanceof Error?l.message:String(l)}`);}if(e.target==="relative")continue;let p=`${e.target}${e.attribute?` (${e.attribute})`:""}`,g=c(e.level);if(M==="menu"&&e.target==="submenuTrigger"&&!O){let l=`Skipping submenu static assertion for ${e.target}: no submenu capability detected in rendered component.`;x.push(l),i.reportStaticTest(p,"skip",l,g);continue}let S=[];if(e.target||S.push("target"),e.attribute||S.push("attribute"),typeof e.expectedValue>"u"&&S.push("expectedValue"),S.length>0){let l=`${e.target||""}${e.attribute?` (${e.attribute})`:""}`,c=`Static assertion missing required field(s): ${S.join(", ")}`,v=E(c,e.level);v.status==="fail"&&(P+=1),v.status==="warn"&&(I+=1),i.reportStaticTest(l,v.status,v.detail,v.level);continue}if(Array.isArray(e.setup)&&e.setup.length>0){let v=function(a){return c.includes(a)};var ve=v;let l=new N(y,b.selectors,z),c=["focus","type","click","keypress","hover"],U=a=>({...a,type:v(a.type)?a.type:"click"}),f=e.setup.map(U),B=await ue(f,l,d,y,p,["submenu","submenuTrigger","submenuItems"]);if(B.skip){x.push(B.message||"Setup action skipped"),i.reportStaticTest(p,"skip",B.message,g);continue}if(!B.success){let a=`Static setup failed: ${B.error}`,T=E(a,e.level);T.status==="fail"&&(P+=1),T.status==="warn"&&(I+=1),i.reportStaticTest(p,T.status,T.detail,T.level);continue}}let h=b.selectors[e.target];if(!h){let l=`Selector for target ${e.target} not found.`,c=E(l,e.level);c.status==="fail"&&(P+=1),c.status==="warn"&&(I+=1),i.reportStaticTest(p,c.status,c.detail,c.level);continue}let w=y.locator(h).first();if(!(await w.count()>0)){let l=`Target ${e.target} not found.`,c=E(l,e.level);c.status==="fail"&&(P+=1),c.status==="warn"&&(I+=1),i.reportStaticTest(p,c.status,c.detail,c.level);continue}let $=(l,c,v)=>{let U=new RegExp(`\\[${c}(?:=["']?([^\\]"']+)["']?)?\\]`),f=l.match(U);if(!f)return !1;if(!v)return !0;let B=f[1];return B?v.split(" | ").includes(B):!1},k=e.expectedValue;if(e.expectedValue&&typeof e.expectedValue=="object"&&"ref"in e.expectedValue){let l={},c=e.relativeTarget;if(e.expectedValue.ref==="relative"&&e.target==="relative"&&c){let v=b.selectors[c];if(!v)throw new Error(`Selector for relativeTarget '${c}' not found in contract selectors.`);l.relativeBaseSelector=v;}else if(e.expectedValue.ref==="relative"&&c){let v=b.selectors[c];if(!v)throw new Error(`Selector for relativeTarget '${c}' not found in contract selectors.`);l.relativeBaseSelector=v;}k=await ye(e.expectedValue,b.selectors,y,l);}if(e.expectedValue)if($(h,e.attribute,typeof k=="string"?k:void 0))q.push(`${e.attribute}="${k}" on ${e.target} verified by selector (already present in: ${h}).`),D+=1,i.reportStaticTest(p,"pass",void 0,g);else {let l=k??"",c=await xe.validateAttribute(w,e.target,e.attribute,l,e.failureMessage,"Static ARIA Test");if(c.success&&c.passMessage)q.push(c.passMessage),D+=1,i.reportStaticTest(p,"pass",void 0,g);else if(!c.success&&c.failMessage){let v=E(c.failMessage,e.level);v.status==="fail"&&(P+=1),v.status==="warn"&&(I+=1),i.reportStaticTest(p,v.status,v.detail,v.level);}}else {let l=e.attribute.split(" | "),c=!1,v=!0;for(let U of l){let f=U.trim();if($(h,f)){q.push(`${f} on ${e.target} verified by selector (already present in: ${h}).`),c=!0;continue}if(v=!1,await w.getAttribute(f)!==null){c=!0;break}}if(!c&&!v){let U=e.failureMessage+` None of the attributes "${e.attribute}" are present.`,f=E(U,e.level);f.status==="fail"&&(P+=1),f.status==="warn"&&(I+=1),i.reportStaticTest(p,f.status,f.detail,f.level);}else !v&&c?(q.push(`At least one of the attributes "${e.attribute}" exists on the element.`),D+=1,i.reportStaticTest(p,"pass",void 0,g)):(D+=1,i.reportStaticTest(p,"pass",void 0,g));}}for(let e of b.dynamic||[]){if(!e.assertions||e.assertions.length===0){let a="Skipping test - no assertions found for this dynamic test.";x.push(a),i.reportTest({description:e.description,level:c(e.level)},"skip",a);continue}if(!y||y.isClosed()){console.warn(`
29
+ \u26A0\uFE0F Browser closed - skipping remaining ${b.dynamic.length-b.dynamic.indexOf(e)} tests
30
+ `),V.push(`CRITICAL: Browser/page closed before completing all tests. ${b.dynamic.length-b.dynamic.indexOf(e)} tests skipped.`);break}try{await d.resetState(y);}catch(a){let T=a instanceof Error?a.message:String(a);throw i.error(T),a}let{setup:p=[],action:g,assertions:S}=e,h=c(e.level),w=new N(y,b.selectors,z);if(Array.isArray(p)&&p.length>0){let T=function(L){return a.includes(L)};var ve=T;let a=["focus","type","click","keypress","hover"],Z=L=>({...L,type:T(L.type)?L.type:"click"}),pe=p.map(Z),W=await ue(pe,w,d,y,e.description,["submenu","submenuTrigger","submenuItems"]);if(W.skip){x.push(W.message||"Setup action skipped"),i.reportTest({description:e.description,level:h},"skip",W.message);continue}if(!W.success){let L=E(`Setup failed: ${W.error}`,e.level);i.reportTest({description:e.description,level:h},L.status,L.detail);continue}}let m=V.length,$=K.length,k=x.length;if(await d.shouldSkipTest(e,y)){let a="Skipping test - component-specific conditions not met";x.push(a),i.reportTest({description:e.description,level:h},"skip",a);continue}let c$1=new se(y,b.selectors,X),v=!1,U=null;for(let a of g){if(!y||y.isClosed()){V.push("CRITICAL: Browser/page closed during test execution. Remaining actions skipped."),v=!0;break}let T;if(a.type==="focus")a.target==="relative"&&a.relativeTarget?T=await w.focus("relative",a.relativeTarget):T=await w.focus(a.target);else if(a.type==="type"&&a.value)T=await w.type(a.target,a.value);else if(a.type==="click")T=await w.click(a.target,a.relativeTarget);else if(a.type==="keypress"&&a.key)T=await w.keypress(a.target,a.key,a.relativeTarget);else if(a.type==="hover")T=await w.hover(a.target,a.relativeTarget);else continue;if(!T.success){if(T.error){let Z=E(T.error,e.level);U={status:Z.status,detail:Z.detail};}v=!0;break}}if(v){i.reportTest({description:e.description,level:h},U?.status||"fail",U?.detail||V[V.length-1]);continue}for(let a of S){let T;if(a.expectedValue&&typeof a.expectedValue=="object"&&"ref"in a.expectedValue)if(a.expectedValue.ref==="relative"){let{RelativeTargetResolver:J}=await import('./RelativeTargetResolver-5SIQLWPN.js'),L=b.selectors.relative;if(!L)throw new Error("Relative selector not defined in contract selectors.");let te=a.relativeTarget||"first",G=await J.resolve(y,L,te);if(!G)throw new Error(`Could not resolve relative target '${te}' for expectedValue.`);let $e=a.expectedValue.property||a.expectedValue.attribute||"id";if($e==="textContent")T=await G.evaluate(ie=>ie.textContent??void 0);else {let ie=await G.getAttribute($e);T=ie===null?void 0:ie;}}else T=await ye(a.expectedValue,b.selectors,y,{});else typeof a.expectedValue=="string"||typeof a.expectedValue>"u"?T=a.expectedValue:T="";let Z={...a,expectedValue:T},pe=T??"",W=await c$1.validate({...Z,expectedValue:pe},e.description);if(W.success&&W.passMessage)q.push(W.passMessage);else if(!W.success&&W.failMessage){let J=[];if(a.target||J.push("target"),a.assertion||J.push("assertion"),["toHaveAttribute","toHaveValue","toHaveRole"].includes(a.assertion)&&(typeof a.attribute>"u"&&a.assertion==="toHaveAttribute"&&J.push("attribute"),typeof a.expectedValue>"u"&&J.push("expectedValue")),J.length>0){let L=c(a.level||e.level),te=`Dynamic assertion missing required field(s): ${J.join(", ")}`,G=E(te,L);if(G.status==="skip")continue;V.push(te),i.reportTest({description:e.description,level:L},G.status,G.detail);continue}}}let f=V.length,B=K.length,be=x.length;f>m?i.reportTest({description:e.description,level:h},"fail",V[V.length-1]):B>$?i.reportTest({description:e.description,level:h},"warn",K[K.length-1]):be>k?i.reportTest({description:e.description,level:h},"skip",x[x.length-1]):i.reportTest({description:e.description,level:h},"pass");}i.reportStatic(D,P,I),i.summary(V);}catch(d){if(d instanceof Error)throw d.message.includes("Executable doesn't exist")||d.message.includes("browserType.launch")?new Error(`
31
+ \u274C CRITICAL: Playwright browsers not found!
32
+ \u{1F4E6} Run: npx playwright install chromium`):d.message.includes("net::ERR_CONNECTION_REFUSED")||d.message.includes("NS_ERROR_CONNECTION_REFUSED")?new Error(`
33
+ \u274C CRITICAL: Cannot connect to dev server!
34
+ Make sure your dev server is running at ${t}`):d.message.includes("Timeout")&&d.message.includes("waitFor")?new Error(`
35
+ \u274C CRITICAL: Component not found on page!
36
+ The component selector could not be found within ${le}ms.
37
+ This usually means:
38
+ - The component didn't render
39
+ - The URL is incorrect
40
+ - The component selector was not provided to the component utility, or a wrong selector was used
41
+ `):d.message.includes("Target page, context or browser has been closed")?new Error(`
42
+ \u274C CRITICAL: Browser/page was closed unexpectedly!
43
+ This usually means:
44
+ - The test timeout was too short
45
+ - The browser crashed
46
+ - An external process killed the browser`):d}finally{y&&await y.close();}return {passes:q,failures:V,skipped:x,warnings:K}}export{tt as runContractTestsPlaywright};
@@ -1 +1 @@
1
- 'use strict';var A={"popup.open":{setup:[{when:["keyboard","textInput"],steps:()=>[{type:"keypress",target:"input",key:"ArrowDown"}]},{when:["pointer"],steps:()=>[{type:"click",target:"button"}]}],assertion:w},"popup.closed":{setup:[{when:["keyboard"],steps:()=>[]},{when:["pointer"],steps:()=>[]}],assertion:[...M(),...f()]},"main.focused":{setup:[{when:["keyboard"],steps:()=>[{type:"focus",target:"main"}]}],assertion:E},"main.notFocused":{setup:[{when:["keyboard"],steps:()=>[]}],assertion:D},"input.filled":{setup:[{when:["keyboard","textInput"],steps:()=>[{type:"type",target:"input",value:"test"}]}],assertion:C},"input.notFilled":{setup:[{when:["keyboard","textInput"],steps:()=>[{type:"type",target:"input",value:""}]}],assertion:I},"activeOption.first":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"input",key:"ArrowDown"}]}],assertion:q},"activeOption.last":{requires:["activeOption.first"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"input",key:"ArrowUp"}]}],assertion:S},"activeDescendant.notEmpty":{requires:[],setup:[{when:["keyboard"],steps:()=>[]}],assertion:T},"activeDescendant.Empty":{requires:[],setup:[{when:["keyboard"],steps:()=>[]}],assertion:f},"selectedOption.first":{requires:["popup.open"],setup:[{when:["pointer"],steps:()=>[{type:"click",target:"relative",relativeTarget:"first"}]}],assertion:()=>b("first")},"selectedOption.last":{requires:["popup.open"],setup:[{when:["pointer"],steps:()=>[{type:"click",target:"relative",relativeTarget:"last"}]}],assertion:()=>b("last")}};function w(){return [{target:"popup",assertion:"toBeVisible",failureMessage:"Expected popup to be visible"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expect combobox main to have aria-expanded='true'."}]}function M(){return [{target:"popup",assertion:"notToBeVisible",failureMessage:"Expected popup to be closed"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expect combobox main to have aria-expanded='false'."}]}function q(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:{ref:"relative",relativeTarget:"first",property:"id"},failureMessage:"Expected aria-activedescendant on main to match the id of the first option."}]}function S(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:{ref:"relative",relativeTarget:"last",property:"id"},failureMessage:"Expected aria-activedescendant on main to match the id of the last option."}]}function T(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:"!empty",failureMessage:"Expected aria-activedescendant on main to not be empty."}]}function f(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:"",failureMessage:"Expected aria-activedescendant on main to be empty."}]}function b(a){return [{target:"relative",relativeTarget:a,assertion:"toHaveAttribute",attribute:"aria-selected",expectedValue:"true",failureMessage:`Expected ${a} option to have aria-selected='true'.`}]}function E(){return [{target:"main",assertion:"toHaveFocus",failureMessage:"Expected main to be focused."}]}function D(){return [{target:"main",assertion:"notToHaveFocus",failureMessage:"Expected main to not have focused."}]}function C(){return [{target:"input",assertion:"toHaveValue",expectedValue:"test",failureMessage:"Expected input to have the value 'test'."}]}function I(){return [{target:"input",assertion:"toHaveValue",expectedValue:"",failureMessage:"Expected input to have the value ''."}]}var x={"popup.open":{setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"main",key:"Enter"}]},{when:["pointer"],steps:()=>[{type:"click",target:"main"}]}],assertion:V},"popup.closed":{setup:[{when:["keyboard"],steps:()=>[]},{when:["pointer"],steps:()=>[]}],assertion:_},"main.focused":{setup:[{when:["keyboard"],steps:()=>[{type:"focus",target:"main"}]}],assertion:F},"main.notFocused":{setup:[{when:["keyboard"],steps:()=>[]}],assertion:H},"activeItem.first":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[]}],assertion:P},"activeItem.last":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"main",key:"ArrowUp"}]}],assertion:O},"submenu.open":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"submenuTrigger",key:"ArrowRight"}]},{when:["pointer"],steps:()=>[{type:"click",target:"submenuTrigger"}]}],assertion:B},"submenu.closed":{requires:["submenu.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"submenuTrigger",key:"ArrowLeft"}]},{when:["pointer"],steps:()=>[{type:"click",target:"submenuTrigger"}]}],assertion:R},"submenuTrigger.focused":{setup:[{when:["keyboard"],steps:()=>[{type:"focus",target:"submenuTrigger"}]}],assertion:L},"submenuTrigger.notFocused":{setup:[{when:["keyboard"],steps:()=>[]}],assertion:z},"submenuActiveItem.first":{requires:["submenu.open"],setup:[{when:["keyboard"],steps:()=>[]},{when:["pointer"],steps:()=>[]}],assertion:J}};function V(){return [{target:"popup",assertion:"toBeVisible",failureMessage:"Expected popup to be visible"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expect menu main to have aria-expanded='true'."}]}function _(){return [{target:"popup",assertion:"notToBeVisible",failureMessage:"Expected popup to be closed"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expect menu main to have aria-expanded='false'."}]}function F(){return [{target:"main",assertion:"toHaveFocus",failureMessage:"Expected menu main to be focused."}]}function H(){return [{target:"main",assertion:"notToHaveFocus",failureMessage:"Expected menu main to not have focused."}]}function P(){return [{target:"relative",assertion:"toHaveFocus",expectedValue:"first",failureMessage:"First menu item should have focus."}]}function O(){return [{target:"relative",assertion:"toHaveFocus",expectedValue:"last",failureMessage:"Last menu item should have focus."}]}function B(){return [{target:"submenu",assertion:"toBeVisible",failureMessage:"Expected submenu to be visible"},{target:"submenuTrigger",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expect submenu trigger to have aria-expanded='true'."}]}function R(){return [{target:"submenu",assertion:"notToBeVisible",failureMessage:"Expected submenu to be closed"},{target:"submenuTrigger",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expect submenu trigger to have aria-expanded='false'."}]}function L(){return [{target:"submenuTrigger",assertion:"toHaveFocus",failureMessage:"Expected submenu trigger to be focused."}]}function z(){return [{target:"submenuTrigger",assertion:"notToHaveFocus",failureMessage:"Expected submenu trigger to not have focused."}]}function J(){return [{target:"submenuItems",assertion:"toHaveFocus",failureMessage:"First interactive item in the submenu should have focus after Right Arrow open the submenu."}]}function N(a,e){return e.some(o=>a.capabilities.includes(o))}function v(a,e){Array.isArray(a)&&a.length&&!a[0].when&&(a=[{when:["keyboard"],steps:()=>a}]);for(let o of a)if(N(e,o.when))return o.steps(e);throw new Error(`No setup strategy matches capabilities: ${e.capabilities.join(", ")}`)}var U={combobox:A,menu:x},h=class{constructor(e){this.jsonContract=e;}toJSON(){return this.jsonContract}},y=class{constructor(e){this.componentName=e;this.statePack=U[e]||{};}metaValue={};selectorsValue={};relationshipInvariants=[];staticAssertions=[];dynamicTests=[];statePack;meta(e){return this.metaValue=e,this}selectors(e){return this.selectorsValue=e,this}relationships(e){let o=this.statePack,p={capabilities:["keyboard"]},c=(t,i=new Set)=>{if(i.has(t))return [];i.add(t);let s=o[t];if(!s)return [];let r=[];if(Array.isArray(s.requires))for(let n of s.requires)r=r.concat(c(n,i));return s.setup&&(r=r.concat(v(s.setup,p))),r};return e({ariaReference:(t,i,s)=>({requires:r=>{let n=c(r,new Set);return {required:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"required",setup:n}),optional:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"optional",setup:n}),recommended:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"recommended",setup:n})}},required:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"required"}),optional:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"optional"}),recommended:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"recommended"})}),contains:(t,i)=>({requires:s=>{let r=c(s,new Set);return {required:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"required",setup:r}),optional:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"optional",setup:r}),recommended:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"recommended",setup:r})}},required:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"required"}),optional:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"optional"}),recommended:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"recommended"})})}),this}static(e){return e({target:p=>{let c=t=>{let i=this.statePack,s={capabilities:["keyboard"]},r=(n,u=new Set)=>{if(u.has(n))return [];u.add(n);let d=i[n];if(!d)return [];let g=[];if(Array.isArray(d.requires))for(let k of d.requires)g=g.concat(r(k,u));return d.setup&&(g=g.concat(v(d.setup,s))),g};return r(t,new Set)},l=(t,i,s)=>({required:()=>this.staticAssertions.push({target:p,attribute:t,expectedValue:i,failureMessage:"",level:"required",setup:s}),optional:()=>this.staticAssertions.push({target:p,attribute:t,expectedValue:i,failureMessage:"",level:"optional",setup:s}),recommended:()=>this.staticAssertions.push({target:p,attribute:t,expectedValue:i,failureMessage:"",level:"recommended",setup:s})});return {has:(t,i)=>({...l(t,i),requires:r=>{let n=c(r);return l(t,i,n)}})}}}),this}when(e){return new m(this,this.statePack,e)}addDynamicTest(e){this.dynamicTests.push(e);}build(){return {meta:this.metaValue,selectors:this.selectorsValue,relationships:this.relationshipInvariants.length?this.relationshipInvariants:void 0,static:this.staticAssertions.length?[{assertions:this.staticAssertions}]:[],dynamic:this.dynamicTests}}},m=class{constructor(e,o,p){this.parent=e;this.statePack=o;this.event=p;}_as;_on;_given=[];_then=[];_desc="";_level="required";as(e){return this._as=e,this}on(e){return this._on=e,this}given(e){return this._given=Array.isArray(e)?e:[e],this}then(e){return this._then=Array.isArray(e)?e:[e],this}describe(e){return this._desc=e,this}required(){return this._level="required",this._finalize(),this.parent}optional(){return this._level="optional",this._finalize(),this.parent}recommended(){return this._level="recommended",this._finalize(),this.parent}_finalize(){let p={capabilities:[{keypress:"keyboard",click:"pointer",type:"textInput",focus:"keyboard",hover:"pointer"}[this._as||"keyboard"]||this._as||"keyboard"]},c=(s,r=new Set)=>{if(r.has(s))return [];r.add(s);let n=this.statePack[s];if(!n)return [];let u=[];if(Array.isArray(n.requires))for(let d of n.requires)u=u.concat(c(d,r));return n.setup&&(u=u.concat(v(n.setup,p))),u},l=[];for(let s of this._given)l.push(...c(s));let t=[];for(let s of this._then){let r=this.statePack[s];if(r&&r.assertion!==void 0){let n=r.assertion;if(typeof n=="function")try{n=n();}catch(u){throw new Error(`Error calling assertion function for state '${s}': ${u.message}`)}Array.isArray(n)?t.push(...n):t.push(n);}}let i=[{type:this._as,target:this._on,key:this._as==="keypress"?this.event:void 0}];this.parent.addDynamicTest({description:this._desc||"",level:this._level,action:i,assertions:t,...l.length?{setup:l}:{}});}};function Y(a,e){let o=new y(a);return e(o),new h(o.build())}exports.createContract=Y;
1
+ 'use strict';var A={"comboboxpopup.open":{setup:[{when:["keyboard","textInput","pointer"],steps:()=>[{type:"keypress",target:"input",key:"ArrowDown"}]},{when:["pointer"],steps:()=>[{type:"click",target:"button"}]}],assertion:w},"comboboxpopup.closed":{setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:[...S(),...h()]},"main.focused":{setup:[{when:["keyboard","pointer"],steps:()=>[{type:"focus",target:"main"}]}],assertion:q},"main.blurred":{setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:D},"input.filled":{setup:[{when:["keyboard","textInput","pointer"],steps:()=>[{type:"type",target:"input",value:"test"}]}],assertion:C},"input.empty":{setup:[{when:["keyboard","textInput","pointer"],steps:()=>[{type:"type",target:"input",value:""}]}],assertion:V},"option.active":{requires:["comboboxpopup.open"],setup:[{when:["keyboard","pointer"],steps:(e={})=>typeof e.relativeTarget=="number"?Array.from({length:e.relativeTarget},()=>({type:"keypress",target:"main",key:"ArrowDown"})):e.relativeTarget==="first"?[{type:"keypress",target:"main",key:"ArrowDown"}]:e.relativeTarget==="last"?[{type:"keypress",target:"main",key:"ArrowDown"},{type:"keypress",target:"main",key:"ArrowUp"}]:[]}],assertion:(e={})=>M(e.relativeTarget)},"activedescendant.set":{requires:[],setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:E},"activedescendant.unset":{requires:[],setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:h},"option.selected":{requires:["comboboxpopup.open"],setup:[{when:["keyboard"],steps:(e={})=>[{type:"keypress",target:"relative",key:"Enter",relativeTargeta:e.relativeTarget}]},{when:["pointer"],steps:(e={})=>[{type:"click",target:"relative",relativeTargeta:e.relativeTarget}]}],assertion:(e={})=>_(e.relativeTarget)}};function w(){return [{target:"popup",assertion:"toBeVisible",failureMessage:"Expected popup to be visible"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expected combobox main to have aria-expanded='true'."}]}function S(){return [{target:"popup",assertion:"notToBeVisible",failureMessage:"Expected popup to be closed"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expected combobox main to have aria-expanded='false'."}]}function M(e){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:{ref:"relative",relativeTarget:e,property:"id"},failureMessage:"Expected aria-activedescendant on main to match the id of the first relative item."}]}function E(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:"!empty",failureMessage:"Expected aria-activedescendant on main to not be empty."}]}function h(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:"",failureMessage:"Expected aria-activedescendant on main to be empty."}]}function _(e){return [{target:"relative",relativeTarget:e,assertion:"toHaveAttribute",attribute:"aria-selected",expectedValue:"true",failureMessage:`Expected ${e} item to have aria-selected='true'.`}]}function q(){return [{target:"main",assertion:"toHaveFocus",failureMessage:"Expected main to be focused."}]}function D(){return [{target:"main",assertion:"notToHaveFocus",failureMessage:"Expected main to not have focused."}]}function C(){return [{target:"input",assertion:"toHaveValue",expectedValue:"test",failureMessage:"Expected input to have the value 'test'."}]}function V(){return [{target:"input",assertion:"toHaveValue",expectedValue:"",failureMessage:"Expected input to have the value ''."}]}var T={"menupopup.open":{setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"main",key:"Enter"}]},{when:["pointer"],steps:()=>[{type:"click",target:"main"}]}],assertion:H},"menupopup.closed":{setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:I},"main.focused":{setup:[{when:["keyboard","pointer"],steps:()=>[{type:"focus",target:"main"}]}],assertion:R},"main.blurred":{setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:B},"menuitem.focused":{requires:["menupopup.open"],setup:[{when:["keyboard"],steps:(e={})=>[{type:"focus",target:"relative",relativeTarget:e.relativeTarget}]}],assertion:(e={})=>P(e.relativeTarget)},"submenupopup.open":{requires:["menupopup.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"submenuTrigger",key:"ArrowRight"}]},{when:["pointer"],steps:()=>[{type:"click",target:"submenuTrigger"}]}],assertion:F},"submenupopup.closed":{setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:z},"submenutrigger.focused":{setup:[{when:["keyboard","pointer"],steps:()=>[{type:"focus",target:"submenuTrigger"}]}],assertion:O},"submenutrigger.blurred":{setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:$},"submenuitem.focused":{requires:["submenupopup.open"],setup:[{when:["keyboard"],steps:(e={})=>{let t=[{type:"focus",target:"submenuTrigger"},{type:"keypress",target:"submenuTrigger",key:"ArrowRight"}];return typeof e.relativeTarget=="number"&&(t=t.concat(Array.from({length:e.relativeTarget},()=>({type:"keypress",target:"submenuItems",key:"ArrowDown"})))),e.relativeTarget==="first"&&(t=t.concat({type:"keypress",target:"submenuItems",key:"ArrowDown"})),e.relativeTarget==="last"&&(t=t.concat({type:"keypress",target:"submenuItems",key:"ArrowUp"})),t}},{when:["pointer"],steps:(e={})=>[{type:"click",target:"submenuTrigger"},{type:"click",target:"relative",relativeTarget:e.relativeTarget}]}],assertion:(e={})=>L(e.relativeTarget)}};function H(){return [{target:"popup",assertion:"toBeVisible",failureMessage:"Expected popup to be visible"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expected menu main to have aria-expanded='true'."}]}function I(){return [{target:"popup",assertion:"notToBeVisible",failureMessage:"Expected popup to be closed"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expected menu main to have aria-expanded='false'."}]}function R(){return [{target:"main",assertion:"toHaveFocus",failureMessage:"Expected menu main to be focused."}]}function B(){return [{target:"main",assertion:"notToHaveFocus",failureMessage:"Expected menu main to not have focused."}]}function P(e){return [{target:"relative",assertion:"toHaveFocus",expectedValue:e,failureMessage:`${e} menu item should have focus.`}]}function F(){return [{target:"submenu",assertion:"toBeVisible",failureMessage:"Expected submenu to be visible"},{target:"submenuTrigger",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expected submenu trigger to have aria-expanded='true'."}]}function z(){return [{target:"submenu",assertion:"notToBeVisible",failureMessage:"Expected submenu to be closed"},{target:"submenuTrigger",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expected submenu trigger to have aria-expanded='false'."}]}function O(){return [{target:"submenuTrigger",assertion:"toHaveFocus",failureMessage:"Expected submenu trigger to be focused."}]}function $(){return [{target:"submenuTrigger",assertion:"notToHaveFocus",failureMessage:"Expected submenu trigger to not have focused."}]}function L(e){return [{target:"relative",relativeTarget:e,assertion:"toHaveFocus",failureMessage:`Expected submenu item ${e} to have focus.`}]}var k={"tab.active":{setup:[{when:["keyboard"],steps:(e={})=>[{type:"keypress",target:"relative",relativeTarget:e.relativeTarget,key:"ArrowLeft"}]},{when:["pointer"],steps:(e={})=>[{type:"click",target:"relative",relativeTarget:e.relativeTarget}]}],assertion:(e={})=>K(e.relativeTarget)},"tab.focused":{setup:[{when:["keyboard","pointer"],steps:(e={})=>[{type:"focus",target:"relative",relativeTarget:e.relativeTarget}]}],assertion:(e={})=>j(e.relativeTarget)}};function j(e){return [{target:"relative",assertion:"toHaveFocus",relativeTarget:e,failureMessage:"Expected first tab to have focus."}]}function J(e){return [{target:"relative",assertion:"toHaveAttribute",attribute:"aria-selected",expectedValue:"true",relativeTarget:e,failureMessage:`Expected ${e} tab to have tabindex='0'.`}]}function K(e){return [{target:"relative",assertion:"toHaveAttribute",attribute:"aria-selected",expectedValue:"true",relativeTarget:e,failureMessage:`Expected ${e} tab to have aria-selected='true'.`},{target:"panel",assertion:"toBeVisible",controlledBy:{target:"relative",relativeTarget:e},failureMessage:`Expected panel controlled by the ${e} tab to be visible.`},J(e)]}function U(e,t){return t.some(c=>e.capabilities.includes(c))}function y(e,t){Array.isArray(e)&&e.length&&!e[0].when&&(e=[{when:["keyboard"],steps:()=>e}]);for(let c of e)if(U(t,c.when))return c.steps(t);throw new Error(`No setup strategy matches capabilities: ${t.capabilities.join(", ")}`)}var X={combobox:A,menu:T,tabs:k},m=class{constructor(t){this.jsonContract=t;}toJSON(){return this.jsonContract}},f=class{constructor(t){this.componentName=t;this.statePack=X[t]||{};}metaValue={};selectorsValue={};relationshipInvariants=[];staticAssertions=[];dynamicTests=[];statePack;meta(t){return this.metaValue=t,this}selectors(t){return this.selectorsValue=t,this}relationships(t){let c=this.statePack,p={capabilities:["keyboard"]},g=(o,i=new Set)=>{if(i.has(o))return [];i.add(o);let a=c[o];if(!a)return [];let r=[];if(Array.isArray(a.requires))for(let s of a.requires)r=r.concat(g(s,i));return a.setup&&(r=r.concat(y(a.setup,p))),r};return t({ariaReference:(o,i,a)=>({requires:r=>{let s=g(r,new Set);return {required:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"required",setup:s}),optional:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"optional",setup:s}),recommended:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"recommended",setup:s})}},required:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"required"}),optional:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"optional"}),recommended:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"recommended"})}),contains:(o,i)=>({requires:a=>{let r=g(a,new Set);return {required:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"required",setup:r}),optional:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"optional",setup:r}),recommended:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"recommended",setup:r})}},required:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"required"}),optional:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"optional"}),recommended:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"recommended"})})}),this}static(t){return t({target:p=>{let g=i=>{let a=this.statePack,r={capabilities:["keyboard"]},s=(n,u=new Set)=>{if(u.has(n))return [];u.add(n);let d=a[n];if(!d)return [];let v=[];if(Array.isArray(d.requires))for(let x of d.requires)v=v.concat(s(x,u));return d.setup&&(v=v.concat(y(d.setup,r))),v};return s(i,new Set)},l=i=>i==="role"?"toHaveRole":"toHaveAttribute",o=(i,a,r)=>{let s=l(i);return {required:()=>this.staticAssertions.push({target:p,assertion:s,attribute:i,expectedValue:a,failureMessage:"",level:"required",setup:r}),optional:()=>this.staticAssertions.push({target:p,assertion:s,attribute:i,expectedValue:a,failureMessage:"",level:"optional",setup:r}),recommended:()=>this.staticAssertions.push({target:p,assertion:s,attribute:i,expectedValue:a,failureMessage:"",level:"recommended",setup:r})}};return {has:(i,a)=>({...o(i,a),requires:s=>{let n=g(s);return o(i,a,n)}})}}}),this}when(t){return new b(this,this.statePack,t)}addDynamicTest(t){this.dynamicTests.push(t);}build(){return {meta:this.metaValue,selectors:this.selectorsValue,relationships:this.relationshipInvariants.length?this.relationshipInvariants:void 0,static:this.staticAssertions.length?[{assertions:this.staticAssertions}]:[],dynamic:this.dynamicTests}}},b=class{constructor(t,c,p){this.parent=t;this.statePack=c;this.event=p;}_as;_onTarget;_onRelativeTarget;_given=[];_then=[];_desc="";_level="required";_orientation;as(t){return this._as=t,this}on(t,c){return this._onTarget=t,this._onRelativeTarget=c,this}given(t){return this._given=this._normalizeStates(t),this}then(t){return this._then=this._normalizeStates(t),this}orientation(t){return this._orientation=t,this}_normalizeStates(t){return (Array.isArray(t)?t:[t]).flatMap(p=>typeof p=="string"?[p]:typeof p=="object"&&p!==null&&"type"in p&&"ref"in p?this._findStateKeyByTypeAndRef(p.type)?[{type:p.type,ref:p.ref}]:[]:[p])}_findStateKeyByTypeAndRef(t){if(Object.keys(this.statePack).includes(t))return t}describe(t){return this._desc=t,this}required(){return this._level="required",this._finalize(),this.parent}optional(){return this._level="optional",this._finalize(),this.parent}recommended(){return this._level="recommended",this._finalize(),this.parent}_finalize(){let p={capabilities:[{keypress:"keyboard",click:"pointer",type:"textInput",focus:"keyboard",hover:"pointer"}[this._as||"keyboard"]||this._as||"keyboard"]},g=(r,s=new Set)=>{if(s.has(r))return [];s.add(r);let n=this.statePack[r];if(!n)return [];let u=[];if(Array.isArray(n.requires))for(let d of n.requires)u=u.concat(g(d,s));return n.setup&&(u=u.concat(y(n.setup,p))),u},l=[];for(let r of this._given)if(typeof r=="string")l.push(...g(r));else if(typeof r=="object"&&r!==null&&"type"in r&&"ref"in r){let s=this._findStateKeyByTypeAndRef(r.type);if(s){let n=this.statePack[s];if(n&&n.setup)for(let u of n.setup)typeof u.steps=="function"?l.push(...u.steps({relativeTarget:r.ref})):Array.isArray(u.steps)&&l.push(...u.steps);}}let o=new Set;l=l.filter(r=>{let s=JSON.stringify(r);return o.has(s)?false:(o.add(s),true)});let i=[];for(let r of this._then)if(typeof r=="string"){let s=this.statePack[r];if(s&&s.assertion!==void 0){let n=s.assertion;if(typeof n=="function")try{n=n();}catch(u){throw new Error(`Error calling assertion function for state '${r}': ${u.message}`)}Array.isArray(n)?i.push(...n):i.push(n);}}else if(typeof r=="object"&&r!==null&&"type"in r&&"ref"in r){let s=this._findStateKeyByTypeAndRef(r.type);if(s){let n=this.statePack[s];if(n&&n.assertion!==void 0){let u=n.assertion;if(typeof u=="function")try{u=u({relativeTarget:r.ref});}catch(d){throw new Error(`Error calling assertion function for state '${s}': ${d.message}`)}Array.isArray(u)?i.push(...u):i.push(u);}}}let a=[{type:this._as,target:this._onTarget,key:this._as==="keypress"?this.event:void 0,relativeTarget:this._onRelativeTarget}];this.parent.addDynamicTest({description:this._desc||"",level:this._level,orientation:this._orientation||"horizontal",action:a,assertions:i,...l.length?{setup:l}:{}});}};function ie(e,t){let c=new f(e);return t(c),new m(c.build())}exports.createContract=ie;
@@ -1,8 +1,19 @@
1
1
  type StatePack = Record<string, {
2
- setup?: DynamicAction[];
3
- assertion?: DynamicAssertion[] | DynamicAssertion;
2
+ setup?: Array<{
3
+ when: string[];
4
+ steps: ((arg?: {
5
+ relativeTarget?: string | number;
6
+ }) => DynamicAction[]) | DynamicAction[];
7
+ }>;
8
+ assertion?: ((arg?: {
9
+ relativeTarget?: string | number;
10
+ }) => DynamicAssertion[] | DynamicAssertion) | DynamicAssertion[] | DynamicAssertion;
4
11
  requires?: string[];
5
12
  }>;
13
+ type RelativeState = {
14
+ type: string;
15
+ ref: string | number;
16
+ };
6
17
  type Level = "required" | "recommended" | "optional";
7
18
  type ContractMeta = {
8
19
  id?: string;
@@ -33,9 +44,10 @@ type RelationshipInvariant = {
33
44
  };
34
45
  type StaticAssertion = {
35
46
  target: string;
47
+ assertion: "toBeVisible" | "notToBeVisible" | "toHaveAttribute" | "toHaveValue" | "toHaveFocus" | "notToHaveFocus" | "toHaveRole";
36
48
  attribute: string;
37
49
  expectedValue?: string;
38
- failureMessage: string;
50
+ failureMessage?: string;
39
51
  level: Level;
40
52
  requires?: string;
41
53
  setup?: DynamicAction[];
@@ -46,7 +58,7 @@ type DynamicAssertion = {
46
58
  attribute?: string;
47
59
  expectedValue?: string;
48
60
  failureMessage?: string;
49
- relativeTarget?: string;
61
+ relativeTarget?: string | number;
50
62
  virtualId?: string;
51
63
  selectorKey?: string;
52
64
  level?: Level;
@@ -54,17 +66,18 @@ type DynamicAssertion = {
54
66
  type DynamicAction = {
55
67
  type: "focus";
56
68
  target: string;
57
- relativeTarget?: "first" | "last" | "next" | "previous";
69
+ relativeTarget?: "first" | "last" | "next" | "previous" | number;
58
70
  virtualId?: string;
59
71
  } | {
60
- type: "click" | "keypress" | "type" | "hover";
72
+ type: "click" | "keypress" | "type" | "hover" | "focus";
61
73
  target: string;
62
74
  key?: string;
63
75
  value?: string;
64
- relativeTarget?: string;
76
+ relativeTarget?: string | number;
65
77
  };
66
78
  type DynamicTest = {
67
79
  description: string;
80
+ orientation?: "vertical" | "horizontal";
68
81
  level?: Level;
69
82
  action: DynamicAction[];
70
83
  assertions: DynamicAssertion[];
@@ -139,16 +152,27 @@ declare class DynamicTestBuilder {
139
152
  private statePack;
140
153
  private event;
141
154
  private _as;
142
- private _on;
155
+ private _onTarget;
156
+ private _onRelativeTarget;
143
157
  private _given;
144
158
  private _then;
145
159
  private _desc;
146
160
  private _level;
161
+ private _orientation;
147
162
  constructor(parent: ContractBuilder, statePack: StatePack, event: string);
148
163
  as(actionType: string): this;
149
- on(target: string): this;
150
- given(states: string | string[]): this;
151
- then(states: string | string[]): this;
164
+ on(target: string, relativeTarget?: string | number): this;
165
+ given(states: string | string[] | RelativeState | RelativeState[]): this;
166
+ then(states: string | string[] | RelativeState | RelativeState[]): this;
167
+ orientation(orientation: "vertical" | "horizontal"): this;
168
+ /**
169
+ * Normalize states to an array of string or resolved state keys from relative state objects.
170
+ */
171
+ private _normalizeStates;
172
+ /**
173
+ * Find a generic state key in the state pack by type.
174
+ */
175
+ private _findStateKeyByTypeAndRef;
152
176
  describe(desc: string): this;
153
177
  required(): ContractBuilder;
154
178
  optional(): ContractBuilder;
@@ -1,8 +1,19 @@
1
1
  type StatePack = Record<string, {
2
- setup?: DynamicAction[];
3
- assertion?: DynamicAssertion[] | DynamicAssertion;
2
+ setup?: Array<{
3
+ when: string[];
4
+ steps: ((arg?: {
5
+ relativeTarget?: string | number;
6
+ }) => DynamicAction[]) | DynamicAction[];
7
+ }>;
8
+ assertion?: ((arg?: {
9
+ relativeTarget?: string | number;
10
+ }) => DynamicAssertion[] | DynamicAssertion) | DynamicAssertion[] | DynamicAssertion;
4
11
  requires?: string[];
5
12
  }>;
13
+ type RelativeState = {
14
+ type: string;
15
+ ref: string | number;
16
+ };
6
17
  type Level = "required" | "recommended" | "optional";
7
18
  type ContractMeta = {
8
19
  id?: string;
@@ -33,9 +44,10 @@ type RelationshipInvariant = {
33
44
  };
34
45
  type StaticAssertion = {
35
46
  target: string;
47
+ assertion: "toBeVisible" | "notToBeVisible" | "toHaveAttribute" | "toHaveValue" | "toHaveFocus" | "notToHaveFocus" | "toHaveRole";
36
48
  attribute: string;
37
49
  expectedValue?: string;
38
- failureMessage: string;
50
+ failureMessage?: string;
39
51
  level: Level;
40
52
  requires?: string;
41
53
  setup?: DynamicAction[];
@@ -46,7 +58,7 @@ type DynamicAssertion = {
46
58
  attribute?: string;
47
59
  expectedValue?: string;
48
60
  failureMessage?: string;
49
- relativeTarget?: string;
61
+ relativeTarget?: string | number;
50
62
  virtualId?: string;
51
63
  selectorKey?: string;
52
64
  level?: Level;
@@ -54,17 +66,18 @@ type DynamicAssertion = {
54
66
  type DynamicAction = {
55
67
  type: "focus";
56
68
  target: string;
57
- relativeTarget?: "first" | "last" | "next" | "previous";
69
+ relativeTarget?: "first" | "last" | "next" | "previous" | number;
58
70
  virtualId?: string;
59
71
  } | {
60
- type: "click" | "keypress" | "type" | "hover";
72
+ type: "click" | "keypress" | "type" | "hover" | "focus";
61
73
  target: string;
62
74
  key?: string;
63
75
  value?: string;
64
- relativeTarget?: string;
76
+ relativeTarget?: string | number;
65
77
  };
66
78
  type DynamicTest = {
67
79
  description: string;
80
+ orientation?: "vertical" | "horizontal";
68
81
  level?: Level;
69
82
  action: DynamicAction[];
70
83
  assertions: DynamicAssertion[];
@@ -139,16 +152,27 @@ declare class DynamicTestBuilder {
139
152
  private statePack;
140
153
  private event;
141
154
  private _as;
142
- private _on;
155
+ private _onTarget;
156
+ private _onRelativeTarget;
143
157
  private _given;
144
158
  private _then;
145
159
  private _desc;
146
160
  private _level;
161
+ private _orientation;
147
162
  constructor(parent: ContractBuilder, statePack: StatePack, event: string);
148
163
  as(actionType: string): this;
149
- on(target: string): this;
150
- given(states: string | string[]): this;
151
- then(states: string | string[]): this;
164
+ on(target: string, relativeTarget?: string | number): this;
165
+ given(states: string | string[] | RelativeState | RelativeState[]): this;
166
+ then(states: string | string[] | RelativeState | RelativeState[]): this;
167
+ orientation(orientation: "vertical" | "horizontal"): this;
168
+ /**
169
+ * Normalize states to an array of string or resolved state keys from relative state objects.
170
+ */
171
+ private _normalizeStates;
172
+ /**
173
+ * Find a generic state key in the state pack by type.
174
+ */
175
+ private _findStateKeyByTypeAndRef;
152
176
  describe(desc: string): this;
153
177
  required(): ContractBuilder;
154
178
  optional(): ContractBuilder;
@@ -1 +1 @@
1
- var A={"popup.open":{setup:[{when:["keyboard","textInput"],steps:()=>[{type:"keypress",target:"input",key:"ArrowDown"}]},{when:["pointer"],steps:()=>[{type:"click",target:"button"}]}],assertion:w},"popup.closed":{setup:[{when:["keyboard"],steps:()=>[]},{when:["pointer"],steps:()=>[]}],assertion:[...M(),...f()]},"main.focused":{setup:[{when:["keyboard"],steps:()=>[{type:"focus",target:"main"}]}],assertion:E},"main.notFocused":{setup:[{when:["keyboard"],steps:()=>[]}],assertion:D},"input.filled":{setup:[{when:["keyboard","textInput"],steps:()=>[{type:"type",target:"input",value:"test"}]}],assertion:C},"input.notFilled":{setup:[{when:["keyboard","textInput"],steps:()=>[{type:"type",target:"input",value:""}]}],assertion:I},"activeOption.first":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"input",key:"ArrowDown"}]}],assertion:q},"activeOption.last":{requires:["activeOption.first"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"input",key:"ArrowUp"}]}],assertion:S},"activeDescendant.notEmpty":{requires:[],setup:[{when:["keyboard"],steps:()=>[]}],assertion:T},"activeDescendant.Empty":{requires:[],setup:[{when:["keyboard"],steps:()=>[]}],assertion:f},"selectedOption.first":{requires:["popup.open"],setup:[{when:["pointer"],steps:()=>[{type:"click",target:"relative",relativeTarget:"first"}]}],assertion:()=>b("first")},"selectedOption.last":{requires:["popup.open"],setup:[{when:["pointer"],steps:()=>[{type:"click",target:"relative",relativeTarget:"last"}]}],assertion:()=>b("last")}};function w(){return [{target:"popup",assertion:"toBeVisible",failureMessage:"Expected popup to be visible"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expect combobox main to have aria-expanded='true'."}]}function M(){return [{target:"popup",assertion:"notToBeVisible",failureMessage:"Expected popup to be closed"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expect combobox main to have aria-expanded='false'."}]}function q(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:{ref:"relative",relativeTarget:"first",property:"id"},failureMessage:"Expected aria-activedescendant on main to match the id of the first option."}]}function S(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:{ref:"relative",relativeTarget:"last",property:"id"},failureMessage:"Expected aria-activedescendant on main to match the id of the last option."}]}function T(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:"!empty",failureMessage:"Expected aria-activedescendant on main to not be empty."}]}function f(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:"",failureMessage:"Expected aria-activedescendant on main to be empty."}]}function b(a){return [{target:"relative",relativeTarget:a,assertion:"toHaveAttribute",attribute:"aria-selected",expectedValue:"true",failureMessage:`Expected ${a} option to have aria-selected='true'.`}]}function E(){return [{target:"main",assertion:"toHaveFocus",failureMessage:"Expected main to be focused."}]}function D(){return [{target:"main",assertion:"notToHaveFocus",failureMessage:"Expected main to not have focused."}]}function C(){return [{target:"input",assertion:"toHaveValue",expectedValue:"test",failureMessage:"Expected input to have the value 'test'."}]}function I(){return [{target:"input",assertion:"toHaveValue",expectedValue:"",failureMessage:"Expected input to have the value ''."}]}var x={"popup.open":{setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"main",key:"Enter"}]},{when:["pointer"],steps:()=>[{type:"click",target:"main"}]}],assertion:V},"popup.closed":{setup:[{when:["keyboard"],steps:()=>[]},{when:["pointer"],steps:()=>[]}],assertion:_},"main.focused":{setup:[{when:["keyboard"],steps:()=>[{type:"focus",target:"main"}]}],assertion:F},"main.notFocused":{setup:[{when:["keyboard"],steps:()=>[]}],assertion:H},"activeItem.first":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[]}],assertion:P},"activeItem.last":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"main",key:"ArrowUp"}]}],assertion:O},"submenu.open":{requires:["popup.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"submenuTrigger",key:"ArrowRight"}]},{when:["pointer"],steps:()=>[{type:"click",target:"submenuTrigger"}]}],assertion:B},"submenu.closed":{requires:["submenu.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"submenuTrigger",key:"ArrowLeft"}]},{when:["pointer"],steps:()=>[{type:"click",target:"submenuTrigger"}]}],assertion:R},"submenuTrigger.focused":{setup:[{when:["keyboard"],steps:()=>[{type:"focus",target:"submenuTrigger"}]}],assertion:L},"submenuTrigger.notFocused":{setup:[{when:["keyboard"],steps:()=>[]}],assertion:z},"submenuActiveItem.first":{requires:["submenu.open"],setup:[{when:["keyboard"],steps:()=>[]},{when:["pointer"],steps:()=>[]}],assertion:J}};function V(){return [{target:"popup",assertion:"toBeVisible",failureMessage:"Expected popup to be visible"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expect menu main to have aria-expanded='true'."}]}function _(){return [{target:"popup",assertion:"notToBeVisible",failureMessage:"Expected popup to be closed"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expect menu main to have aria-expanded='false'."}]}function F(){return [{target:"main",assertion:"toHaveFocus",failureMessage:"Expected menu main to be focused."}]}function H(){return [{target:"main",assertion:"notToHaveFocus",failureMessage:"Expected menu main to not have focused."}]}function P(){return [{target:"relative",assertion:"toHaveFocus",expectedValue:"first",failureMessage:"First menu item should have focus."}]}function O(){return [{target:"relative",assertion:"toHaveFocus",expectedValue:"last",failureMessage:"Last menu item should have focus."}]}function B(){return [{target:"submenu",assertion:"toBeVisible",failureMessage:"Expected submenu to be visible"},{target:"submenuTrigger",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expect submenu trigger to have aria-expanded='true'."}]}function R(){return [{target:"submenu",assertion:"notToBeVisible",failureMessage:"Expected submenu to be closed"},{target:"submenuTrigger",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expect submenu trigger to have aria-expanded='false'."}]}function L(){return [{target:"submenuTrigger",assertion:"toHaveFocus",failureMessage:"Expected submenu trigger to be focused."}]}function z(){return [{target:"submenuTrigger",assertion:"notToHaveFocus",failureMessage:"Expected submenu trigger to not have focused."}]}function J(){return [{target:"submenuItems",assertion:"toHaveFocus",failureMessage:"First interactive item in the submenu should have focus after Right Arrow open the submenu."}]}function N(a,e){return e.some(o=>a.capabilities.includes(o))}function v(a,e){Array.isArray(a)&&a.length&&!a[0].when&&(a=[{when:["keyboard"],steps:()=>a}]);for(let o of a)if(N(e,o.when))return o.steps(e);throw new Error(`No setup strategy matches capabilities: ${e.capabilities.join(", ")}`)}var U={combobox:A,menu:x},h=class{constructor(e){this.jsonContract=e;}toJSON(){return this.jsonContract}},y=class{constructor(e){this.componentName=e;this.statePack=U[e]||{};}metaValue={};selectorsValue={};relationshipInvariants=[];staticAssertions=[];dynamicTests=[];statePack;meta(e){return this.metaValue=e,this}selectors(e){return this.selectorsValue=e,this}relationships(e){let o=this.statePack,p={capabilities:["keyboard"]},c=(t,i=new Set)=>{if(i.has(t))return [];i.add(t);let s=o[t];if(!s)return [];let r=[];if(Array.isArray(s.requires))for(let n of s.requires)r=r.concat(c(n,i));return s.setup&&(r=r.concat(v(s.setup,p))),r};return e({ariaReference:(t,i,s)=>({requires:r=>{let n=c(r,new Set);return {required:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"required",setup:n}),optional:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"optional",setup:n}),recommended:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"recommended",setup:n})}},required:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"required"}),optional:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"optional"}),recommended:()=>this.relationshipInvariants.push({type:"aria-reference",from:t,attribute:i,to:s,level:"recommended"})}),contains:(t,i)=>({requires:s=>{let r=c(s,new Set);return {required:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"required",setup:r}),optional:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"optional",setup:r}),recommended:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"recommended",setup:r})}},required:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"required"}),optional:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"optional"}),recommended:()=>this.relationshipInvariants.push({type:"contains",parent:t,child:i,level:"recommended"})})}),this}static(e){return e({target:p=>{let c=t=>{let i=this.statePack,s={capabilities:["keyboard"]},r=(n,u=new Set)=>{if(u.has(n))return [];u.add(n);let d=i[n];if(!d)return [];let g=[];if(Array.isArray(d.requires))for(let k of d.requires)g=g.concat(r(k,u));return d.setup&&(g=g.concat(v(d.setup,s))),g};return r(t,new Set)},l=(t,i,s)=>({required:()=>this.staticAssertions.push({target:p,attribute:t,expectedValue:i,failureMessage:"",level:"required",setup:s}),optional:()=>this.staticAssertions.push({target:p,attribute:t,expectedValue:i,failureMessage:"",level:"optional",setup:s}),recommended:()=>this.staticAssertions.push({target:p,attribute:t,expectedValue:i,failureMessage:"",level:"recommended",setup:s})});return {has:(t,i)=>({...l(t,i),requires:r=>{let n=c(r);return l(t,i,n)}})}}}),this}when(e){return new m(this,this.statePack,e)}addDynamicTest(e){this.dynamicTests.push(e);}build(){return {meta:this.metaValue,selectors:this.selectorsValue,relationships:this.relationshipInvariants.length?this.relationshipInvariants:void 0,static:this.staticAssertions.length?[{assertions:this.staticAssertions}]:[],dynamic:this.dynamicTests}}},m=class{constructor(e,o,p){this.parent=e;this.statePack=o;this.event=p;}_as;_on;_given=[];_then=[];_desc="";_level="required";as(e){return this._as=e,this}on(e){return this._on=e,this}given(e){return this._given=Array.isArray(e)?e:[e],this}then(e){return this._then=Array.isArray(e)?e:[e],this}describe(e){return this._desc=e,this}required(){return this._level="required",this._finalize(),this.parent}optional(){return this._level="optional",this._finalize(),this.parent}recommended(){return this._level="recommended",this._finalize(),this.parent}_finalize(){let p={capabilities:[{keypress:"keyboard",click:"pointer",type:"textInput",focus:"keyboard",hover:"pointer"}[this._as||"keyboard"]||this._as||"keyboard"]},c=(s,r=new Set)=>{if(r.has(s))return [];r.add(s);let n=this.statePack[s];if(!n)return [];let u=[];if(Array.isArray(n.requires))for(let d of n.requires)u=u.concat(c(d,r));return n.setup&&(u=u.concat(v(n.setup,p))),u},l=[];for(let s of this._given)l.push(...c(s));let t=[];for(let s of this._then){let r=this.statePack[s];if(r&&r.assertion!==void 0){let n=r.assertion;if(typeof n=="function")try{n=n();}catch(u){throw new Error(`Error calling assertion function for state '${s}': ${u.message}`)}Array.isArray(n)?t.push(...n):t.push(n);}}let i=[{type:this._as,target:this._on,key:this._as==="keypress"?this.event:void 0}];this.parent.addDynamicTest({description:this._desc||"",level:this._level,action:i,assertions:t,...l.length?{setup:l}:{}});}};function Y(a,e){let o=new y(a);return e(o),new h(o.build())}export{Y as createContract};
1
+ var A={"comboboxpopup.open":{setup:[{when:["keyboard","textInput","pointer"],steps:()=>[{type:"keypress",target:"input",key:"ArrowDown"}]},{when:["pointer"],steps:()=>[{type:"click",target:"button"}]}],assertion:w},"comboboxpopup.closed":{setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:[...S(),...h()]},"main.focused":{setup:[{when:["keyboard","pointer"],steps:()=>[{type:"focus",target:"main"}]}],assertion:q},"main.blurred":{setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:D},"input.filled":{setup:[{when:["keyboard","textInput","pointer"],steps:()=>[{type:"type",target:"input",value:"test"}]}],assertion:C},"input.empty":{setup:[{when:["keyboard","textInput","pointer"],steps:()=>[{type:"type",target:"input",value:""}]}],assertion:V},"option.active":{requires:["comboboxpopup.open"],setup:[{when:["keyboard","pointer"],steps:(e={})=>typeof e.relativeTarget=="number"?Array.from({length:e.relativeTarget},()=>({type:"keypress",target:"main",key:"ArrowDown"})):e.relativeTarget==="first"?[{type:"keypress",target:"main",key:"ArrowDown"}]:e.relativeTarget==="last"?[{type:"keypress",target:"main",key:"ArrowDown"},{type:"keypress",target:"main",key:"ArrowUp"}]:[]}],assertion:(e={})=>M(e.relativeTarget)},"activedescendant.set":{requires:[],setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:E},"activedescendant.unset":{requires:[],setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:h},"option.selected":{requires:["comboboxpopup.open"],setup:[{when:["keyboard"],steps:(e={})=>[{type:"keypress",target:"relative",key:"Enter",relativeTargeta:e.relativeTarget}]},{when:["pointer"],steps:(e={})=>[{type:"click",target:"relative",relativeTargeta:e.relativeTarget}]}],assertion:(e={})=>_(e.relativeTarget)}};function w(){return [{target:"popup",assertion:"toBeVisible",failureMessage:"Expected popup to be visible"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expected combobox main to have aria-expanded='true'."}]}function S(){return [{target:"popup",assertion:"notToBeVisible",failureMessage:"Expected popup to be closed"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expected combobox main to have aria-expanded='false'."}]}function M(e){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:{ref:"relative",relativeTarget:e,property:"id"},failureMessage:"Expected aria-activedescendant on main to match the id of the first relative item."}]}function E(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:"!empty",failureMessage:"Expected aria-activedescendant on main to not be empty."}]}function h(){return [{target:"main",assertion:"toHaveAttribute",attribute:"aria-activedescendant",expectedValue:"",failureMessage:"Expected aria-activedescendant on main to be empty."}]}function _(e){return [{target:"relative",relativeTarget:e,assertion:"toHaveAttribute",attribute:"aria-selected",expectedValue:"true",failureMessage:`Expected ${e} item to have aria-selected='true'.`}]}function q(){return [{target:"main",assertion:"toHaveFocus",failureMessage:"Expected main to be focused."}]}function D(){return [{target:"main",assertion:"notToHaveFocus",failureMessage:"Expected main to not have focused."}]}function C(){return [{target:"input",assertion:"toHaveValue",expectedValue:"test",failureMessage:"Expected input to have the value 'test'."}]}function V(){return [{target:"input",assertion:"toHaveValue",expectedValue:"",failureMessage:"Expected input to have the value ''."}]}var T={"menupopup.open":{setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"main",key:"Enter"}]},{when:["pointer"],steps:()=>[{type:"click",target:"main"}]}],assertion:H},"menupopup.closed":{setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:I},"main.focused":{setup:[{when:["keyboard","pointer"],steps:()=>[{type:"focus",target:"main"}]}],assertion:R},"main.blurred":{setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:B},"menuitem.focused":{requires:["menupopup.open"],setup:[{when:["keyboard"],steps:(e={})=>[{type:"focus",target:"relative",relativeTarget:e.relativeTarget}]}],assertion:(e={})=>P(e.relativeTarget)},"submenupopup.open":{requires:["menupopup.open"],setup:[{when:["keyboard"],steps:()=>[{type:"keypress",target:"submenuTrigger",key:"ArrowRight"}]},{when:["pointer"],steps:()=>[{type:"click",target:"submenuTrigger"}]}],assertion:F},"submenupopup.closed":{setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:z},"submenutrigger.focused":{setup:[{when:["keyboard","pointer"],steps:()=>[{type:"focus",target:"submenuTrigger"}]}],assertion:O},"submenutrigger.blurred":{setup:[{when:["keyboard","pointer"],steps:()=>[]}],assertion:$},"submenuitem.focused":{requires:["submenupopup.open"],setup:[{when:["keyboard"],steps:(e={})=>{let t=[{type:"focus",target:"submenuTrigger"},{type:"keypress",target:"submenuTrigger",key:"ArrowRight"}];return typeof e.relativeTarget=="number"&&(t=t.concat(Array.from({length:e.relativeTarget},()=>({type:"keypress",target:"submenuItems",key:"ArrowDown"})))),e.relativeTarget==="first"&&(t=t.concat({type:"keypress",target:"submenuItems",key:"ArrowDown"})),e.relativeTarget==="last"&&(t=t.concat({type:"keypress",target:"submenuItems",key:"ArrowUp"})),t}},{when:["pointer"],steps:(e={})=>[{type:"click",target:"submenuTrigger"},{type:"click",target:"relative",relativeTarget:e.relativeTarget}]}],assertion:(e={})=>L(e.relativeTarget)}};function H(){return [{target:"popup",assertion:"toBeVisible",failureMessage:"Expected popup to be visible"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expected menu main to have aria-expanded='true'."}]}function I(){return [{target:"popup",assertion:"notToBeVisible",failureMessage:"Expected popup to be closed"},{target:"main",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expected menu main to have aria-expanded='false'."}]}function R(){return [{target:"main",assertion:"toHaveFocus",failureMessage:"Expected menu main to be focused."}]}function B(){return [{target:"main",assertion:"notToHaveFocus",failureMessage:"Expected menu main to not have focused."}]}function P(e){return [{target:"relative",assertion:"toHaveFocus",expectedValue:e,failureMessage:`${e} menu item should have focus.`}]}function F(){return [{target:"submenu",assertion:"toBeVisible",failureMessage:"Expected submenu to be visible"},{target:"submenuTrigger",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"true",failureMessage:"Expected submenu trigger to have aria-expanded='true'."}]}function z(){return [{target:"submenu",assertion:"notToBeVisible",failureMessage:"Expected submenu to be closed"},{target:"submenuTrigger",assertion:"toHaveAttribute",attribute:"aria-expanded",expectedValue:"false",failureMessage:"Expected submenu trigger to have aria-expanded='false'."}]}function O(){return [{target:"submenuTrigger",assertion:"toHaveFocus",failureMessage:"Expected submenu trigger to be focused."}]}function $(){return [{target:"submenuTrigger",assertion:"notToHaveFocus",failureMessage:"Expected submenu trigger to not have focused."}]}function L(e){return [{target:"relative",relativeTarget:e,assertion:"toHaveFocus",failureMessage:`Expected submenu item ${e} to have focus.`}]}var k={"tab.active":{setup:[{when:["keyboard"],steps:(e={})=>[{type:"keypress",target:"relative",relativeTarget:e.relativeTarget,key:"ArrowLeft"}]},{when:["pointer"],steps:(e={})=>[{type:"click",target:"relative",relativeTarget:e.relativeTarget}]}],assertion:(e={})=>K(e.relativeTarget)},"tab.focused":{setup:[{when:["keyboard","pointer"],steps:(e={})=>[{type:"focus",target:"relative",relativeTarget:e.relativeTarget}]}],assertion:(e={})=>j(e.relativeTarget)}};function j(e){return [{target:"relative",assertion:"toHaveFocus",relativeTarget:e,failureMessage:"Expected first tab to have focus."}]}function J(e){return [{target:"relative",assertion:"toHaveAttribute",attribute:"aria-selected",expectedValue:"true",relativeTarget:e,failureMessage:`Expected ${e} tab to have tabindex='0'.`}]}function K(e){return [{target:"relative",assertion:"toHaveAttribute",attribute:"aria-selected",expectedValue:"true",relativeTarget:e,failureMessage:`Expected ${e} tab to have aria-selected='true'.`},{target:"panel",assertion:"toBeVisible",controlledBy:{target:"relative",relativeTarget:e},failureMessage:`Expected panel controlled by the ${e} tab to be visible.`},J(e)]}function U(e,t){return t.some(c=>e.capabilities.includes(c))}function y(e,t){Array.isArray(e)&&e.length&&!e[0].when&&(e=[{when:["keyboard"],steps:()=>e}]);for(let c of e)if(U(t,c.when))return c.steps(t);throw new Error(`No setup strategy matches capabilities: ${t.capabilities.join(", ")}`)}var X={combobox:A,menu:T,tabs:k},m=class{constructor(t){this.jsonContract=t;}toJSON(){return this.jsonContract}},f=class{constructor(t){this.componentName=t;this.statePack=X[t]||{};}metaValue={};selectorsValue={};relationshipInvariants=[];staticAssertions=[];dynamicTests=[];statePack;meta(t){return this.metaValue=t,this}selectors(t){return this.selectorsValue=t,this}relationships(t){let c=this.statePack,p={capabilities:["keyboard"]},g=(o,i=new Set)=>{if(i.has(o))return [];i.add(o);let a=c[o];if(!a)return [];let r=[];if(Array.isArray(a.requires))for(let s of a.requires)r=r.concat(g(s,i));return a.setup&&(r=r.concat(y(a.setup,p))),r};return t({ariaReference:(o,i,a)=>({requires:r=>{let s=g(r,new Set);return {required:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"required",setup:s}),optional:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"optional",setup:s}),recommended:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"recommended",setup:s})}},required:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"required"}),optional:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"optional"}),recommended:()=>this.relationshipInvariants.push({type:"aria-reference",from:o,attribute:i,to:a,level:"recommended"})}),contains:(o,i)=>({requires:a=>{let r=g(a,new Set);return {required:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"required",setup:r}),optional:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"optional",setup:r}),recommended:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"recommended",setup:r})}},required:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"required"}),optional:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"optional"}),recommended:()=>this.relationshipInvariants.push({type:"contains",parent:o,child:i,level:"recommended"})})}),this}static(t){return t({target:p=>{let g=i=>{let a=this.statePack,r={capabilities:["keyboard"]},s=(n,u=new Set)=>{if(u.has(n))return [];u.add(n);let d=a[n];if(!d)return [];let v=[];if(Array.isArray(d.requires))for(let x of d.requires)v=v.concat(s(x,u));return d.setup&&(v=v.concat(y(d.setup,r))),v};return s(i,new Set)},l=i=>i==="role"?"toHaveRole":"toHaveAttribute",o=(i,a,r)=>{let s=l(i);return {required:()=>this.staticAssertions.push({target:p,assertion:s,attribute:i,expectedValue:a,failureMessage:"",level:"required",setup:r}),optional:()=>this.staticAssertions.push({target:p,assertion:s,attribute:i,expectedValue:a,failureMessage:"",level:"optional",setup:r}),recommended:()=>this.staticAssertions.push({target:p,assertion:s,attribute:i,expectedValue:a,failureMessage:"",level:"recommended",setup:r})}};return {has:(i,a)=>({...o(i,a),requires:s=>{let n=g(s);return o(i,a,n)}})}}}),this}when(t){return new b(this,this.statePack,t)}addDynamicTest(t){this.dynamicTests.push(t);}build(){return {meta:this.metaValue,selectors:this.selectorsValue,relationships:this.relationshipInvariants.length?this.relationshipInvariants:void 0,static:this.staticAssertions.length?[{assertions:this.staticAssertions}]:[],dynamic:this.dynamicTests}}},b=class{constructor(t,c,p){this.parent=t;this.statePack=c;this.event=p;}_as;_onTarget;_onRelativeTarget;_given=[];_then=[];_desc="";_level="required";_orientation;as(t){return this._as=t,this}on(t,c){return this._onTarget=t,this._onRelativeTarget=c,this}given(t){return this._given=this._normalizeStates(t),this}then(t){return this._then=this._normalizeStates(t),this}orientation(t){return this._orientation=t,this}_normalizeStates(t){return (Array.isArray(t)?t:[t]).flatMap(p=>typeof p=="string"?[p]:typeof p=="object"&&p!==null&&"type"in p&&"ref"in p?this._findStateKeyByTypeAndRef(p.type)?[{type:p.type,ref:p.ref}]:[]:[p])}_findStateKeyByTypeAndRef(t){if(Object.keys(this.statePack).includes(t))return t}describe(t){return this._desc=t,this}required(){return this._level="required",this._finalize(),this.parent}optional(){return this._level="optional",this._finalize(),this.parent}recommended(){return this._level="recommended",this._finalize(),this.parent}_finalize(){let p={capabilities:[{keypress:"keyboard",click:"pointer",type:"textInput",focus:"keyboard",hover:"pointer"}[this._as||"keyboard"]||this._as||"keyboard"]},g=(r,s=new Set)=>{if(s.has(r))return [];s.add(r);let n=this.statePack[r];if(!n)return [];let u=[];if(Array.isArray(n.requires))for(let d of n.requires)u=u.concat(g(d,s));return n.setup&&(u=u.concat(y(n.setup,p))),u},l=[];for(let r of this._given)if(typeof r=="string")l.push(...g(r));else if(typeof r=="object"&&r!==null&&"type"in r&&"ref"in r){let s=this._findStateKeyByTypeAndRef(r.type);if(s){let n=this.statePack[s];if(n&&n.setup)for(let u of n.setup)typeof u.steps=="function"?l.push(...u.steps({relativeTarget:r.ref})):Array.isArray(u.steps)&&l.push(...u.steps);}}let o=new Set;l=l.filter(r=>{let s=JSON.stringify(r);return o.has(s)?false:(o.add(s),true)});let i=[];for(let r of this._then)if(typeof r=="string"){let s=this.statePack[r];if(s&&s.assertion!==void 0){let n=s.assertion;if(typeof n=="function")try{n=n();}catch(u){throw new Error(`Error calling assertion function for state '${r}': ${u.message}`)}Array.isArray(n)?i.push(...n):i.push(n);}}else if(typeof r=="object"&&r!==null&&"type"in r&&"ref"in r){let s=this._findStateKeyByTypeAndRef(r.type);if(s){let n=this.statePack[s];if(n&&n.assertion!==void 0){let u=n.assertion;if(typeof u=="function")try{u=u({relativeTarget:r.ref});}catch(d){throw new Error(`Error calling assertion function for state '${s}': ${d.message}`)}Array.isArray(u)?i.push(...u):i.push(u);}}}let a=[{type:this._as,target:this._onTarget,key:this._as==="keypress"?this.event:void 0,relativeTarget:this._onRelativeTarget}];this.parent.addDynamicTest({description:this._desc||"",level:this._level,orientation:this._orientation||"horizontal",action:a,assertions:i,...l.length?{setup:l}:{}});}};function ie(e,t){let c=new f(e);return t(c),new m(c.build())}export{ie as createContract};