@@ -818,4 +818,131 @@ suite('Abstract Fields', function () {
818818 } ) ;
819819 } ) ;
820820 } ) ;
821+
822+ suite ( 'Aria' , function ( ) {
823+ class TestField extends Blockly . Field {
824+ constructor ( value , config = undefined ) {
825+ super ( value , null , config ) ;
826+ }
827+ }
828+
829+ suite ( 'getAriaTypeName' , function ( ) {
830+ test ( 'Default returns null' , function ( ) {
831+ const field = new TestField ( ) ;
832+ assert . isNull ( field . getAriaTypeName ( ) ) ;
833+ } ) ;
834+
835+ test ( 'Returns configured ariaTypeName (JS)' , function ( ) {
836+ const field = new TestField ( 'value' , { ariaTypeName : 'number' } ) ;
837+ assert . equal ( field . getAriaTypeName ( ) , 'number' ) ;
838+ } ) ;
839+
840+ test ( 'Returns configured ariaTypeName (JSON)' , function ( ) {
841+ class CustomField extends Blockly . Field {
842+ constructor ( opt_config ) {
843+ super ( 'value' , null , opt_config ) ;
844+ }
845+
846+ static fromJson ( options ) {
847+ return new CustomField ( options ) ;
848+ }
849+ }
850+
851+ const field = CustomField . fromJson ( { ariaTypeName : 'text input' } ) ;
852+ assert . equal ( field . getAriaTypeName ( ) , 'text input' ) ;
853+ } ) ;
854+ } ) ;
855+
856+ suite ( 'getAriaValue' , function ( ) {
857+ test ( 'Returns string value' , function ( ) {
858+ const field = new TestField ( 'hello' ) ;
859+ assert . equal ( field . getAriaValue ( ) , 'hello' ) ;
860+ } ) ;
861+
862+ test ( 'Returns stringified number' , function ( ) {
863+ const field = new TestField ( 123 ) ;
864+ assert . equal ( field . getAriaValue ( ) , '123' ) ;
865+ } ) ;
866+
867+ test ( 'Returns null for null value' , function ( ) {
868+ const field = new TestField ( null ) ;
869+ assert . isNull ( field . getAriaValue ( ) ) ;
870+ } ) ;
871+
872+ test ( 'Returns null for undefined value' , function ( ) {
873+ const field = new TestField ( undefined ) ;
874+ assert . isNull ( field . getAriaValue ( ) ) ;
875+ } ) ;
876+ } ) ;
877+
878+ suite ( 'computeAriaLabel' , function ( ) {
879+ test ( 'Value only (default)' , function ( ) {
880+ const field = new TestField ( 'hello' ) ;
881+ assert . equal ( field . computeAriaLabel ( ) , 'hello' ) ;
882+ } ) ;
883+
884+ test ( 'Value only when includeTypeInfo=false' , function ( ) {
885+ const field = new TestField ( 'hello' , { ariaTypeName : 'text' } ) ;
886+ assert . equal ( field . computeAriaLabel ( false ) , 'hello' ) ;
887+ } ) ;
888+
889+ test ( 'Type and value when includeTypeInfo=true' , function ( ) {
890+ const field = new TestField ( 'hello' , { ariaTypeName : 'text' } ) ;
891+ assert . equal ( field . computeAriaLabel ( true ) , 'text: hello' ) ;
892+ } ) ;
893+
894+ test ( 'Type only when value is null' , function ( ) {
895+ const field = new TestField ( null , { ariaTypeName : 'text' } ) ;
896+ assert . equal ( field . computeAriaLabel ( true ) , 'text' ) ;
897+ } ) ;
898+
899+ test ( 'Empty string when no type or value' , function ( ) {
900+ const field = new TestField ( null ) ;
901+ assert . equal ( field . computeAriaLabel ( true ) , '' ) ;
902+ } ) ;
903+
904+ test ( 'Handles missing type with includeTypeInfo=true' , function ( ) {
905+ const field = new TestField ( 'hello' ) ;
906+ assert . equal ( field . computeAriaLabel ( true ) , 'hello' ) ;
907+ } ) ;
908+ } ) ;
909+
910+ suite ( 'Subclass overrides' , function ( ) {
911+ class CustomValueField extends TestField {
912+ getAriaValue ( ) {
913+ return 'custom value' ;
914+ }
915+ }
916+
917+ class CustomTypeField extends TestField {
918+ getAriaTypeName ( ) {
919+ return 'custom type' ;
920+ }
921+ }
922+
923+ class FullCustomField extends TestField {
924+ getAriaValue ( ) {
925+ return 'custom value' ;
926+ }
927+ getAriaTypeName ( ) {
928+ return 'custom type' ;
929+ }
930+ }
931+
932+ test ( 'Uses overridden getAriaValue' , function ( ) {
933+ const field = new CustomValueField ( 'ignored' ) ;
934+ assert . equal ( field . computeAriaLabel ( ) , 'custom value' ) ;
935+ } ) ;
936+
937+ test ( 'Uses overridden getAriaTypeName' , function ( ) {
938+ const field = new CustomTypeField ( 'value' ) ;
939+ assert . equal ( field . computeAriaLabel ( true ) , 'custom type: value' ) ;
940+ } ) ;
941+
942+ test ( 'Uses both overrides' , function ( ) {
943+ const field = new FullCustomField ( ) ;
944+ assert . equal ( field . computeAriaLabel ( true ) , 'custom type: custom value' ) ;
945+ } ) ;
946+ } ) ;
947+ } ) ;
821948} ) ;
0 commit comments