Skip to content

Commit c711528

Browse files
committed
test: add tests
Signed-off-by: Anna Larch <anna@nextcloud.com>
1 parent 3e078ea commit c711528

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/__tests__/Activity.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { mount } from '@vue/test-utils'
66
import { afterAll, beforeAll, expect, test, vi } from 'vitest'
77
import { nextTick } from 'vue'
88
import ActivityComponent from '../components/ActivityComponent.vue'
9+
import GenericActivity from '../components/activities/GenericActivity.vue'
910
import wsData from '../__mocks__/@nextcloud/activity_ws.json'
1011
import 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+
})

src/__tests__/ActivityTab.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ test('Create ActivityTab', async () => {
2525
expect(wrapper.vm.$data.activities.length).toBe(18)
2626
})
2727

28+
test('Activity list has aria-live and aria-relevant attributes', async () => {
29+
const wrapper = mount(ActivityTab, {
30+
props: {
31+
node: { id: 'test' } as any,
32+
},
33+
})
34+
35+
await new Promise<void>((resolve) => waitFor('ul', wrapper, resolve))
36+
await nextTick()
37+
38+
const list = wrapper.find('ul.activity__list')
39+
expect(list.exists()).toBe(true)
40+
expect(list.attributes('aria-live')).toBe('polite')
41+
expect(list.attributes('aria-relevant')).toBe('additions')
42+
})
43+
2844
function waitFor(query: string, wrapper: VueWrapper, callback: () => void) {
2945
if (wrapper.find(query).exists()) {
3046
return callback()

0 commit comments

Comments
 (0)