Skip to content

Commit 1a98114

Browse files
susnuxnextcloud-command
authored andcommitted
test: add tests for NcSavingIndicatorIcon
Signed-off-by: Ferdinand Thiessen <[email protected]> Signed-off-by: nextcloud-command <[email protected]>
1 parent 2d41bcc commit 1a98114

4 files changed

+80
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*!
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
import { expect, test } from '@playwright/experimental-ct-vue'
6+
import NcSavingIndicatorIcon from '../../../src/components/NcSavingIndicatorIcon/NcSavingIndicatorIcon.vue'
7+
8+
test('Icon has accessible name', async ({ mount, page }) => {
9+
const component = await mount(NcSavingIndicatorIcon, {
10+
props: {
11+
name: 'Saving something',
12+
},
13+
})
14+
15+
await expect(page.getByRole('img', { name: 'Saving something' })).toBeVisible()
16+
17+
// reactivity
18+
await component.update({ props: { name: 'Saving nothing' } })
19+
await expect(page.getByRole('img', { name: 'Saving nothing' })).toBeVisible()
20+
})
21+
22+
test('Can specify size', async ({ mount }) => {
23+
const component = await mount(NcSavingIndicatorIcon, {
24+
props: {
25+
size: 42,
26+
name: 'Saving something',
27+
},
28+
})
29+
30+
const box = await component.getByRole('img').boundingBox()
31+
expect(box?.height).toBe(42)
32+
expect(box?.width).toBe(42)
33+
34+
// reactive
35+
await component.update({
36+
props: {
37+
size: 24,
38+
},
39+
})
40+
const boxSmall = await component.getByRole('img').boundingBox()
41+
expect(boxSmall?.height).toBe(24)
42+
expect(boxSmall?.width).toBe(24)
43+
})
44+
45+
test('Has click event', async ({ mount }) => {
46+
let clicked = 0
47+
const component = await mount(NcSavingIndicatorIcon, {
48+
on: {
49+
click() {
50+
clicked++
51+
},
52+
},
53+
})
54+
55+
expect(clicked).toBe(0)
56+
await component.click()
57+
await component.click()
58+
expect(clicked).toBe(2)
59+
})
60+
61+
test.describe('Icon is rendered with correct color', () => {
62+
// ensure screenshots look consistent
63+
test.beforeEach(({ page }) => {
64+
page.addStyleTag({ content: '#app-content { padding: 12px; }\n' })
65+
})
66+
67+
for (const [error, saving] of [[false, false], [false, true], [true, false]]) {
68+
test(`with error (${error}) and saving (${saving}) prop`, async ({ mount }) => {
69+
const component = await mount(NcSavingIndicatorIcon, {
70+
props: {
71+
name: 'Saving something',
72+
error,
73+
saving,
74+
},
75+
})
76+
77+
await expect(component).toHaveScreenshot()
78+
})
79+
}
80+
})

0 commit comments

Comments
 (0)