@@ -3,80 +3,7 @@ import {CdkRadioButton, CdkRadioGroup} from './radio';
33import { ComponentFixture , TestBed } from '@angular/core/testing' ;
44import { By } from '@angular/platform-browser' ;
55import { BidiModule , Direction } from '@angular/cdk/bidi' ;
6- import { provideFakeDirectionality } from '@angular/cdk/testing/private' ;
7- import axe from 'axe-core' ;
8-
9- // Basic ANSI color functions because chalk has issues with unit tests.
10- const colors = {
11- red : ( text : string ) => `\x1b[31m${ text } \x1b[0m` ,
12- yellow : ( text : string ) => `\x1b[33m${ text } \x1b[0m` ,
13- blue : ( text : string ) => `\x1b[34m${ text } \x1b[0m` ,
14- magenta : ( text : string ) => `\x1b[35m${ text } \x1b[0m` ,
15- cyan : ( text : string ) => `\x1b[36m${ text } \x1b[0m` ,
16- gray : ( text : string ) => `\x1b[90m${ text } \x1b[0m` ,
17- underline : ( text : string ) => `\x1b[4m${ text } \x1b[0m` ,
18- default : ( text : string ) => `\x1b[0m${ text } \x1b[0m` ,
19- } ;
20-
21- // TODO: Move this to a separate folder/file so it can be reused across components.
22- async function runAccessibilityChecks ( root : HTMLElement ) : Promise < void > {
23- const results = await axe . run ( root ) ;
24-
25- if ( ! results . violations . length ) {
26- return ;
27- }
28-
29- const reportLines : string [ ] = [ ] ;
30- const append = ( text : string ) => reportLines . push ( colors . default ( text ) ) ;
31- append ( colors . red ( `Found ${ results . violations . length } accessibility violation(s):` ) ) ;
32-
33- results . violations . forEach ( ( violation , index ) => {
34- append ( '' ) ;
35- append ( colors . red ( `Violation ${ index + 1 } : ${ violation . id } \n` ) ) ;
36-
37- let impactText = violation . impact || 'unknown' ;
38- switch ( violation . impact ) {
39- case 'critical' :
40- impactText = colors . red ( impactText ) ;
41- break ;
42- case 'serious' :
43- impactText = colors . yellow ( impactText ) ;
44- break ;
45- case 'moderate' :
46- impactText = colors . blue ( impactText ) ;
47- break ;
48- case 'minor' :
49- impactText = colors . gray ( impactText ) ;
50- break ;
51- default :
52- impactText = colors . default ( impactText ) ;
53- break ;
54- }
55-
56- append ( ` Impact: ${ impactText } ` ) ;
57- append ( ` Description: ${ violation . description } ` ) ;
58- append ( ` Help: ${ violation . help } ` ) ;
59- append ( ` Help URL: ${ colors . underline ( colors . blue ( violation . helpUrl ) ) } \n` ) ;
60-
61- if ( violation . nodes && violation . nodes . length > 0 ) {
62- append ( ' Failing Elements:' ) ;
63- violation . nodes . forEach ( ( node , nodeIndex ) => {
64- append ( colors . cyan ( ` Node ${ nodeIndex + 1 } :` ) ) ;
65- if ( node . target && node . target . length > 0 ) {
66- append ( ` Selector: ${ colors . magenta ( node . target . join ( ', ' ) ) } ` ) ;
67- }
68- if ( node . failureSummary ) {
69- append ( ' Failure Summary:' ) ;
70- node . failureSummary
71- . split ( '\n' )
72- . forEach ( line => append ( colors . yellow ( ` ${ line . trim ( ) } ` ) ) ) ;
73- }
74- } ) ;
75- }
76- } ) ;
77-
78- fail ( reportLines . join ( '\n' ) ) ;
79- }
6+ import { provideFakeDirectionality , runAccessibilityChecks } from '@angular/cdk/testing/private' ;
807
818describe ( 'CdkRadioGroup' , ( ) => {
829 let fixture : ComponentFixture < RadioGroupExample > ;
0 commit comments