Skip to content

Commit 7399f6d

Browse files
committed
test: adjust for dependency updates
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent a5df574 commit 7399f6d

19 files changed

Lines changed: 107 additions & 36 deletions

File tree

.github/workflows/playwright.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ name: Playwright Tests
55

66
on:
77
pull_request:
8-
branches: [master]
8+
branches:
9+
- master
10+
- stable35
911
types:
1012
- opened
1113
- synchronize

apps/files/src/actions/openLocallyAction.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import { action } from './openLocallyAction.ts'
1313

1414
vi.mock('@nextcloud/auth')
1515
vi.mock('@nextcloud/axios')
16+
// Only mock the toasts, the dialog classes are needed to test the confirmation dialog
17+
vi.mock('@nextcloud/dialogs', async (importOriginal) => ({
18+
...await importOriginal<typeof nextcloudDialogs>(),
19+
showError: vi.fn(),
20+
}))
1621

1722
const view = {
1823
id: 'files',

apps/files/src/services/DropServiceUtils.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { logger } from '../utils/logger.ts'
1010
import { dataTransferToFileTree } from './DropService.ts'
1111
import { Directory, traverseTree } from './DropServiceUtils.ts'
1212

13+
vi.mock('@nextcloud/dialogs')
14+
1315
const dataTree = {
1416
'file0.txt': ['Hello, world!', 1234567890],
1517
dir1: {

apps/files/src/views/DialogConfirmFileHidden.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('DialogConfirmFileHidden', () => {
2525
})
2626

2727
await expect(component.findByRole('dialog', { name: 'Rename file to hidden' })).resolves.not.toThrow()
28-
expect((component.getByRole('checkbox', { name: /Do not show this dialog again/i }) as HTMLInputElement).checked).toBe(false)
28+
expect((component.getByRole('switch', { name: /Do not show this dialog again/i }) as HTMLInputElement).checked).toBe(false)
2929
await expect(component.findByRole('button', { name: 'Cancel' })).resolves.not.toThrow()
3030
await expect(component.findByRole('button', { name: 'Rename' })).resolves.not.toThrow()
3131
})
@@ -86,7 +86,7 @@ describe('DialogConfirmFileHidden', () => {
8686
},
8787
})
8888

89-
await fireEvent.click(component.getByRole('checkbox', { name: /Do not show this dialog again/i }))
89+
await fireEvent.click(component.getByRole('switch', { name: /Do not show this dialog again/i }))
9090
const store = useUserConfigStore()
9191
expect(store.update).toHaveBeenCalledOnce()
9292
expect(store.update).toHaveBeenCalledWith('show_dialog_file_extension', false)

apps/files_trashbin/src/services/api.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const axiosMock = vi.hoisted(() => ({
1313
delete: vi.fn(),
1414
}))
1515
vi.mock('@nextcloud/axios', () => ({ default: axiosMock }))
16+
vi.mock('@nextcloud/dialogs')
1617

