@@ -6,6 +6,7 @@ import { mount } from '@vue/test-utils'
66import { afterAll , beforeAll , expect , test , vi } from 'vitest'
77import { nextTick } from 'vue'
88import ActivityComponent from '../components/ActivityComponent.vue'
9+ import GenericActivity from '../components/activities/GenericActivity.vue'
910import wsData from '../__mocks__/@nextcloud/activity_ws.json'
1011import ActivityModel from '../models/ActivityModel.js'
1112
@@ -107,3 +108,46 @@ test('Display correct information for creations', async () => {
107108
108109 expectLinkWithText ( wrapper , 'Test file.md' )
109110} )
111+
112+ test ( 'Preview image uses filename as alt text when no link' , async ( ) => {
113+ const activityWithPreview = new ActivityModel ( {
114+ ...wsData . ocs . data [ 1 ] ,
115+ previews : [ {
116+ source : 'http://localhost/preview/123' ,
117+ mimeType : 'image/jpeg' ,
118+ isMimeTypeIcon : false ,
119+ fileId : 123 ,
120+ filename : 'photo.jpg' ,
121+ view : 'files' ,
122+ } ] ,
123+ } )
124+ const wrapper = mount ( GenericActivity , { propsData : { activity : activityWithPreview , showPreviews : true } } )
125+
126+ await nextTick ( )
127+
128+ const img = wrapper . find ( 'img' )
129+ expect ( img . exists ( ) ) . toBe ( true )
130+ expect ( img . attributes ( 'alt' ) ) . toBe ( 'photo.jpg' )
131+ } )
132+
133+ test ( 'Preview image uses "Open {filename}" as alt text when link is present' , async ( ) => {
134+ const activityWithPreview = new ActivityModel ( {
135+ ...wsData . ocs . data [ 1 ] ,
136+ previews : [ {
137+ source : 'http://localhost/preview/123' ,
138+ link : 'http://localhost/files/photo.jpg' ,
139+ mimeType : 'image/jpeg' ,
140+ isMimeTypeIcon : false ,
141+ fileId : 123 ,
142+ filename : 'photo.jpg' ,
143+ view : 'files' ,
144+ } ] ,
145+ } )
146+ const wrapper = mount ( GenericActivity , { propsData : { activity : activityWithPreview , showPreviews : true } } )
147+
148+ await nextTick ( )
149+
150+ const img = wrapper . find ( 'img' )
151+ expect ( img . exists ( ) ) . toBe ( true )
152+ expect ( img . attributes ( 'alt' ) ) . toBe ( 'Open photo.jpg' )
153+ } )
0 commit comments