@@ -3,6 +3,7 @@ import { render } from "@testing-library/svelte";
33import { linkCtxKey , type ILinkContext } from "./LinkContext.svelte" ;
44import TestLinkContextWithContextSpy from "../../testing/TestLinkContextWithContextSpy.svelte" ;
55import { flushSync } from "svelte" ;
6+ import type { ActiveStateAriaAttributes } from "$lib/types.js" ;
67
78describe ( "LinkContext" , ( ) => {
89 afterEach ( ( ) => {
@@ -26,6 +27,7 @@ describe("LinkContext", () => {
2627 expect ( linkCtx ?. prependBasePath ) . toBeUndefined ( ) ;
2728 expect ( linkCtx ?. preserveQuery ) . toBeUndefined ( ) ;
2829 expect ( linkCtx ?. activeState ) . toBeUndefined ( ) ;
30+ expect ( linkCtx ?. activeStateAria ) . toBeUndefined ( ) ;
2931 } ) ;
3032
3133 test ( "Should transmit via context the explicitly set properties." , ( ) => {
@@ -35,7 +37,7 @@ describe("LinkContext", () => {
3537 replace : true ,
3638 prependBasePath : true ,
3739 preserveQuery : [ 'search' , 'filter' ] ,
38- activeState : { class : "active-link" , style : "color: red;" , aria : { 'aria- current' : 'page' } }
40+ activeState : { class : "active-link" , style : "color: red;" , aria : { current : 'page' } }
3941 }
4042
4143 // Act.
@@ -61,7 +63,7 @@ describe("LinkContext", () => {
6163 replace : true ,
6264 prependBasePath : true ,
6365 preserveQuery : [ 'search' , 'filter' ] ,
64- activeState : { class : "active-link" , style : "color: red;" , aria : { 'aria- current' : 'page' } }
66+ activeState : { class : "active-link" , style : "color: red;" , aria : { current : 'page' } }
6567 } ;
6668 const context = new Map ( ) ;
6769 context . set ( linkCtxKey , parentCtx ) ;
@@ -109,7 +111,7 @@ describe("LinkContext", () => {
109111 parentValue : false ,
110112 value : true ,
111113 } ,
112- ] ) ( "Should override the parent context value for $property when set as a property." , ( { property, parentValue, value} ) => {
114+ ] ) ( "Should override the parent context value for $property when set as a property." , ( { property, parentValue, value } ) => {
113115 // Arrange.
114116 const parentCtx : ILinkContext = {
115117 replace : true ,
@@ -186,11 +188,73 @@ describe("LinkContext", () => {
186188 expect ( linkCtx ) . toBeDefined ( ) ;
187189 expect ( linkCtx ?. [ property ] ) . toEqual ( updated ) ;
188190 } ) ;
191+ test ( "Should calculate expanded aria attributes from the values in activeState.aria." , ( ) => {
192+ // Arrange.
193+ let linkCtx : ILinkContext | undefined ;
194+ const ctxProps : ILinkContext = {
195+ activeState : { aria : { current : 'location' } }
196+ } ;
197+
198+ // Act.
199+ render ( TestLinkContextWithContextSpy , {
200+ props : {
201+ ...ctxProps ,
202+ get linkCtx ( ) { return linkCtx ; } ,
203+ set linkCtx ( v ) { linkCtx = v ; }
204+ }
205+ } ) ;
206+
207+ // Assert.
208+ expect ( linkCtx ) . toBeDefined ( ) ;
209+ expect ( linkCtx ?. activeStateAria ) . toEqual ( { 'aria-current' : 'location' } ) ;
210+ } ) ;
211+ test ( "Should update activeStateAria when activeState.aria changes (re-render)." , async ( ) => {
212+ // Arrange.
213+ let linkCtx : ILinkContext | undefined ;
214+ const { rerender } = render ( TestLinkContextWithContextSpy , {
215+ props : {
216+ activeState : { aria : { current : 'location' } } ,
217+ get linkCtx ( ) { return linkCtx ; } ,
218+ set linkCtx ( v ) { linkCtx = v ; }
219+ }
220+ } ) ;
221+ expect ( linkCtx ) . toBeDefined ( ) ;
222+ expect ( linkCtx ?. activeStateAria ) . toEqual ( { 'aria-current' : 'location' } ) ;
223+
224+ // Act.
225+ await rerender ( { activeState : { aria : { current : 'page' } } } ) ;
226+
227+ // Assert.
228+ expect ( linkCtx ) . toBeDefined ( ) ;
229+ expect ( linkCtx ?. activeStateAria ) . toEqual ( { 'aria-current' : 'page' } ) ;
230+ } ) ;
231+ test ( "Should update activeStateAria when activeState.aria changes (state change)." , ( ) => {
232+ // Arrange.
233+ let linkCtx : ILinkContext | undefined ;
234+ let aria = $state < ActiveStateAriaAttributes > ( { current : 'location' } ) ;
235+ render ( TestLinkContextWithContextSpy , {
236+ props : {
237+ activeState : { aria } ,
238+ get linkCtx ( ) { return linkCtx ; } ,
239+ set linkCtx ( v ) { linkCtx = v ; }
240+ }
241+ } ) ;
242+ expect ( linkCtx ) . toBeDefined ( ) ;
243+ expect ( linkCtx ?. activeStateAria ) . toEqual ( { 'aria-current' : 'location' } ) ;
244+
245+ // Act.
246+ aria . current = 'page' ;
247+ flushSync ( ) ;
248+
249+ // Assert.
250+ expect ( linkCtx ) . toBeDefined ( ) ;
251+ expect ( linkCtx ?. activeStateAria ) . toEqual ( { 'aria-current' : 'page' } ) ;
252+ } ) ;
189253 } ) ;
190254
191255 describe ( 'Parent Context Reactivity' , ( ) => {
192256 test . each < {
193- property : keyof ILinkContext ,
257+ property : Exclude < keyof ILinkContext , 'activeStateAria' > ,
194258 initial : any ,
195259 updated : any
196260 } > ( [
0 commit comments