1718
describe('files_trashbin: API - emptyTrash', () => {
1819
beforeEach(() => {

build/frontend-legacy/__tests__/mock-window.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,18 @@ window.OCA = { ...window.OCA }
1313
window.OCP = { ...window.OCP }
1414

1515
window._oc_webroot = ''
16+
17+
// jsdom does not implement `innerText` at all, while the specification defines it
18+
// to fall back to `textContent` for elements that are not being rendered.
19+
// @see https://github.com/jsdom/jsdom/issues/1245
20+
if (!('innerText' in HTMLElement.prototype)) {
21+
Object.defineProperty(HTMLElement.prototype, 'innerText', {
22+
configurable: true,
23+
get() {
24+
return this.textContent
25+
},
26+
set(value) {
27+
this.textContent = value
28+
},
29+
})
30+
}

build/frontend/__tests__/mock-window.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,18 @@ window.OCA = { ...window.OCA }
1313
window.OCP = { ...window.OCP }
1414

1515
window._oc_webroot = ''
16+
17+
// jsdom does not implement `innerText` at all, while the specification defines it
18+
// to fall back to `textContent` for elements that are not being rendered.
19+
// @see https://github.com/jsdom/jsdom/issues/1245
20+
if (!('innerText' in HTMLElement.prototype)) {
21+
Object.defineProperty(HTMLElement.prototype, 'innerText', {
22+
configurable: true,
23+
get() {
24+
return this.textContent
25+
},
26+
set(value) {
27+
this.textContent = value
28+
},
29+
})
30+
}

build/frontend/vitest.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export default defineConfig({
3636
resolve: {
3737
preserveSymlinks: true,
3838
},
39+
server: {
40+
fs: {
41+
// The dependencies are installed in the repository root, which is outside of the vite root,
42+
// so it needs to be allowed explicitly for assets like `*.svg?raw` to be loadable.
43+
allow: [resolve(import.meta.dirname, '../..')],
44+
},
45+
},
3946
test: {
4047
include: ['apps/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
4148
env: {

tests/playwright/e2e/files/drag-n-drop.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { expect, test } from '../../support/fixtures/files-page.ts'
77
import { mkdir, uploadContent } from '../../support/utils/dav.ts'
88
import { createFileDataTransfer, dropFilesOn } from '../../support/utils/drag-drop.ts'
9+
import { getToast } from '../../support/utils/toast.ts'
910

1011
test.describe('files: Drag and Drop', () => {
1112
test.beforeEach(async ({ filesListPage }) => {
@@ -56,7 +57,7 @@ test.describe('files: Drag and Drop', () => {
5657

5758
await dropFilesOn(filesListPage.getDropArea(), dataTransfer)
5859

59-
await expect(page.locator('.toast-warning')).toBeVisible()
60+
await expect(getToast(page, 'Your browser does not support the Filesystem API')).toBeVisible()
6061
await expect(filesListPage.getRowForFile('first.txt')).toBeVisible()
6162
await expect(filesListPage.getRowForFile('second.txt')).toBeVisible()
6263
await expect(filesListPage.getRowForFile('Foo')).toHaveCount(0)

tests/playwright/e2e/files/files.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { expect, test } from '../../support/fixtures/files-page.ts'
77
import { mkdir, uploadContent } from '../../support/utils/dav.ts'
8+
import { getToast } from '../../support/utils/toast.ts'
89

910
test.describe('Files', () => {
1011
test('Login with a user and open the files app', async ({ filesListPage }) => {
@@ -21,7 +22,7 @@ test.describe('Files', () => {
2122
await expect(row).toBeVisible()
2223
await expect(row).toHaveAttribute('data-cy-files-list-row-name', 'original.txt')
2324
await expect(row).toBeActiveRow()
24-
await expect(page.getByText('The file could not be found')).toHaveCount(0)
25+
await expect(getToast(page, 'The file could not be found')).toHaveCount(0)
2526
})
2627

2728
test('Opens a valid folder shows its content', async ({ page, user, filesListPage }) => {
@@ -31,13 +32,13 @@ test.describe('Files', () => {
3132
await filesListPage.waitForList()
3233

3334
await expect(filesListPage.getBreadcrumbs()).toContainText('folder')
34-
await expect(page.getByText('The file could not be found')).toHaveCount(0)
35+
await expect(getToast(page, 'The file could not be found')).toHaveCount(0)
3536
})
3637

3738
test('Opens an unknown file show an error', async ({ page }) => {
3839
await page.goto('apps/files/files/123456')
3940

4041
// The error toast is shown once the (failing) PROPFIND resolves
41-
await expect(page.getByText('The file could not be found')).toBeVisible()
42+
await expect(getToast(page, 'The file could not be found')).toBeVisible()
4243
})
4344
})

0 commit comments

Comments
 (0)