|
| 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', { tag: '@visual' }, () => { |
| 62 | + // visual tests only run on chromium |
| 63 | + test.skip(({ browserName }) => browserName !== 'chromium') |
| 64 | + |
| 65 | + // ensure screenshots look consistent |
| 66 | + test.beforeEach(({ page }) => { |
| 67 | + page.addStyleTag({ content: '#app-content { padding: 12px; }\n' }) |
| 68 | + }) |
| 69 | + |
| 70 | + for (const [error, saving] of [[false, false], [false, true], [true, false]]) { |
| 71 | + test(`with error (${error}) and saving (${saving}) prop`, async ({ mount }) => { |
| 72 | + const component = await mount(NcSavingIndicatorIcon, { |
| 73 | + props: { |
| 74 | + name: 'Saving something', |
| 75 | + error, |
| 76 | + saving, |
| 77 | + }, |
| 78 | + }) |
| 79 | + |
| 80 | + await expect(component).toHaveScreenshot() |
| 81 | + }) |
| 82 | + } |
| 83 | +}) |
0 commit comments