import { Rule , Diagnostic } from "@siteimprove/alfa-act" ; import { Role } from "@siteimprove/alfa-aria" ; import { Element } from "@siteimprove/alfa-dom" ; import { Predicate } from "@siteimprove/alfa-predicate" ; import { Err , Ok } from "@siteimprove/alfa-result" ; import { Page } from "@siteimprove/alfa-web" ; import { expectation } from "../common/expectation" ; import { hasNonEmptyAccessibleName , hasExplicitRole , isIgnored , } from "../common/predicate" ; import { Scope } from "../tags" ; const { and , not } = Predicate ; const { hasName } = Role ; const { isElement } = Element ; export default Rule . Atomic . of < Page , Element > ( { uri : "https://alfa.siteimprove.com/rules/sia-r40" , tags : [ Scope . Component ] , evaluate ( { device , document } ) { return { applicability ( ) { return document . descendants ( { flattened : true , nested : true } ) . filter ( isElement ) . filter ( and ( hasExplicitRole ( hasName ( "region" ) ) , not ( isIgnored ( device ) ) ) ) ; } , expectations ( target ) { return { 1 : expectation ( hasNonEmptyAccessibleName ( device ) ( target ) , ( ) => Outcomes . HasName , ( ) => Outcomes . HasNoName ) , } ; } , } ; } , } ) ; export namespace Outcomes { export const HasName = Ok . of ( Diagnostic . of ( `The region has an accessible name` ) ) ; export const HasNoName = Err . of ( Diagnostic . of ( `The region does not have an accessible name` ) ) ; }