@@ -12,7 +12,10 @@ vi.mock('@codemirror/state', () => {
1212 }
1313
1414 const EditorState = {
15- create : vi . fn ( ( config ) => ( { ...config } ) )
15+ create : vi . fn ( ( config ) => ( { ...config } ) ) ,
16+ readOnly : {
17+ of : vi . fn ( ( value ) => ( { type : 'readOnly' , value } ) )
18+ }
1619 }
1720
1821 return { Compartment, EditorState }
@@ -47,6 +50,9 @@ vi.mock('@codemirror/view', () => {
4750 EditorView . editable = {
4851 of : vi . fn ( ( value ) => ( { type : 'editable' , value } ) )
4952 }
53+ EditorView . contentAttributes = {
54+ of : vi . fn ( ( value ) => ( { type : 'contentAttributes' , value } ) )
55+ }
5056 EditorView . theme = vi . fn ( ( spec , options ) => ( { type : 'theme' , spec, options } ) )
5157 EditorView . lineWrapping = { type : 'lineWrapping' }
5258 EditorView . updateListener = {
@@ -162,7 +168,10 @@ describe('CodeEditor', () => {
162168
163169 editor . setReadOnly ( true )
164170 expect ( view . dispatch ) . toHaveBeenLastCalledWith ( {
165- effects : { type : 'reconfigure' , value : { type : 'editable' , value : false } }
171+ effects : [
172+ { type : 'reconfigure' , value : { type : 'editable' , value : false } } ,
173+ { type : 'reconfigure' , value : { type : 'readOnly' , value : true } }
174+ ]
166175 } )
167176
168177 editor . focusEditor ( )
@@ -201,4 +210,59 @@ describe('CodeEditor', () => {
201210 )
202211 expect ( keymapExtension . value [ 0 ] ) . toMatchObject ( { key : 'Tab' } )
203212 } )
213+
214+ it ( 'exposes an accessible name and description on the editing surface' , async ( ) => {
215+ const editor = new CodeEditor ( )
216+ const container = document . createElement ( 'div' )
217+ document . body . appendChild ( container )
218+
219+ await editor . initialize (
220+ container ,
221+ 'generated content' ,
222+ 'text/n3' ,
223+ 'dark' ,
224+ undefined ,
225+ {
226+ label : 'Generated N3 for https://pod.example/card' ,
227+ description : 'Generated N3 serialization. This content is read-only.'
228+ }
229+ )
230+
231+ const attributes = createdViews [ 0 ] . state . extensions . find (
232+ extension => extension . type === 'compartment-of' &&
233+ extension . value . type === 'contentAttributes'
234+ ) . value
235+ expect ( attributes . value ) . toEqual ( {
236+ 'aria-label' : 'Generated N3 for https://pod.example/card' ,
237+ 'aria-description' : 'Generated N3 serialization. This content is read-only.'
238+ } )
239+ } )
240+
241+ it ( 'updates the accessible description when editor mode changes' , async ( ) => {
242+ const editor = new CodeEditor ( )
243+ const container = document . createElement ( 'div' )
244+ document . body . appendChild ( container )
245+
246+ await editor . initialize ( container , 'content' , 'text/plain' , 'dark' , undefined , {
247+ label : 'Source editor for https://pod.example/file.txt' ,
248+ description : 'Read-only source content.'
249+ } )
250+ editor . setAccessibility ( {
251+ label : 'Source editor for https://pod.example/file.txt' ,
252+ description : 'Editable source content.'
253+ } )
254+
255+ expect ( createdViews [ 0 ] . dispatch ) . toHaveBeenLastCalledWith ( {
256+ effects : {
257+ type : 'reconfigure' ,
258+ value : {
259+ type : 'contentAttributes' ,
260+ value : {
261+ 'aria-label' : 'Source editor for https://pod.example/file.txt' ,
262+ 'aria-description' : 'Editable source content.'
263+ }
264+ }
265+ }
266+ } )
267+ } )
204268} )
0 commit comments