Skip to content

Commit dbee850

Browse files
committed
fix(ActionInsertLink): disable "Link to file" if offline
Fixes: #1868 Signed-off-by: Jonas <jonas@freesources.org>
1 parent 3e1b521 commit dbee850

3 files changed

Lines changed: 94 additions & 0 deletions

File tree

cypress/e2e/offline.spec.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { randUser } from '../utils/index.js'
7+
8+
const user = randUser()
9+
10+
describe('Offline', function() {
11+
before(() => {
12+
cy.createUser(user)
13+
})
14+
15+
beforeEach(() => {
16+
cy.login(user)
17+
cy.uploadTestFile()
18+
cy.visit('/apps/files')
19+
cy.openTestFile()
20+
})
21+
22+
it('Offline state indicator', () => {
23+
cy.get('.session-list').should('exist')
24+
cy.get('.offline-state').should('not.exist')
25+
cy.goOffline()
26+
cy.get('.session-list').should('not.exist')
27+
cy.get('.offline-state').should('exist')
28+
cy.goOnline()
29+
})
30+
31+
it.only('Disabled upload and link file when offline', () => {
32+
cy.getMenuEntry('insert-attachment')
33+
.find('button')
34+
.should('not.be.disabled')
35+
cy.getSubmenuEntry('insert-link', 'insert-link-file')
36+
.find('button')
37+
.should('not.be.disabled')
38+
cy.getMenuEntry('insert-link').click()
39+
40+
cy.goOffline()
41+
42+
cy.getMenuEntry('insert-attachment')
43+
.find('button')
44+
.should('be.disabled')
45+
cy.getSubmenuEntry('insert-link', 'insert-link-file')
46+
.find('button')
47+
.should('be.disabled')
48+
cy.getMenuEntry('insert-link').click()
49+
50+
cy.goOnline()
51+
})
52+
})

cypress/support/commands.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,42 @@ Cypress.Commands.overwrite('login', (login, user) => {
3838
cy.wrap(user, silent).as('currentUser')
3939
})
4040

41+
// Switch network state
42+
Cypress.Commands.add('goOffline', () => {
43+
cy.log('**go offline**')
44+
.then(() => {
45+
return Cypress.automation('remote:debugger:protocol', { command: 'Network.enable' })
46+
})
47+
.then(() => {
48+
return Cypress.automation('remote:debugger:protocol', {
49+
command: 'Network.emulateNetworkConditions',
50+
params: {
51+
offline: true,
52+
latency: -1,
53+
downloadThroughput: -1,
54+
uploadThroughput: -1,
55+
},
56+
})
57+
})
58+
})
59+
Cypress.Commands.add('goOnline', () => {
60+
cy.log('**go online**')
61+
.then(() => {
62+
return Cypress.automation('remote:debugger:protocol', {
63+
command: 'Network.emulateNetworkConditions',
64+
params: {
65+
offline: false,
66+
latency: -1,
67+
downloadThroughput: -1,
68+
uploadThroughput: -1,
69+
},
70+
})
71+
})
72+
.then(() => {
73+
return Cypress.automation('remote:debugger:protocol', { command: 'Network.disable' })
74+
})
75+
})
76+
4177
Cypress.Commands.add('openDirectEditingToken', (token) => {
4278
const visitHooks = {
4379
onBeforeLoad(win) {

src/components/Menu/ActionInsertLink.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<NcActionButton
3737
v-if="!isUsingDirectEditing"
3838
ref="buttonFile"
39+
:disabled="!networkOnline"
3940
:data-text-action-entry="`${actionEntry.key}-file`"
4041
@click="linkFile">
4142
<template #icon>
@@ -89,6 +90,7 @@ import { getLinkWithPicker } from '@nextcloud/vue/dist/Components/NcRichText.js'
8990
import { getMarkAttributes, isActive } from '@tiptap/core'
9091
9192
import { t } from '@nextcloud/l10n'
93+
import { useNetworkState } from '../../composables/useNetworkState.ts'
9294
import { buildFilePicker } from '../../helpers/filePicker.js'
9395
import { useFileMixin } from '../Editor.provider.ts'
9496
import { Document, LinkOff, Loading, Shape, Web } from '../icons.js'
@@ -109,6 +111,10 @@ export default {
109111
},
110112
extends: BaseActionEntry,
111113
mixins: [useFileMixin, useMenuIDMixin],
114+
setup() {
115+
const { networkOnline } = useNetworkState()
116+
return { ...BaseActionEntry.setup(), networkOnline }
117+
},
112118
data: () => {
113119
return {
114120
href: '',

0 commit comments

Comments
 (0)