aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorfenn-cs <fenn25.fn@gmail.com>2024-07-31 10:24:14 +0100
committerfenn-cs <fenn25.fn@gmail.com>2024-07-31 13:10:03 +0100
commitd9896805b1dd0f0d7955fa86d1a8b058acaefcca (patch)
treeb0e3f4c2dc0cbb4a9172408ec1bee1a1dc09c8ce /apps
parentc8a36ab37356c21a0d047a0a6be392a5a6c443d2 (diff)
downloadnextcloud-server-d9896805b1dd0f0d7955fa86d1a8b058acaefcca.tar.gz
nextcloud-server-d9896805b1dd0f0d7955fa86d1a8b058acaefcca.zip
fix: Adjust tests for editLocallyAction
Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/files/src/actions/editLocallyAction.spec.ts47
-rw-r--r--apps/files/src/actions/editLocallyAction.ts2
2 files changed, 39 insertions, 10 deletions
diff --git a/apps/files/src/actions/editLocallyAction.spec.ts b/apps/files/src/actions/editLocallyAction.spec.ts
index e7102b8defb..3d32930c273 100644
--- a/apps/files/src/actions/editLocallyAction.spec.ts
+++ b/apps/files/src/actions/editLocallyAction.spec.ts
@@ -22,14 +22,35 @@
import { action } from './editLocallyAction'
import { expect } from '@jest/globals'
import { File, Permission, View, FileAction } from '@nextcloud/files'
-import * as ncDialogs from '@nextcloud/dialogs'
+import { DialogBuilder, showError } from '@nextcloud/dialogs'
import axios from '@nextcloud/axios'
+const dialogBuilder = {
+ setName: jest.fn().mockReturnThis(),
+ setText: jest.fn().mockReturnThis(),
+ setButtons: jest.fn().mockReturnThis(),
+ build: jest.fn().mockReturnValue({
+ show: jest.fn().mockResolvedValue(true),
+ }),
+} as unknown as DialogBuilder
+
+jest.mock('@nextcloud/dialogs', () => ({
+ DialogBuilder: jest.fn(() => dialogBuilder),
+ showError: jest.fn(),
+}))
+
const view = {
id: 'files',
name: 'Files',
} as View
+// Mock webroot variable
+beforeAll(() => {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (window as any)._oc_webroot = '';
+ (window as any).OCA = { Viewer: { open: jest.fn() } }
+})
+
describe('Edit locally action conditions tests', () => {
test('Default values', () => {
expect(action).toBeInstanceOf(FileAction)
@@ -55,7 +76,7 @@ describe('Edit locally action enabled tests', () => {
expect(action.enabled!([file], view)).toBe(true)
})
- test('Disabled for non-dav ressources', () => {
+ test('Disabled for non-dav resources', () => {
const file = new File({
id: 1,
source: 'https://domain.com/data/foobar.txt',
@@ -115,8 +136,11 @@ describe('Edit locally action enabled tests', () => {
describe('Edit locally action execute tests', () => {
test('Edit locally opens proper URL', async () => {
- jest.spyOn(axios, 'post').mockImplementation(async () => ({ data: { ocs: { data: { token: 'foobar' } } } }))
- jest.spyOn(ncDialogs, 'showError')
+ jest.spyOn(axios, 'post').mockImplementation(async () => ({
+ data: { ocs: { data: { token: 'foobar' } } }
+ }))
+ const mockedShowError = jest.mocked(showError)
+ const spyDialogBuilder = jest.spyOn(dialogBuilder, 'build')
const file = new File({
id: 1,
@@ -128,17 +152,20 @@ describe('Edit locally action execute tests', () => {
const exec = await action.exec(file, view, '/')
+ expect(spyDialogBuilder).toBeCalled()
+
// Silent action
expect(exec).toBe(null)
expect(axios.post).toBeCalledTimes(1)
expect(axios.post).toBeCalledWith('http://localhost/ocs/v2.php/apps/files/api/v1/openlocaleditor?format=json', { path: '/foobar.txt' })
- expect(ncDialogs.showError).toBeCalledTimes(0)
+ expect(mockedShowError).toBeCalledTimes(0)
expect(window.location.href).toBe('nc://open/test@localhost/foobar.txt?token=foobar')
})
- test('Edit locally fails and show error', async () => {
+ test('Edit locally fails and shows error', async () => {
jest.spyOn(axios, 'post').mockImplementation(async () => ({}))
- jest.spyOn(ncDialogs, 'showError')
+ const mockedShowError = jest.mocked(showError)
+ const spyDialogBuilder = jest.spyOn(dialogBuilder, 'build')
const file = new File({
id: 1,
@@ -150,12 +177,14 @@ describe('Edit locally action execute tests', () => {
const exec = await action.exec(file, view, '/')
+ expect(spyDialogBuilder).toBeCalled()
+
// Silent action
expect(exec).toBe(null)
expect(axios.post).toBeCalledTimes(1)
expect(axios.post).toBeCalledWith('http://localhost/ocs/v2.php/apps/files/api/v1/openlocaleditor?format=json', { path: '/foobar.txt' })
- expect(ncDialogs.showError).toBeCalledTimes(1)
- expect(ncDialogs.showError).toBeCalledWith('Failed to redirect to client')
+ expect(mockedShowError).toBeCalledTimes(1)
+ expect(mockedShowError).toBeCalledWith('Failed to redirect to client')
expect(window.location.href).toBe('http://localhost/')
})
})
diff --git a/apps/files/src/actions/editLocallyAction.ts b/apps/files/src/actions/editLocallyAction.ts
index e6e847e2fec..38393b919d5 100644
--- a/apps/files/src/actions/editLocallyAction.ts
+++ b/apps/files/src/actions/editLocallyAction.ts
@@ -62,7 +62,7 @@ const confirmLocalEditDialog = (
.then(() => {
// Ensure the callback is called even if the dialog is dismissed in other ways
if (!callbackCalled) {
- localEditCallback(true)
+ localEditCallback(false)
}
})
}