-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also move mocks from setup.mjs into testHelpers. Signed-off-by: Max <max@nextcloud.com>
- Loading branch information
1 parent
8a7e10b
commit 3e9e6a7
Showing
3 changed files
with
117 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
// Mocks for browser APIs missing in jsdom | ||
|
||
import { vi } from 'vitest' | ||
|
||
// Mock ClipboardEvent and DragEvent as long as jsdom is used | ||
// https://github.com/ueberdosis/tiptap/issues/4455 | ||
|
||
class ClipboardEventMock extends Event { | ||
|
||
constructor(type, eventInitDict) { | ||
super(type, eventInitDict) | ||
this.clipboardData = { | ||
getData: vi.fn(), | ||
setData: vi.fn(), | ||
} | ||
} | ||
|
||
} | ||
|
||
global.ClipboardEvent = ClipboardEventMock | ||
|
||
class DragEventMock extends Event { | ||
|
||
constructor(type, eventInitDict) { | ||
super(type, eventInitDict) | ||
this.dataTransfer = { | ||
getData: vi.fn(), | ||
setData: vi.fn(), | ||
} | ||
} | ||
|
||
} | ||
global.DragEvent = DragEventMock | ||
|
||
// https://github.com/jsdom/jsdom/issues/3002 | ||
Range.prototype.getBoundingClientRect = vi.fn() | ||
Range.prototype.getBoundingClientRect.mockReturnValue({ | ||
bottom: 0, | ||
height: 0, | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
width: 0, | ||
}) | ||
Range.prototype.getClientRects = () => ({ | ||
item: vi.fn(), | ||
length: 0, | ||
[Symbol.iterator]: vi.fn(), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { vi } from 'vitest' | ||
|
||
global.t = vi.fn().mockImplementation((app, text) => text) | ||
global.n = vi.fn().mockImplementation((app, text) => text) | ||
|
||
vi.mock('@nextcloud/auth', () => ({ | ||
getCurrentUser: vi.fn().mockImplementation(() => ({ | ||
uid: 'user1', | ||
displayName: 'User 1', | ||
isAdmin: false, | ||
})), | ||
getRequestToken: vi.fn().mockImplementation(() => '123456abcdef'), | ||
onRequestTokenUpdate: vi.fn().mockImplementation(() => {}), | ||
})) | ||
|
||
vi.mock('@nextcloud/files', () => ({ | ||
formatFileSize: (size) => size, | ||
Header: class {}, | ||
})) | ||
vi.mock('@nextcloud/dialogs', () => ({ | ||
FilePickerType: {}, | ||
getFilePickerBuilder: () => {}, | ||
})) | ||
|
||
global.OC = { | ||
requestToken: '123', | ||
coreApps: [ | ||
'core', | ||
], | ||
config: { | ||
modRewriteWorking: true, | ||
}, | ||
dialogs: { | ||
}, | ||
isUserAdmin() { | ||
return true | ||
}, | ||
getLanguage() { | ||
return 'en-GB' | ||
}, | ||
getLocale() { | ||
return 'en_GB' | ||
}, | ||
|
||
MimeType: { | ||
getIconUrl: vi.fn(), | ||
}, | ||
L10N: { | ||
translate: global.t, | ||
}, | ||
} | ||
|
||
global.OCA = {} | ||
global._oc_webroot = '' |