From 37e12e8d73e666b3ee07d409e28e03985a51baf4 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 19 Aug 2018 18:03:26 -0700 Subject: [PATCH] add option to remove emoji from user display names (#450) * add option to remove emoji from user display names fixes #449 * slight memory perf improvement --- package-lock.json | 5 ++ package.json | 1 + .../profile/AccountDisplayName.html | 16 +++++- routes/_pages/settings/general.html | 5 ++ routes/_store/store.js | 1 + routes/_utils/emojifyText.js | 12 ++++- routes/_utils/strings.js | 2 +- tests/spec/118-display-name-custom-emoji.js | 53 ++++++++++++++++++- tests/utils.js | 2 + 9 files changed, 92 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2ca14703..0433bdfc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4177,6 +4177,11 @@ "minimalistic-crypto-utils": "^1.0.0" } }, + "emoji-regex": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.0.tgz", + "integrity": "sha512-lnvttkzAlYW8WpFPiStPWyd/YdS02cFsYwXwWqnbKY43fMgUeUx+vzW1Zaozu34n4Fm7sxygi8+SEL6dcks/hQ==" + }, "emojis-list": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-2.1.0.tgz", diff --git a/package.json b/package.json index a22426fb..28c1b973 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "chokidar": "^2.0.4", "cross-env": "^5.2.0", "css-loader": "^1.0.0", + "emoji-regex": "^7.0.0", "escape-html": "^1.0.3", "esm": "^3.0.77", "events": "^3.0.0", diff --git a/routes/_components/profile/AccountDisplayName.html b/routes/_components/profile/AccountDisplayName.html index 7a64502d..40f25e6c 100644 --- a/routes/_components/profile/AccountDisplayName.html +++ b/routes/_components/profile/AccountDisplayName.html @@ -5,17 +5,29 @@ } ') }) + +test('Can remove emoji from user display names', async t => { + await updateUserDisplayNameAs('foobar', '🌈 foo :blobpats: 🌈') + await sleep(1000) + await loginAsFoobar(t) + await t + .expect(displayNameInComposeBox.innerText).eql('🌈 foo 🌈') + .expect($('.compose-box-display-name img').exists).ok() + .click(settingsNavButton) + .click(generalSettingsButton) + .click(removeEmojiFromDisplayNamesInput) + .expect(removeEmojiFromDisplayNamesInput.checked).ok() + .click(homeNavButton) + .expect(displayNameInComposeBox.innerText).eql('foo') + .expect($('.compose-box-display-name img').exists).notOk() + .click(settingsNavButton) + .click(generalSettingsButton) + .click(removeEmojiFromDisplayNamesInput) + .expect(removeEmojiFromDisplayNamesInput.checked).notOk() + .click(homeNavButton) + .expect(displayNameInComposeBox.innerText).eql('🌈 foo 🌈') + .expect($('.compose-box-display-name img').exists).ok() +}) + +test('Cannot remove emoji from user display names if result would be empty', async t => { + await updateUserDisplayNameAs('foobar', '🌈 :blobpats: 🌈') + await sleep(1000) + await loginAsFoobar(t) + await t + .expect(displayNameInComposeBox.innerText).eql('🌈 🌈') + .expect($('.compose-box-display-name img').exists).ok() + .click(settingsNavButton) + .click(generalSettingsButton) + .click(removeEmojiFromDisplayNamesInput) + .expect(removeEmojiFromDisplayNamesInput.checked).ok() + .click(homeNavButton) + .expect(displayNameInComposeBox.innerText).eql('🌈 🌈') + .expect($('.compose-box-display-name img').exists).ok() + .click(settingsNavButton) + .click(generalSettingsButton) + .click(removeEmojiFromDisplayNamesInput) + .expect(removeEmojiFromDisplayNamesInput.checked).notOk() + .click(homeNavButton) + .expect(displayNameInComposeBox.innerText).eql('🌈 🌈') + .expect($('.compose-box-display-name img').exists).ok() +}) diff --git a/tests/utils.js b/tests/utils.js index 71e1031e..836becdd 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -41,6 +41,8 @@ export const followsButton = $('.account-profile-details > *:nth-child(2)') export const followersButton = $('.account-profile-details > *:nth-child(3)') export const avatarInComposeBox = $('.compose-box-avatar') export const displayNameInComposeBox = $('.compose-box-display-name') +export const generalSettingsButton = $('a[href="/settings/general"]') +export const removeEmojiFromDisplayNamesInput = $('#choice-omit-emoji-in-display-names') export const favoritesCountElement = $('.status-favs-reblogs:nth-child(3)').addCustomDOMProperties({ innerCount: el => parseInt(el.innerText, 10)