From ae5984d2f1bca6e76166a49f1c54de043c0bdfc5 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 20 Aug 2026 21:00:36 +0300 Subject: [PATCH] remove related dispatches --- src/boot/after_store.js | 2 +- src/components/chat_new/chat_new.js | 3 +- .../domain_mute_card/domain_mute_card.js | 4 +- src/components/emoji_input/suggestor.js | 4 +- .../follow_request_card.js | 6 +- .../lists_user_search/lists_user_search.js | 4 +- src/components/mobile_nav/mobile_nav.js | 3 +- src/components/notification/notification.js | 11 +- src/components/notifications/notifications.js | 1 - src/components/quote/quote_form.js | 4 +- .../remove_follower_button.js | 7 +- src/components/search/search.js | 5 +- .../settings_modal/tabs/composing_tab.js | 5 +- .../settings_modal/tabs/developer_tab.js | 5 +- .../tabs/mutes_and_blocks_tab.js | 7 +- src/components/status/status.js | 4 +- .../action_button_container.js | 2 +- .../status_bookmark_folder_menu.js | 5 +- .../user_list_menu/user_list_menu.js | 7 +- src/components/user_note/user_note.js | 9 +- src/lib/push_notifications_plugin.js | 27 -- .../status_poster/status_poster.service.js | 10 +- src/services/sw/sw.js | 7 +- test/fixtures/setup_test.js | 1 - test/unit/specs/boot/routes.spec.js | 1 - test/unit/specs/components/draft.spec.js | 2 +- .../specs/components/rich_content.spec.js | 336 ++++++++++-------- .../notification_utils.spec.js | 4 +- test/unit/specs/stores/notifications.spec.js | 10 - 29 files changed, 260 insertions(+), 236 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index 2b2c75362..32c1a65e2 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -543,7 +543,7 @@ const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => { window.highlightConfig = useUserHighlightStore() FaviconService.initFaviconService() - initServiceWorker(store) + initServiceWorker() window.addEventListener('focus', () => updateFocus()) diff --git a/src/components/chat_new/chat_new.js b/src/components/chat_new/chat_new.js index 23193c169..1e26d24fb 100644 --- a/src/components/chat_new/chat_new.js +++ b/src/components/chat_new/chat_new.js @@ -71,7 +71,8 @@ const chatNew = { this.loading = true this.userIds = [] this.$store - .dispatch('search', { q: query, resolve: true, type: 'accounts' }) + this.useSearchStore() + .search({ q: query, resolve: true, type: 'accounts' }) .then((data) => { this.loading = false this.userIds = data.accounts.map((a) => a.id) diff --git a/src/components/domain_mute_card/domain_mute_card.js b/src/components/domain_mute_card/domain_mute_card.js index a0442a706..274679b8d 100644 --- a/src/components/domain_mute_card/domain_mute_card.js +++ b/src/components/domain_mute_card/domain_mute_card.js @@ -17,10 +17,10 @@ const DomainMuteCard = { }, methods: { unmuteDomain() { - return this.$store.dispatch('unmuteDomain', this.domain) + return useUsersStore().unmuteDomain(this.domain) }, muteDomain() { - return this.$store.dispatch('muteDomain', this.domain) + return useUsersStore().muteDomain(this.domain) }, }, } diff --git a/src/components/emoji_input/suggestor.js b/src/components/emoji_input/suggestor.js index c31cb6717..6a7dbff9a 100644 --- a/src/components/emoji_input/suggestor.js +++ b/src/components/emoji_input/suggestor.js @@ -1,3 +1,5 @@ +import { useSearchStore } from 'src/stores/search.js' + /** * suggest - generates a suggestor function to be used by emoji-input * data: object providing source information for specific types of suggestions: @@ -77,7 +79,7 @@ export const suggestUsers = ({ dispatch, state }) => { let timeout = null let cancelUserSearch = null - const userSearch = (query) => dispatch('searchUsers', { query }) + const userSearch = (query) => useSearchStore().searchUsers({ query }) const debounceUserSearch = (query) => { cancelUserSearch?.() return new Promise((resolve, reject) => { diff --git a/src/components/follow_request_card/follow_request_card.js b/src/components/follow_request_card/follow_request_card.js index 02d3bec34..c4b43811a 100644 --- a/src/components/follow_request_card/follow_request_card.js +++ b/src/components/follow_request_card/follow_request_card.js @@ -55,10 +55,11 @@ const FollowRequestCard = { id: this.user.id, credentials: useOAuthStore().token, }) + // TODO fix this.$store.dispatch('removeFollowRequest', this.user) const notifId = this.findFollowRequestNotificationId() - this.$store.dispatch('markSingleNotificationAsSeen', { id: notifId }) + useNotificationsStore().markSingleNotificationAsSeen(notifId) this.hideApproveConfirmDialog() }, denyUser() { @@ -75,7 +76,8 @@ const FollowRequestCard = { id: this.user.id, credentials: useOAuthStore().token, }).then(() => { - this.$store.dispatch('dismissNotificationLocal', { id: notifId }) + useNotificationsStore().dismissNotificationLocal(notifId) + // TODO fix this.$store.dispatch('removeFollowRequest', this.user) }) this.hideDenyConfirmDialog() diff --git a/src/components/lists_user_search/lists_user_search.js b/src/components/lists_user_search/lists_user_search.js index aed3f1ce7..5ac6e679a 100644 --- a/src/components/lists_user_search/lists_user_search.js +++ b/src/components/lists_user_search/lists_user_search.js @@ -32,8 +32,8 @@ const ListsUserSearch = { this.loading = true this.$emit('loading') this.userIds = [] - this.$store - .dispatch('search', { + this.useSearchStore() + .search({ q: query, resolve: true, type: 'accounts', diff --git a/src/components/mobile_nav/mobile_nav.js b/src/components/mobile_nav/mobile_nav.js index 80cfc5326..163c0e9aa 100644 --- a/src/components/mobile_nav/mobile_nav.js +++ b/src/components/mobile_nav/mobile_nav.js @@ -12,6 +12,7 @@ import { useAnnouncementsStore } from 'src/stores/announcements.js' import { useChatsStore } from 'src/stores/chats.js' import { useInstanceStore } from 'src/stores/instance.js' import { useMergedConfigStore } from 'src/stores/merged_config.js' +import { useNotificationsStore } from 'src/stores/notifications.js' import { useUsersStore } from 'src/stores/users.js' import { library } from '@fortawesome/fontawesome-svg-core' @@ -149,7 +150,7 @@ const MobileNav = { this.hideConfirmLogout() }, markNotificationsAsSeen() { - this.$store.dispatch('markNotificationsAsSeen') + useNotificationsStore().markNotificationsAsSeen() }, onScroll({ target: { scrollTop, clientHeight, scrollHeight } }) { this.notificationsAtTop = scrollTop > 0 diff --git a/src/components/notification/notification.js b/src/components/notification/notification.js index 577a81142..a589c0cf6 100644 --- a/src/components/notification/notification.js +++ b/src/components/notification/notification.js @@ -15,6 +15,7 @@ import { import { useInstanceStore } from 'src/stores/instance.js' import { useMergedConfigStore } from 'src/stores/merged_config.js' +import { useNotificationsStore } from 'src/stores/notifications.js' import { useOAuthStore } from 'src/stores/oauth.js' import { useStatusesStore } from 'src/stores/statuses.js' import { useUserHighlightStore } from 'src/stores/user_highlight.js' @@ -150,10 +151,9 @@ const Notification = { id: this.user.id, credentials: useOAuthStore().token, }) + // TODO Fix this this.$store.dispatch('removeFollowRequest', this.user) - this.$store.dispatch('markSingleNotificationAsSeen', { - id: this.notification.id, - }) + useNotificationsStore().markSingleNotificationAsSeen(this.notification.id) this.hideApproveConfirmDialog() }, denyUser() { @@ -168,9 +168,8 @@ const Notification = { id: this.user.id, credentials: useOAuthStore().token, }).then(() => { - this.$store.dispatch('dismissNotificationLocal', { - id: this.notification.id, - }) + useNotificationsStore().dismissNotificationLocal(this.notification.id) + // TODO Fix this this.$store.dispatch('removeFollowRequest', this.user) }) this.hideDenyConfirmDialog() diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js index 3f65cc65b..e642fc554 100644 --- a/src/components/notifications/notifications.js +++ b/src/components/notifications/notifications.js @@ -17,7 +17,6 @@ import { useChatsStore } from 'src/stores/chats.js' import { useInterfaceStore } from 'src/stores/interface.js' import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useNotificationsStore } from 'src/stores/notifications.js' -import { useUsersStore } from 'src/stores/users.js' import { library } from '@fortawesome/fontawesome-svg-core' import { diff --git a/src/components/quote/quote_form.js b/src/components/quote/quote_form.js index b350fb0e3..61abf743b 100644 --- a/src/components/quote/quote_form.js +++ b/src/components/quote/quote_form.js @@ -93,8 +93,8 @@ export default { this.$emit('update:id', notice[3]) } else if (value) { this.loading = true - this.$store - .dispatch('search', { + this.useSearchStore() + .search({ q: value, resolve: true, offset: 0, diff --git a/src/components/remove_follower_button/remove_follower_button.js b/src/components/remove_follower_button/remove_follower_button.js index cbe92dce1..a0e7a0f13 100644 --- a/src/components/remove_follower_button/remove_follower_button.js +++ b/src/components/remove_follower_button/remove_follower_button.js @@ -1,6 +1,7 @@ import { defineAsyncComponent } from 'vue' import { useMergedConfigStore } from 'src/stores/merged_config.js' +import { useUsersStore } from 'src/stores/users.js' export default { props: ['user', 'relationship'], @@ -43,9 +44,9 @@ export default { }, doRemoveUserFromFollowers() { this.inProgress = true - this.$store - .dispatch('removeUserFromFollowers', this.relationship.id) - .then(() => { + useUsersStore() + .removeUserFromFollowers(this.relationship.id) + .finally(() => { this.inProgress = false }) this.hideConfirmRemoveUserFromFollowers() diff --git a/src/components/search/search.js b/src/components/search/search.js index e4c2c5674..43a9b4f73 100644 --- a/src/components/search/search.js +++ b/src/components/search/search.js @@ -4,6 +4,7 @@ import Conversation from 'src/components/conversation/conversation.vue' import FollowCard from 'src/components/follow_card/follow_card.vue' import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx' +import { useSearchStore } from 'src/stores/search.js' import { useStatusesStore } from 'src/stores/statuses.js' import { useUsersStore } from 'src/stores/users.js' @@ -79,8 +80,8 @@ const Search = { this.lastStatusFetchCount = 0 } - this.$store - .dispatch('search', { + useSearchStore() + .search({ q: query, resolve: true, offset: this.statusesOffset, diff --git a/src/components/settings_modal/tabs/composing_tab.js b/src/components/settings_modal/tabs/composing_tab.js index dadb2498f..3e734e6e9 100644 --- a/src/components/settings_modal/tabs/composing_tab.js +++ b/src/components/settings_modal/tabs/composing_tab.js @@ -13,6 +13,7 @@ import UnitSetting from '../helpers/unit_setting.vue' import { useInstanceStore } from 'src/stores/instance.js' import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js' +import { useInterfaceStore } from 'src/stores/interface.js' import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useOAuthStore } from 'src/stores/oauth.js' import { useSyncConfigStore } from 'src/stores/sync_config.js' @@ -139,10 +140,10 @@ const ComposingTab = { clearCache(key) { clearCache(key) .then(() => { - this.$store.dispatch('settingsSaved', { success: true }) + useInterfaceStore().settingsSaved({ success: true }) }) .catch((error) => { - this.$store.dispatch('settingsSaved', { error }) + useInterfaceStore().settingsSaved({ error }) }) }, tooSmall() { diff --git a/src/components/settings_modal/tabs/developer_tab.js b/src/components/settings_modal/tabs/developer_tab.js index 9a6258638..9697233d5 100644 --- a/src/components/settings_modal/tabs/developer_tab.js +++ b/src/components/settings_modal/tabs/developer_tab.js @@ -4,6 +4,7 @@ import BooleanSetting from '../helpers/boolean_setting.vue' import SharedComputedObject from '../helpers/shared_computed_object.js' import { useInstanceStore } from 'src/stores/instance.js' +import { useInterfaceStore } from 'src/stores/interface.js' import { cacheKey, clearCache, emojiCacheKey } from 'src/services/sw/sw.js' @@ -35,10 +36,10 @@ const VersionTab = { clearCache(key) { clearCache(key) .then(() => { - this.$store.dispatch('settingsSaved', { success: true }) + useInterfaceStore().settingsSaved({ success: true }) }) .catch((error) => { - this.$store.dispatch('settingsSaved', { error }) + useInterfaceStore().settingsSaved({ error }) }) }, }, diff --git a/src/components/settings_modal/tabs/mutes_and_blocks_tab.js b/src/components/settings_modal/tabs/mutes_and_blocks_tab.js index e7884992e..824ec6a2e 100644 --- a/src/components/settings_modal/tabs/mutes_and_blocks_tab.js +++ b/src/components/settings_modal/tabs/mutes_and_blocks_tab.js @@ -12,6 +12,7 @@ import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx' import { useInstanceStore } from 'src/stores/instance.js' import { useOAuthStore } from 'src/stores/oauth.js' import { useOAuthTokensStore } from 'src/stores/oauth_tokens.js' +import { useSearchStore } from 'src/stores/search.js' import { useUsersStore } from 'src/stores/users.js' import { importBlocks, importFollows } from 'src/api/user.js' @@ -106,8 +107,8 @@ const MutesAndBlocks = { }) }, queryUserIds(query) { - return this.$store - .dispatch('searchUsers', { query }) + return useSearchStore() + .searchUsers({ query }) .then((users) => map(users, 'id')) }, blockUsers(ids) { @@ -133,7 +134,7 @@ const MutesAndBlocks = { }) }, unmuteDomains(domains) { - return this.$store.dispatch('unmuteDomains', domains) + return useUsersStore().unmuteDomains(domains) }, }, } diff --git a/src/components/status/status.js b/src/components/status/status.js index 7c8400bdc..d807b64ff 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -564,7 +564,7 @@ const Status = { this.mainStatus.rebloggedBy && this.mainStatus.rebloggedBy.length !== num ) { - this.$store.dispatch('fetchRepeats', this.status.id) + useStatusesStore().fetchRepeats(this.status.id) } }, 'mainStatus.fave_num': function (num) { @@ -574,7 +574,7 @@ const Status = { this.mainStatus.favoritedBy && this.mainStatus.favoritedBy.length !== num ) { - this.$store.dispatch('fetchFavs', this.status.id) + useStatusesStore().fetchFavs(this.status.id) } }, isSuspendable: function (suspend) { diff --git a/src/components/status_action_buttons/action_button_container.js b/src/components/status_action_buttons/action_button_container.js index cdb83c0b5..fce80d9f0 100644 --- a/src/components/status_action_buttons/action_button_container.js +++ b/src/components/status_action_buttons/action_button_container.js @@ -50,7 +50,7 @@ export default { emits: ['emojiPickerShown'], mounted() { if (this.button.name === 'mute') { - this.$store.dispatch('fetchDomainMutes') + useUsersStore().fetchDomainMutes() } }, data() { diff --git a/src/components/status_bookmark_folder_menu/status_bookmark_folder_menu.js b/src/components/status_bookmark_folder_menu/status_bookmark_folder_menu.js index c2f070b6d..5e2c71b65 100644 --- a/src/components/status_bookmark_folder_menu/status_bookmark_folder_menu.js +++ b/src/components/status_bookmark_folder_menu/status_bookmark_folder_menu.js @@ -3,6 +3,7 @@ import { mapState } from 'pinia' import Popover from 'src/components/popover/popover.vue' import { useBookmarkFoldersStore } from 'src/stores/bookmark_folders.js' +import { useStatusesStore } from 'src/stores/statuses.js' import { library } from '@fortawesome/fontawesome-svg-core' import { faChevronRight, faFolder } from '@fortawesome/free-solid-svg-icons' @@ -30,8 +31,8 @@ const StatusBookmarkFolderMenu = { toggleFolder(id) { const value = id === this.folderId ? null : id - this.$store - .dispatch('bookmark', { id: this.status.id, bookmark_folder_id: value }) + useStatusesStore() + .bookmark(this.status.id, value) .then(() => this.$emit('success')) .catch((err) => this.$emit('error', err.error.error)) }, diff --git a/src/components/user_list_menu/user_list_menu.js b/src/components/user_list_menu/user_list_menu.js index b36175276..d04cdf692 100644 --- a/src/components/user_list_menu/user_list_menu.js +++ b/src/components/user_list_menu/user_list_menu.js @@ -3,6 +3,7 @@ import { mapState } from 'pinia' import Popover from 'src/components/popover/popover.vue' import { useListsStore } from 'src/stores/lists.js' +import { useUsersStore } from 'src/stores/users.js' import { library } from '@fortawesome/fontawesome-svg-core' import { faChevronRight } from '@fortawesome/free-solid-svg-icons' @@ -18,7 +19,7 @@ const UserListMenu = { Popover, }, created() { - this.$store.dispatch('fetchUserInLists', this.user.id) + useUsersStore().fetchUserInLists(this.user.id) }, computed: { ...mapState(useListsStore, { @@ -49,7 +50,7 @@ const UserListMenu = { if (!response.ok) { return } - this.$store.dispatch('fetchUserInLists', this.user.id) + useUsersStore().fetchUserInLists(this.user.id) }) } else { useListsStore() @@ -58,7 +59,7 @@ const UserListMenu = { if (!response.ok) { return } - this.$store.dispatch('fetchUserInLists', this.user.id) + useUsersStore().fetchUserInLists(this.user.id) }) } }, diff --git a/src/components/user_note/user_note.js b/src/components/user_note/user_note.js index bd246e9b3..dab3ac9f6 100644 --- a/src/components/user_note/user_note.js +++ b/src/components/user_note/user_note.js @@ -1,5 +1,7 @@ import PanelLoading from 'src/components/panel_loading/panel_loading.vue' +import { useUsersStore } from 'src/stores/users.js' + const UserNote = { props: { user: Object, @@ -29,11 +31,8 @@ const UserNote = { finalizeEditing() { this.frozen = true - this.$store - .dispatch('editUserNote', { - id: this.user.id, - comment: this.localNote, - }) + useUsersStore() + .editUserNote(this.user.id, this.localNote) .then(() => { this.frozen = false this.editing = false diff --git a/src/lib/push_notifications_plugin.js b/src/lib/push_notifications_plugin.js index 4798068cf..951eb2c4b 100644 --- a/src/lib/push_notifications_plugin.js +++ b/src/lib/push_notifications_plugin.js @@ -61,30 +61,3 @@ export const piniaPushNotificationsPlugin = ({ store }) => { } }) } - -// TODO make it work with pinia -export const vuexPushNotificationsPlugin = (store) => { - store.subscribe((mutation, state) => { - // Initial state - const vapidPublicKey = useInstanceStore().vapidPublicKey - const enabled = useMergedConfigStore().mergedConfig.webPushNotifications - const permissionGranted = - useInterfaceStore().notificationPermission === 'granted' - const permissionPresent = - useInterfaceStore().notificationPermission !== undefined - const user = state.users.currentUser - - if (!permissionPresent || !vapidPublicKey) return - - if ( - mutation.type === 'setCurrentUser' || - mutation.type === 'clearCurrentUser' - ) { - if (user && permissionGranted && enabled) { - return store.dispatch('registerPushNotifications') - } else { - return store.dispatch('unregisterPushNotifications') - } - } - }) -} diff --git a/src/services/status_poster/status_poster.service.js b/src/services/status_poster/status_poster.service.js index a25f60107..371632ece 100644 --- a/src/services/status_poster/status_poster.service.js +++ b/src/services/status_poster/status_poster.service.js @@ -1,6 +1,7 @@ import { map } from 'lodash' import { useStatusesStore } from 'src/stores/statuses.js' +import { useTimelinesStore } from 'src/stores/timelines.js' import { useUsersStore } from 'src/stores/users.js' import { @@ -75,10 +76,13 @@ const editStatus = ({ mediaIds, contentType, }) - .then(({ data }) => { - store.dispatch('addNewStatuses', { + .then(({ data, timestamp }) => { + useStatusesStore().addNewStatuses({ + statuses: [data], + timestamp, + }) + useTimelinesStore().addStatusesToTimeline('friends', undefined, { statuses: [data], - timeline: 'friends', showImmediately: true, noIdUpdate: true, // To prevent missing notices on next pull. }) diff --git a/src/services/sw/sw.js b/src/services/sw/sw.js index ef8200a4d..9040f0cf5 100644 --- a/src/services/sw/sw.js +++ b/src/services/sw/sw.js @@ -1,3 +1,5 @@ +import { useNotificationsStore } from 'src/stores/notifications.js' + /* global process */ function urlBase64ToUint8Array(base64String) { const padding = '='.repeat((4 - (base64String.length % 4)) % 4) @@ -94,16 +96,15 @@ function sendSubscriptionToBackEnd( return responseData }) } -export async function initServiceWorker(store) { +export async function initServiceWorker() { if (!isSWSupported()) return await getOrCreateServiceWorker() navigator.serviceWorker.addEventListener('message', (event) => { - const { dispatch } = store const { type, ...rest } = event.data switch (type) { case 'notificationClicked': - dispatch('notificationClicked', { id: rest.id }) + useNotificationsStore().notificationClicked(rest.id) } }) } diff --git a/test/fixtures/setup_test.js b/test/fixtures/setup_test.js index d63e639d7..3da0231a4 100644 --- a/test/fixtures/setup_test.js +++ b/test/fixtures/setup_test.js @@ -1,4 +1,3 @@ -import { createTestingPinia } from '@pinia/testing' import { config } from '@vue/test-utils' import { createMemoryHistory, createRouter } from 'vue-router' import VueVirtualScroller from 'vue-virtual-scroller' diff --git a/test/unit/specs/boot/routes.spec.js b/test/unit/specs/boot/routes.spec.js index a7fab6210..068bedabe 100644 --- a/test/unit/specs/boot/routes.spec.js +++ b/test/unit/specs/boot/routes.spec.js @@ -3,7 +3,6 @@ import { createTestingPinia } from '@pinia/testing' createTestingPinia() import { createMemoryHistory, createRouter } from 'vue-router' -import { createStore } from 'vuex' import routes from 'src/boot/routes' diff --git a/test/unit/specs/components/draft.spec.js b/test/unit/specs/components/draft.spec.js index 6332eba7e..40d63419b 100644 --- a/test/unit/specs/components/draft.spec.js +++ b/test/unit/specs/components/draft.spec.js @@ -2,12 +2,12 @@ import { createTestingPinia } from '@pinia/testing' import { flushPromises, mount } from '@vue/test-utils' import { setActivePinia } from 'pinia' import { nextTick } from 'vue' -import { useUsersStore } from 'src/stores/users.js' import PostStatusForm from 'src/components/post_status_form/post_status_form.vue' import { $t, mountOpts, waitForEvent } from '../../../fixtures/setup_test' import { useMergedConfigStore } from 'src/stores/merged_config.js' +import { useUsersStore } from 'src/stores/users.js' const autoSaveOrNot = (caseFn, caseTitle, runFn) => { caseFn(`${caseTitle} with auto-save`, function () { diff --git a/test/unit/specs/components/rich_content.spec.js b/test/unit/specs/components/rich_content.spec.js index 9286d9d73..19bfdc035 100644 --- a/test/unit/specs/components/rich_content.spec.js +++ b/test/unit/specs/components/rich_content.spec.js @@ -1,9 +1,9 @@ import { createTestingPinia } from '@pinia/testing' -import { setActivePinia } from 'pinia' import { mount, shallowMount } from '@vue/test-utils' -import { mountOpts } from '../../../fixtures/setup_test' +import { setActivePinia } from 'pinia' import RichContent from 'src/components/rich_content/rich_content.jsx' +import { mountOpts } from '../../../fixtures/setup_test' const attentions = [] @@ -30,15 +30,18 @@ describe('RichContent', () => { it('renders simple post without exploding', () => { const html = p('Hello world!') - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: true, - greentext: true, - emoji: [], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: true, + greentext: true, + emoji: [], + html, + }, + }), + ) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(html)) }) @@ -46,30 +49,36 @@ describe('RichContent', () => { it('unescapes everything as needed', () => { const html = [p('Testing 'em all'), 'Testing 'em all'].join('') const expected = [p("Testing 'em all"), "Testing 'em all"].join('') - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: true, - greentext: true, - emoji: [], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: true, + greentext: true, + emoji: [], + html, + }, + }), + ) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected)) }) it('replaces mention with mentionsline', () => { const html = p(makeMention('John'), ' how are you doing today?') - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: true, - greentext: true, - emoji: [], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: true, + greentext: true, + emoji: [], + html, + }, + }), + ) expect(wrapper.html().replaceAll('\n', '')).to.eql( compwrap(p(mentionsLine(1), ' how are you doing today?')), @@ -93,15 +102,18 @@ describe('RichContent', () => { ), ].join('') - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: true, - greentext: true, - emoji: [], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: true, + greentext: true, + emoji: [], + html, + }, + }), + ) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected)) }) @@ -128,15 +140,18 @@ describe('RichContent', () => { ].join(''), ].join('\n') - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: false, - greentext: true, - emoji: [], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: false, + greentext: true, + emoji: [], + html, + }, + }), + ) expect(wrapper.html()).to.eql(compwrap(strippedHtml)) }) @@ -148,15 +163,18 @@ describe('RichContent', () => { '>any year', ].join('\n') - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: false, - greentext: true, - emoji: [], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: false, + greentext: true, + emoji: [], + html, + }, + }), + ) expect(wrapper.html()).to.eql(compwrap(expected)) }) @@ -164,15 +182,18 @@ describe('RichContent', () => { it('Does not add greentext and cyantext if setting is set to false', () => { const html = ['>preordering videogames', '>any year'].join('\n') - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: false, - greentext: false, - emoji: [], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: false, + greentext: false, + emoji: [], + html, + }, + }), + ) expect(wrapper.html()).to.eql(compwrap(html)) }) @@ -184,15 +205,18 @@ describe('RichContent', () => { '', ) - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: false, - greentext: false, - emoji: [{ url: 'about:blank', shortcode: 'spurdo' }], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: false, + greentext: false, + emoji: [{ url: 'about:blank', shortcode: 'spurdo' }], + html, + }, + }), + ) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected)) }) @@ -200,15 +224,18 @@ describe('RichContent', () => { it("Doesn't add nonexistent emoji to post", () => { const html = p('Lol :lol:') - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: false, - greentext: false, - emoji: [], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: false, + greentext: false, + emoji: [], + html, + }, + }), + ) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(html)) }) @@ -227,15 +254,18 @@ describe('RichContent', () => { '>quote', ].join('\n') - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: true, - greentext: true, - emoji: [], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: true, + greentext: true, + emoji: [], + html, + }, + }), + ) expect(wrapper.html()).to.eql(compwrap(expected)) }) @@ -249,15 +279,18 @@ describe('RichContent', () => { ].join('
') const expected = ['Bruh', 'Bruh', mentionsLine(3), 'Bruh'].join('
') - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: true, - greentext: true, - emoji: [], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: true, + greentext: true, + emoji: [], + html, + }, + }), + ) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected)) }) @@ -284,15 +317,18 @@ describe('RichContent', () => { '

', ].join('') - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: true, - greentext: true, - emoji: [], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: true, + greentext: true, + emoji: [], + html, + }, + }), + ) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected)) }) @@ -330,15 +366,18 @@ describe('RichContent', () => { p('Testing'), ].join('') - const wrapper = mount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: true, - greentext: true, - emoji: [], - html, - }, - })) + const wrapper = mount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: true, + greentext: true, + emoji: [], + html, + }, + }), + ) expect( wrapper @@ -402,15 +441,18 @@ describe('RichContent', () => { 'Testing', ].join('') - const wrapper = mount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: true, - greentext: true, - emoji: [], - html, - }, - })) + const wrapper = mount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: true, + greentext: true, + emoji: [], + html, + }, + }), + ) expect( wrapper @@ -450,15 +492,18 @@ describe('RichContent', () => { '

', ].join('') - const wrapper = shallowMount(RichContent, mountOpts({ - props: { - attentions, - handleLinks: true, - greentext: true, - emoji: [], - html, - }, - })) + const wrapper = shallowMount( + RichContent, + mountOpts({ + props: { + attentions, + handleLinks: true, + greentext: true, + emoji: [], + html, + }, + }), + ) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected)) }) @@ -495,13 +540,16 @@ describe('RichContent', () => { const ptest = (handleLinks, vhtml) => { const t0 = performance.now() - const wrapper = mount(TestComponent, mountOpts({ - props: { - attentions, - handleLinks, - vhtml, - }, - })) + const wrapper = mount( + TestComponent, + mountOpts({ + props: { + attentions, + handleLinks, + vhtml, + }, + }), + ) const t1 = performance.now() diff --git a/test/unit/specs/services/notification_utils/notification_utils.spec.js b/test/unit/specs/services/notification_utils/notification_utils.spec.js index f610fae7f..09d39f704 100644 --- a/test/unit/specs/services/notification_utils/notification_utils.spec.js +++ b/test/unit/specs/services/notification_utils/notification_utils.spec.js @@ -1,8 +1,8 @@ -import { setActivePinia } from 'pinia' import { createTestingPinia } from '@pinia/testing' +import { setActivePinia } from 'pinia' -import { useSyncConfigStore } from 'src/stores/sync_config.js' import { useNotificationsStore } from 'src/stores/notifications.js' +import { useSyncConfigStore } from 'src/stores/sync_config.js' import * as NotificationUtils from 'src/services/notification_utils/notification_utils.js' diff --git a/test/unit/specs/stores/notifications.spec.js b/test/unit/specs/stores/notifications.spec.js index 653999cdb..ad8b6bf44 100644 --- a/test/unit/specs/stores/notifications.spec.js +++ b/test/unit/specs/stores/notifications.spec.js @@ -85,14 +85,6 @@ const mockStatusNotification = ({ from_profile: user, }) -const DEFAULT_OPTIONS = (method = 'POST') => ({ - method, - credentials: 'same-origin', - headers: { - Accept: 'application/json', - }, -}) - describe('Notifications store', () => { beforeEach(() => { vi.useFakeTimers() @@ -328,7 +320,6 @@ describe('Notifications store', () => { vi.stubGlobal('fetch', mockFetch) const store = useNotificationsStore() - const mockedNotification = mockStatusNotification() store.addNewNotifications({ timestamp: 1337, @@ -366,7 +357,6 @@ describe('Notifications store', () => { vi.stubGlobal('fetch', mockFetch) const store = useNotificationsStore() - const mockedNotification = mockStatusNotification() // FormData is weird to test store.addNewNotifications({