@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
1 lines • 4.72 kB
Source Map (JSON)
{"version":3,"sources":["../../../packages/core/test-utilities/jasmine-axe-matcher.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAEpC;;GAEG;AACH,qBAAa,kBAAkB;IAE3B;;;;OAIG;WACW,aAAa,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,MAAM;CAsBhE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BE;AACF,eAAO,MAAM,iBAAiB,EAAE,OAAO,CAAC,sBAmCvC,CAAC","file":"jasmine-axe-matcher.d.ts","sourcesContent":["import * as axe from 'axe-core/axe';\r\n\r\n/**\r\n * Reports the violations results.\r\n */\r\nexport class JasmineAxeReporter {\r\n\r\n /**\r\n * Helper method to dump violation details on test fail only.\r\n * This will help investigating issue with context specific help links.\r\n * @param violations all violations reported by the axe-core engine.\r\n */\r\n public static reportResults(violations: axe.Result[]): string {\r\n const violationsOutput = [];\r\n violationsOutput.push(`\\n\\r Axe-core engine found ${violations.length} violations.`);\r\n violations.forEach(violation => {\r\n violationsOutput.push('---------------------Start-------------------------------------');\r\n violationsOutput.push('Rule Id: ' + violation.id);\r\n violationsOutput.push('Violation: ' + violation.help);\r\n violationsOutput.push('Help Url: ' + violation.helpUrl);\r\n violationsOutput.push('Description: ' + violation.description);\r\n violationsOutput.push('Impact: ' + violation.impact);\r\n violationsOutput.push('Tags: ' + violation.tags);\r\n\r\n // Multiple nodes can have sane violations. Below will provide what node selector and HTML.\r\n violation.nodes.forEach(node => {\r\n violationsOutput.push('Target: ' + node.target);\r\n violationsOutput.push('Target HTML: ' + node.html);\r\n });\r\n violationsOutput.push('---------------------End---------------------------------------');\r\n });\r\n\r\n return violationsOutput.join('\\n\\r');\r\n }\r\n}\r\n\r\n/**\r\n * JasmineAxeMatcher is a custom Jasmine matcher responsible for accessibility scan using axe-core.\r\n * Axe-core is running on default configurations running all rules related to\r\n * WCAG2a, WCAG2aa, WCAG21aa, section-508, best-practice and experimental.\r\n * See https://www.deque.com/axe/axe-for-web/documentation/api-documentation/#api-name-axegetrules\r\n *\r\n * Runs all axe-core rules.\r\n * elementContext: Context of the element code be document Node | string | inclusion-exclusion object\r\n * Examples:\r\n * fixture.nativeElement\r\n * document.getElementById(id)\r\n * <div id=\"content\">\r\n * A node List: document.querySelectorAll\r\n * A CSS selector for .className, div, #tag.\r\n * inclusion-exclusion object\r\n * Examples:\r\n* Include all elements with id foobar but exclude any div within it.\r\n* {\r\n* include: ['#foobar '],\r\n* exclude: [['#foobar div']]\r\n* }\r\n* Include all elements if id header and all links and exclude a link with id foobarLink\r\n* {\r\n* include: [['#header '], ['a ']];\r\n* exclude: [['a', '#foobarLink']]\r\n* }\r\n*/\r\nexport const JasmineAxeMatcher: jasmine.CustomMatcherFactories = {\r\n toHaveNoAccessibilityViolations: () => {\r\n return {\r\n compare: (elementContext: HTMLElement): jasmine.CustomMatcherResult => {\r\n const result: jasmine.CustomMatcherResult = {\r\n pass: true,\r\n message: ''\r\n };\r\n\r\n if (MsftSme.isNullOrUndefined(elementContext)) {\r\n result.pass = false;\r\n result.message = 'elementContext can not be null or undefined';\r\n return result;\r\n }\r\n\r\n if (MsftSme.isNullOrWhiteSpace(elementContext.outerHTML)) {\r\n result.pass = false;\r\n result.message = 'elementContext can not be empty';\r\n return result;\r\n }\r\n\r\n axe.run(elementContext).then((results: axe.AxeResults) => {\r\n if (results.violations.length > 0) {\r\n\r\n // Always return pass but it will fail the test if expectations fail.\r\n result.pass = true;\r\n result.message = '';\r\n expect(results.violations.length).withContext(JasmineAxeReporter.reportResults(results.violations)).toBe(0);\r\n }\r\n });\r\n\r\n return result;\r\n }\r\n };\r\n }\r\n};\r\n"]}