Skip to content

Commit f5b2222

Browse files
committed
fix(settings): allow to clear twitter and fediverse
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 0371c2c commit f5b2222

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

apps/settings/src/components/PersonalInfo/FediverseSection.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { NAME_READABLE_ENUM } from '../../constants/AccountPropertyConstants.js'
1919
2020
import AccountPropertySection from './shared/AccountPropertySection.vue'
2121
22-
const { fediverse } = loadState<AccountProperties>('settings', 'personalInfoParameters', {})
22+
const { fediverse } = loadState<AccountProperties>('settings', 'personalInfoParameters')
2323
2424
const value = ref({ ...fediverse })
2525
const readable = NAME_READABLE_ENUM[fediverse.name]
@@ -29,11 +29,18 @@ const readable = NAME_READABLE_ENUM[fediverse.name]
2929
* @param text The potential fediverse handle
3030
*/
3131
function onValidate(text: string): boolean {
32+
// allow to clear the value
33+
if (text === '') {
34+
return true
35+
}
36+
37+
// check its in valid format
3238
const result = text.match(/^@?([^@/]+)@([^@/]+)$/)
3339
if (result === null) {
3440
return false
3541
}
3642
43+
// check its a valid URL
3744
try {
3845
return URL.parse(`https://${result[2]}/`) !== null
3946
} catch {

apps/settings/src/components/PersonalInfo/TwitterSection.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ref } from 'vue'
1919
import { NAME_READABLE_ENUM } from '../../constants/AccountPropertyConstants.ts'
2020
import AccountPropertySection from './shared/AccountPropertySection.vue'
2121
22-
const { twitter } = loadState<AccountProperties>('settings', 'personalInfoParameters', {})
22+
const { twitter } = loadState<AccountProperties>('settings', 'personalInfoParameters')
2323
2424
const value = ref({ ...twitter })
2525
const readable = NAME_READABLE_ENUM[twitter.name]
@@ -29,6 +29,6 @@ const readable = NAME_READABLE_ENUM[twitter.name]
2929
* @param text The potential twitter handle
3030
*/
3131
function onValidate(text: string): boolean {
32-
return text.match(/^@?([a-zA-Z0-9_]{2,15})$/) !== null
32+
return text === '' || text.match(/^@?([a-zA-Z0-9_]{2,15})$/) !== null
3333
}
3434
</script>

cypress/e2e/settings/personal-info.cy.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('Settings: Change personal information', { testIsolation: true }, () =>
110110

111111
before(() => {
112112
// make sure the fediverse check does not do http requests
113-
cy.runOccCommand('config:system:set has_internet_connection --value false')
113+
cy.runOccCommand('config:system:set has_internet_connection --type bool --value false')
114114
// ensure we can set locale and language
115115
cy.runOccCommand('config:system:delete force_language')
116116
cy.runOccCommand('config:system:delete force_locale')
@@ -370,6 +370,23 @@ describe('Settings: Change personal information', { testIsolation: true }, () =>
370370
inputForLabel('Phone number').should('have.value', '')
371371
})
372372

373+
it('Can reset social media property', () => {
374+
cy.contains('label', 'Fediverse').scrollIntoView()
375+
inputForLabel('Fediverse').type('{selectAll}@nextcloud@mastodon.social')
376+
handlePasswordConfirmation(user.password)
377+
378+
cy.wait('@submitSetting')
379+
cy.reload()
380+
inputForLabel('Fediverse').should('have.value', 'nextcloud@mastodon.social')
381+
382+
inputForLabel('Fediverse').clear()
383+
handlePasswordConfirmation(user.password)
384+
385+
cy.wait('@submitSetting')
386+
cy.reload()
387+
inputForLabel('Fediverse').should('have.value', '')
388+
})
389+
373390
it('Can set Website and change its visibility', () => {
374391
cy.contains('label', 'Website').scrollIntoView()
375392
// Check invalid input

0 commit comments

Comments
 (0)