@@ -15,6 +15,7 @@ import { mount } from '@vue/test-utils'
1515import { setActivePinia , createPinia } from 'pinia'
1616import FilesListTableHeader from './FilesListTableHeader.vue'
1717import { useFilesStore } from '../../store/files.js'
18+ import { useFilesSortingStore } from '../../store/filesSorting.js'
1819
1920// ---------------------------------------------------------------------------
2021// Mocks
@@ -219,4 +220,80 @@ describe('FilesListTableHeader', () => {
219220 expect ( stub . props ( 'modelValue' ) ) . toBe ( false )
220221 } )
221222 } )
223+
224+ describe ( 'RULE: ariaSortForMode reflects filesSortingStore state' , ( ) => {
225+ // loadState mock returns the default value, so the store initialises with
226+ // sortingMode = 'created_at' and sortingDirection = 'desc'.
227+
228+ it ( 'returns "none" when the column is sortable but not the active sort mode' , ( ) => {
229+ const wrapper = createWrapper ( )
230+ const vm = wrapper . vm as InstanceType < typeof FilesListTableHeader > & { ariaSortForMode : ( mode : string , isSortable ?: boolean ) => string | null }
231+
232+ expect ( vm . ariaSortForMode ( 'status' ) ) . toBe ( 'none' )
233+ expect ( vm . ariaSortForMode ( 'name' ) ) . toBe ( 'none' )
234+ } )
235+
236+ it ( 'returns null when the column is not sortable' , ( ) => {
237+ const wrapper = createWrapper ( )
238+ const vm = wrapper . vm as InstanceType < typeof FilesListTableHeader > & { ariaSortForMode : ( mode : string , isSortable ?: boolean ) => string | null }
239+
240+ expect ( vm . ariaSortForMode ( 'actions' , false ) ) . toBeNull ( )
241+ } )
242+
243+ it ( 'returns "descending" when the column is active and direction is desc' , async ( ) => {
244+ const wrapper = createWrapper ( )
245+ const sortingStore = useFilesSortingStore ( )
246+ sortingStore . sortingMode = 'created_at'
247+ sortingStore . sortingDirection = 'desc'
248+ await wrapper . vm . $nextTick ( )
249+
250+ const vm = wrapper . vm as InstanceType < typeof FilesListTableHeader > & { ariaSortForMode : ( mode : string ) => string | null }
251+ expect ( vm . ariaSortForMode ( 'created_at' ) ) . toBe ( 'descending' )
252+ } )
253+
254+ it ( 'returns "ascending" when the column is active and direction is asc' , async ( ) => {
255+ const wrapper = createWrapper ( )
256+ const sortingStore = useFilesSortingStore ( )
257+ sortingStore . sortingMode = 'status'
258+ sortingStore . sortingDirection = 'asc'
259+ await wrapper . vm . $nextTick ( )
260+
261+ const vm = wrapper . vm as InstanceType < typeof FilesListTableHeader > & { ariaSortForMode : ( mode : string ) => string | null }
262+ expect ( vm . ariaSortForMode ( 'status' ) ) . toBe ( 'ascending' )
263+ } )
264+
265+ it ( 'sets aria-sort attribute on the active <th> element' , async ( ) => {
266+ const wrapper = createWrapper ( )
267+ const sortingStore = useFilesSortingStore ( )
268+ sortingStore . sortingMode = 'created_at'
269+ sortingStore . sortingDirection = 'desc'
270+ await wrapper . vm . $nextTick ( )
271+
272+ const th = wrapper . find ( 'th.files-list__row-created_at' )
273+ expect ( th . attributes ( 'aria-sort' ) ) . toBe ( 'descending' )
274+ } )
275+
276+ it ( 'does not set aria-sort on non-sortable columns' , async ( ) => {
277+ const wrapper = createWrapper ( )
278+ const sortingStore = useFilesSortingStore ( )
279+ sortingStore . sortingMode = 'created_at'
280+ sortingStore . sortingDirection = 'desc'
281+ await wrapper . vm . $nextTick ( )
282+
283+ // The actions column has no aria-sort (not sortable)
284+ const actionsTh = wrapper . find ( 'th.files-list__row-actions' )
285+ expect ( actionsTh . attributes ( 'aria-sort' ) ) . toBeUndefined ( )
286+ } )
287+
288+ it ( 'sets aria-sort="none" on sortable inactive columns' , async ( ) => {
289+ const wrapper = createWrapper ( )
290+ const sortingStore = useFilesSortingStore ( )
291+ sortingStore . sortingMode = 'created_at'
292+ sortingStore . sortingDirection = 'desc'
293+ await wrapper . vm . $nextTick ( )
294+
295+ expect ( wrapper . find ( 'th.files-list__row-status' ) . attributes ( 'aria-sort' ) ) . toBe ( 'none' )
296+ expect ( wrapper . find ( 'th.files-list__row-signers' ) . attributes ( 'aria-sort' ) ) . toBe ( 'none' )
297+ } )
298+ } )
222299} )
0 commit comments