From f5b222263a8bee396dba605a1e468a28af092af7 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 17 Apr 2025 13:11:32 +0200 Subject: [PATCH] fix(settings): allow to clear twitter and fediverse Signed-off-by: Ferdinand Thiessen --- .../PersonalInfo/FediverseSection.vue | 9 ++++++++- .../PersonalInfo/TwitterSection.vue | 4 ++-- cypress/e2e/settings/personal-info.cy.ts | 19 ++++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/apps/settings/src/components/PersonalInfo/FediverseSection.vue b/apps/settings/src/components/PersonalInfo/FediverseSection.vue index 65400ce0e45..043fa6e64b9 100644 --- a/apps/settings/src/components/PersonalInfo/FediverseSection.vue +++ b/apps/settings/src/components/PersonalInfo/FediverseSection.vue @@ -19,7 +19,7 @@ import { NAME_READABLE_ENUM } from '../../constants/AccountPropertyConstants.js' import AccountPropertySection from './shared/AccountPropertySection.vue' -const { fediverse } = loadState('settings', 'personalInfoParameters', {}) +const { fediverse } = loadState('settings', 'personalInfoParameters') const value = ref({ ...fediverse }) const readable = NAME_READABLE_ENUM[fediverse.name] @@ -29,11 +29,18 @@ const readable = NAME_READABLE_ENUM[fediverse.name] * @param text The potential fediverse handle */ function onValidate(text: string): boolean { + // allow to clear the value + if (text === '') { + return true + } + + // check its in valid format const result = text.match(/^@?([^@/]+)@([^@/]+)$/) if (result === null) { return false } + // check its a valid URL try { return URL.parse(`https://${result[2]}/`) !== null } catch { diff --git a/apps/settings/src/components/PersonalInfo/TwitterSection.vue b/apps/settings/src/components/PersonalInfo/TwitterSection.vue index 802f96087c2..43d08f81e3f 100644 --- a/apps/settings/src/components/PersonalInfo/TwitterSection.vue +++ b/apps/settings/src/components/PersonalInfo/TwitterSection.vue @@ -19,7 +19,7 @@ import { ref } from 'vue' import { NAME_READABLE_ENUM } from '../../constants/AccountPropertyConstants.ts' import AccountPropertySection from './shared/AccountPropertySection.vue' -const { twitter } = loadState('settings', 'personalInfoParameters', {}) +const { twitter } = loadState('settings', 'personalInfoParameters') const value = ref({ ...twitter }) const readable = NAME_READABLE_ENUM[twitter.name] @@ -29,6 +29,6 @@ const readable = NAME_READABLE_ENUM[twitter.name] * @param text The potential twitter handle */ function onValidate(text: string): boolean { - return text.match(/^@?([a-zA-Z0-9_]{2,15})$/) !== null + return text === '' || text.match(/^@?([a-zA-Z0-9_]{2,15})$/) !== null } diff --git a/cypress/e2e/settings/personal-info.cy.ts b/cypress/e2e/settings/personal-info.cy.ts index ba1e744bbf5..8d4b4bb606a 100644 --- a/cypress/e2e/settings/personal-info.cy.ts +++ b/cypress/e2e/settings/personal-info.cy.ts @@ -110,7 +110,7 @@ describe('Settings: Change personal information', { testIsolation: true }, () => before(() => { // make sure the fediverse check does not do http requests - cy.runOccCommand('config:system:set has_internet_connection --value false') + cy.runOccCommand('config:system:set has_internet_connection --type bool --value false') // ensure we can set locale and language cy.runOccCommand('config:system:delete force_language') cy.runOccCommand('config:system:delete force_locale') @@ -370,6 +370,23 @@ describe('Settings: Change personal information', { testIsolation: true }, () => inputForLabel('Phone number').should('have.value', '') }) + it('Can reset social media property', () => { + cy.contains('label', 'Fediverse').scrollIntoView() + inputForLabel('Fediverse').type('{selectAll}@nextcloud@mastodon.social') + handlePasswordConfirmation(user.password) + + cy.wait('@submitSetting') + cy.reload() + inputForLabel('Fediverse').should('have.value', 'nextcloud@mastodon.social') + + inputForLabel('Fediverse').clear() + handlePasswordConfirmation(user.password) + + cy.wait('@submitSetting') + cy.reload() + inputForLabel('Fediverse').should('have.value', '') + }) + it('Can set Website and change its visibility', () => { cy.contains('label', 'Website').scrollIntoView() // Check invalid input