remove related dispatches

This commit is contained in:
Henry Jameson 2026-08-20 21:00:36 +03:00
commit ae5984d2f1
29 changed files with 260 additions and 236 deletions

View file

@ -543,7 +543,7 @@ const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => {
window.highlightConfig = useUserHighlightStore() window.highlightConfig = useUserHighlightStore()
FaviconService.initFaviconService() FaviconService.initFaviconService()
initServiceWorker(store) initServiceWorker()
window.addEventListener('focus', () => updateFocus()) window.addEventListener('focus', () => updateFocus())

View file

@ -71,7 +71,8 @@ const chatNew = {
this.loading = true this.loading = true
this.userIds = [] this.userIds = []
this.$store this.$store
.dispatch('search', { q: query, resolve: true, type: 'accounts' }) this.useSearchStore()
.search({ q: query, resolve: true, type: 'accounts' })
.then((data) => { .then((data) => {
this.loading = false this.loading = false
this.userIds = data.accounts.map((a) => a.id) this.userIds = data.accounts.map((a) => a.id)

View file

@ -17,10 +17,10 @@ const DomainMuteCard = {
}, },
methods: { methods: {
unmuteDomain() { unmuteDomain() {
return this.$store.dispatch('unmuteDomain', this.domain) return useUsersStore().unmuteDomain(this.domain)
}, },
muteDomain() { muteDomain() {
return this.$store.dispatch('muteDomain', this.domain) return useUsersStore().muteDomain(this.domain)
}, },
}, },
} }

View file

@ -1,3 +1,5 @@
import { useSearchStore } from 'src/stores/search.js'
/** /**
* suggest - generates a suggestor function to be used by emoji-input * suggest - generates a suggestor function to be used by emoji-input
* data: object providing source information for specific types of suggestions: * data: object providing source information for specific types of suggestions:
@ -77,7 +79,7 @@ export const suggestUsers = ({ dispatch, state }) => {
let timeout = null let timeout = null
let cancelUserSearch = null let cancelUserSearch = null
const userSearch = (query) => dispatch('searchUsers', { query }) const userSearch = (query) => useSearchStore().searchUsers({ query })
const debounceUserSearch = (query) => { const debounceUserSearch = (query) => {
cancelUserSearch?.() cancelUserSearch?.()
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View file

@ -55,10 +55,11 @@ const FollowRequestCard = {
id: this.user.id, id: this.user.id,
credentials: useOAuthStore().token, credentials: useOAuthStore().token,
}) })
// TODO fix
this.$store.dispatch('removeFollowRequest', this.user) this.$store.dispatch('removeFollowRequest', this.user)
const notifId = this.findFollowRequestNotificationId() const notifId = this.findFollowRequestNotificationId()
this.$store.dispatch('markSingleNotificationAsSeen', { id: notifId }) useNotificationsStore().markSingleNotificationAsSeen(notifId)
this.hideApproveConfirmDialog() this.hideApproveConfirmDialog()
}, },
denyUser() { denyUser() {
@ -75,7 +76,8 @@ const FollowRequestCard = {
id: this.user.id, id: this.user.id,
credentials: useOAuthStore().token, credentials: useOAuthStore().token,
}).then(() => { }).then(() => {
this.$store.dispatch('dismissNotificationLocal', { id: notifId }) useNotificationsStore().dismissNotificationLocal(notifId)
// TODO fix
this.$store.dispatch('removeFollowRequest', this.user) this.$store.dispatch('removeFollowRequest', this.user)
}) })
this.hideDenyConfirmDialog() this.hideDenyConfirmDialog()

View file

@ -32,8 +32,8 @@ const ListsUserSearch = {
this.loading = true this.loading = true
this.$emit('loading') this.$emit('loading')
this.userIds = [] this.userIds = []
this.$store this.useSearchStore()
.dispatch('search', { .search({
q: query, q: query,
resolve: true, resolve: true,
type: 'accounts', type: 'accounts',

View file

@ -12,6 +12,7 @@ import { useAnnouncementsStore } from 'src/stores/announcements.js'
import { useChatsStore } from 'src/stores/chats.js' import { useChatsStore } from 'src/stores/chats.js'
import { useInstanceStore } from 'src/stores/instance.js' import { useInstanceStore } from 'src/stores/instance.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useNotificationsStore } from 'src/stores/notifications.js'
import { useUsersStore } from 'src/stores/users.js' import { useUsersStore } from 'src/stores/users.js'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
@ -149,7 +150,7 @@ const MobileNav = {
this.hideConfirmLogout() this.hideConfirmLogout()
}, },
markNotificationsAsSeen() { markNotificationsAsSeen() {
this.$store.dispatch('markNotificationsAsSeen') useNotificationsStore().markNotificationsAsSeen()
}, },
onScroll({ target: { scrollTop, clientHeight, scrollHeight } }) { onScroll({ target: { scrollTop, clientHeight, scrollHeight } }) {
this.notificationsAtTop = scrollTop > 0 this.notificationsAtTop = scrollTop > 0

View file

@ -15,6 +15,7 @@ import {
import { useInstanceStore } from 'src/stores/instance.js' import { useInstanceStore } from 'src/stores/instance.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useNotificationsStore } from 'src/stores/notifications.js'
import { useOAuthStore } from 'src/stores/oauth.js' import { useOAuthStore } from 'src/stores/oauth.js'
import { useStatusesStore } from 'src/stores/statuses.js' import { useStatusesStore } from 'src/stores/statuses.js'
import { useUserHighlightStore } from 'src/stores/user_highlight.js' import { useUserHighlightStore } from 'src/stores/user_highlight.js'
@ -150,10 +151,9 @@ const Notification = {
id: this.user.id, id: this.user.id,
credentials: useOAuthStore().token, credentials: useOAuthStore().token,
}) })
// TODO Fix this
this.$store.dispatch('removeFollowRequest', this.user) this.$store.dispatch('removeFollowRequest', this.user)
this.$store.dispatch('markSingleNotificationAsSeen', { useNotificationsStore().markSingleNotificationAsSeen(this.notification.id)
id: this.notification.id,
})
this.hideApproveConfirmDialog() this.hideApproveConfirmDialog()
}, },
denyUser() { denyUser() {
@ -168,9 +168,8 @@ const Notification = {
id: this.user.id, id: this.user.id,
credentials: useOAuthStore().token, credentials: useOAuthStore().token,
}).then(() => { }).then(() => {
this.$store.dispatch('dismissNotificationLocal', { useNotificationsStore().dismissNotificationLocal(this.notification.id)
id: this.notification.id, // TODO Fix this
})
this.$store.dispatch('removeFollowRequest', this.user) this.$store.dispatch('removeFollowRequest', this.user)
}) })
this.hideDenyConfirmDialog() this.hideDenyConfirmDialog()

View file

@ -17,7 +17,6 @@ import { useChatsStore } from 'src/stores/chats.js'
import { useInterfaceStore } from 'src/stores/interface.js' import { useInterfaceStore } from 'src/stores/interface.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useNotificationsStore } from 'src/stores/notifications.js' import { useNotificationsStore } from 'src/stores/notifications.js'
import { useUsersStore } from 'src/stores/users.js'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
import { import {

View file

@ -93,8 +93,8 @@ export default {
this.$emit('update:id', notice[3]) this.$emit('update:id', notice[3])
} else if (value) { } else if (value) {
this.loading = true this.loading = true
this.$store this.useSearchStore()
.dispatch('search', { .search({
q: value, q: value,
resolve: true, resolve: true,
offset: 0, offset: 0,

View file

@ -1,6 +1,7 @@
import { defineAsyncComponent } from 'vue' import { defineAsyncComponent } from 'vue'
import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useUsersStore } from 'src/stores/users.js'
export default { export default {
props: ['user', 'relationship'], props: ['user', 'relationship'],
@ -43,9 +44,9 @@ export default {
}, },
doRemoveUserFromFollowers() { doRemoveUserFromFollowers() {
this.inProgress = true this.inProgress = true
this.$store useUsersStore()
.dispatch('removeUserFromFollowers', this.relationship.id) .removeUserFromFollowers(this.relationship.id)
.then(() => { .finally(() => {
this.inProgress = false this.inProgress = false
}) })
this.hideConfirmRemoveUserFromFollowers() this.hideConfirmRemoveUserFromFollowers()

View file

@ -4,6 +4,7 @@ import Conversation from 'src/components/conversation/conversation.vue'
import FollowCard from 'src/components/follow_card/follow_card.vue' import FollowCard from 'src/components/follow_card/follow_card.vue'
import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx' 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 { useStatusesStore } from 'src/stores/statuses.js'
import { useUsersStore } from 'src/stores/users.js' import { useUsersStore } from 'src/stores/users.js'
@ -79,8 +80,8 @@ const Search = {
this.lastStatusFetchCount = 0 this.lastStatusFetchCount = 0
} }
this.$store useSearchStore()
.dispatch('search', { .search({
q: query, q: query,
resolve: true, resolve: true,
offset: this.statusesOffset, offset: this.statusesOffset,

View file

@ -13,6 +13,7 @@ import UnitSetting from '../helpers/unit_setting.vue'
import { useInstanceStore } from 'src/stores/instance.js' import { useInstanceStore } from 'src/stores/instance.js'
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.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 { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useOAuthStore } from 'src/stores/oauth.js' import { useOAuthStore } from 'src/stores/oauth.js'
import { useSyncConfigStore } from 'src/stores/sync_config.js' import { useSyncConfigStore } from 'src/stores/sync_config.js'
@ -139,10 +140,10 @@ const ComposingTab = {
clearCache(key) { clearCache(key) {
clearCache(key) clearCache(key)
.then(() => { .then(() => {
this.$store.dispatch('settingsSaved', { success: true }) useInterfaceStore().settingsSaved({ success: true })
}) })
.catch((error) => { .catch((error) => {
this.$store.dispatch('settingsSaved', { error }) useInterfaceStore().settingsSaved({ error })
}) })
}, },
tooSmall() { tooSmall() {

View file

@ -4,6 +4,7 @@ import BooleanSetting from '../helpers/boolean_setting.vue'
import SharedComputedObject from '../helpers/shared_computed_object.js' import SharedComputedObject from '../helpers/shared_computed_object.js'
import { useInstanceStore } from 'src/stores/instance.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' import { cacheKey, clearCache, emojiCacheKey } from 'src/services/sw/sw.js'
@ -35,10 +36,10 @@ const VersionTab = {
clearCache(key) { clearCache(key) {
clearCache(key) clearCache(key)
.then(() => { .then(() => {
this.$store.dispatch('settingsSaved', { success: true }) useInterfaceStore().settingsSaved({ success: true })
}) })
.catch((error) => { .catch((error) => {
this.$store.dispatch('settingsSaved', { error }) useInterfaceStore().settingsSaved({ error })
}) })
}, },
}, },

View file

@ -12,6 +12,7 @@ import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx'
import { useInstanceStore } from 'src/stores/instance.js' import { useInstanceStore } from 'src/stores/instance.js'
import { useOAuthStore } from 'src/stores/oauth.js' import { useOAuthStore } from 'src/stores/oauth.js'
import { useOAuthTokensStore } from 'src/stores/oauth_tokens.js' import { useOAuthTokensStore } from 'src/stores/oauth_tokens.js'
import { useSearchStore } from 'src/stores/search.js'
import { useUsersStore } from 'src/stores/users.js' import { useUsersStore } from 'src/stores/users.js'
import { importBlocks, importFollows } from 'src/api/user.js' import { importBlocks, importFollows } from 'src/api/user.js'
@ -106,8 +107,8 @@ const MutesAndBlocks = {
}) })
}, },
queryUserIds(query) { queryUserIds(query) {
return this.$store return useSearchStore()
.dispatch('searchUsers', { query }) .searchUsers({ query })
.then((users) => map(users, 'id')) .then((users) => map(users, 'id'))
}, },
blockUsers(ids) { blockUsers(ids) {
@ -133,7 +134,7 @@ const MutesAndBlocks = {
}) })
}, },
unmuteDomains(domains) { unmuteDomains(domains) {
return this.$store.dispatch('unmuteDomains', domains) return useUsersStore().unmuteDomains(domains)
}, },
}, },
} }

View file

@ -564,7 +564,7 @@ const Status = {
this.mainStatus.rebloggedBy && this.mainStatus.rebloggedBy &&
this.mainStatus.rebloggedBy.length !== num this.mainStatus.rebloggedBy.length !== num
) { ) {
this.$store.dispatch('fetchRepeats', this.status.id) useStatusesStore().fetchRepeats(this.status.id)
} }
}, },
'mainStatus.fave_num': function (num) { 'mainStatus.fave_num': function (num) {
@ -574,7 +574,7 @@ const Status = {
this.mainStatus.favoritedBy && this.mainStatus.favoritedBy &&
this.mainStatus.favoritedBy.length !== num this.mainStatus.favoritedBy.length !== num
) { ) {
this.$store.dispatch('fetchFavs', this.status.id) useStatusesStore().fetchFavs(this.status.id)
} }
}, },
isSuspendable: function (suspend) { isSuspendable: function (suspend) {

View file

@ -50,7 +50,7 @@ export default {
emits: ['emojiPickerShown'], emits: ['emojiPickerShown'],
mounted() { mounted() {
if (this.button.name === 'mute') { if (this.button.name === 'mute') {
this.$store.dispatch('fetchDomainMutes') useUsersStore().fetchDomainMutes()
} }
}, },
data() { data() {

View file

@ -3,6 +3,7 @@ import { mapState } from 'pinia'
import Popover from 'src/components/popover/popover.vue' import Popover from 'src/components/popover/popover.vue'
import { useBookmarkFoldersStore } from 'src/stores/bookmark_folders.js' import { useBookmarkFoldersStore } from 'src/stores/bookmark_folders.js'
import { useStatusesStore } from 'src/stores/statuses.js'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
import { faChevronRight, faFolder } from '@fortawesome/free-solid-svg-icons' import { faChevronRight, faFolder } from '@fortawesome/free-solid-svg-icons'
@ -30,8 +31,8 @@ const StatusBookmarkFolderMenu = {
toggleFolder(id) { toggleFolder(id) {
const value = id === this.folderId ? null : id const value = id === this.folderId ? null : id
this.$store useStatusesStore()
.dispatch('bookmark', { id: this.status.id, bookmark_folder_id: value }) .bookmark(this.status.id, value)
.then(() => this.$emit('success')) .then(() => this.$emit('success'))
.catch((err) => this.$emit('error', err.error.error)) .catch((err) => this.$emit('error', err.error.error))
}, },

View file

@ -3,6 +3,7 @@ import { mapState } from 'pinia'
import Popover from 'src/components/popover/popover.vue' import Popover from 'src/components/popover/popover.vue'
import { useListsStore } from 'src/stores/lists.js' import { useListsStore } from 'src/stores/lists.js'
import { useUsersStore } from 'src/stores/users.js'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
import { faChevronRight } from '@fortawesome/free-solid-svg-icons' import { faChevronRight } from '@fortawesome/free-solid-svg-icons'
@ -18,7 +19,7 @@ const UserListMenu = {
Popover, Popover,
}, },
created() { created() {
this.$store.dispatch('fetchUserInLists', this.user.id) useUsersStore().fetchUserInLists(this.user.id)
}, },
computed: { computed: {
...mapState(useListsStore, { ...mapState(useListsStore, {
@ -49,7 +50,7 @@ const UserListMenu = {
if (!response.ok) { if (!response.ok) {
return return
} }
this.$store.dispatch('fetchUserInLists', this.user.id) useUsersStore().fetchUserInLists(this.user.id)
}) })
} else { } else {
useListsStore() useListsStore()
@ -58,7 +59,7 @@ const UserListMenu = {
if (!response.ok) { if (!response.ok) {
return return
} }
this.$store.dispatch('fetchUserInLists', this.user.id) useUsersStore().fetchUserInLists(this.user.id)
}) })
} }
}, },

View file

@ -1,5 +1,7 @@
import PanelLoading from 'src/components/panel_loading/panel_loading.vue' import PanelLoading from 'src/components/panel_loading/panel_loading.vue'
import { useUsersStore } from 'src/stores/users.js'
const UserNote = { const UserNote = {
props: { props: {
user: Object, user: Object,
@ -29,11 +31,8 @@ const UserNote = {
finalizeEditing() { finalizeEditing() {
this.frozen = true this.frozen = true
this.$store useUsersStore()
.dispatch('editUserNote', { .editUserNote(this.user.id, this.localNote)
id: this.user.id,
comment: this.localNote,
})
.then(() => { .then(() => {
this.frozen = false this.frozen = false
this.editing = false this.editing = false

View file

@ -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')
}
}
})
}

View file

@ -1,6 +1,7 @@
import { map } from 'lodash' import { map } from 'lodash'
import { useStatusesStore } from 'src/stores/statuses.js' import { useStatusesStore } from 'src/stores/statuses.js'
import { useTimelinesStore } from 'src/stores/timelines.js'
import { useUsersStore } from 'src/stores/users.js' import { useUsersStore } from 'src/stores/users.js'
import { import {
@ -75,10 +76,13 @@ const editStatus = ({
mediaIds, mediaIds,
contentType, contentType,
}) })
.then(({ data }) => { .then(({ data, timestamp }) => {
store.dispatch('addNewStatuses', { useStatusesStore().addNewStatuses({
statuses: [data],
timestamp,
})
useTimelinesStore().addStatusesToTimeline('friends', undefined, {
statuses: [data], statuses: [data],
timeline: 'friends',
showImmediately: true, showImmediately: true,
noIdUpdate: true, // To prevent missing notices on next pull. noIdUpdate: true, // To prevent missing notices on next pull.
}) })

View file

@ -1,3 +1,5 @@
import { useNotificationsStore } from 'src/stores/notifications.js'
/* global process */ /* global process */
function urlBase64ToUint8Array(base64String) { function urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - (base64String.length % 4)) % 4) const padding = '='.repeat((4 - (base64String.length % 4)) % 4)
@ -94,16 +96,15 @@ function sendSubscriptionToBackEnd(
return responseData return responseData
}) })
} }
export async function initServiceWorker(store) { export async function initServiceWorker() {
if (!isSWSupported()) return if (!isSWSupported()) return
await getOrCreateServiceWorker() await getOrCreateServiceWorker()
navigator.serviceWorker.addEventListener('message', (event) => { navigator.serviceWorker.addEventListener('message', (event) => {
const { dispatch } = store
const { type, ...rest } = event.data const { type, ...rest } = event.data
switch (type) { switch (type) {
case 'notificationClicked': case 'notificationClicked':
dispatch('notificationClicked', { id: rest.id }) useNotificationsStore().notificationClicked(rest.id)
} }
}) })
} }

View file

@ -1,4 +1,3 @@
import { createTestingPinia } from '@pinia/testing'
import { config } from '@vue/test-utils' import { config } from '@vue/test-utils'
import { createMemoryHistory, createRouter } from 'vue-router' import { createMemoryHistory, createRouter } from 'vue-router'
import VueVirtualScroller from 'vue-virtual-scroller' import VueVirtualScroller from 'vue-virtual-scroller'

View file

@ -3,7 +3,6 @@ import { createTestingPinia } from '@pinia/testing'
createTestingPinia() createTestingPinia()
import { createMemoryHistory, createRouter } from 'vue-router' import { createMemoryHistory, createRouter } from 'vue-router'
import { createStore } from 'vuex'
import routes from 'src/boot/routes' import routes from 'src/boot/routes'

View file

@ -2,12 +2,12 @@ import { createTestingPinia } from '@pinia/testing'
import { flushPromises, mount } from '@vue/test-utils' import { flushPromises, mount } from '@vue/test-utils'
import { setActivePinia } from 'pinia' import { setActivePinia } from 'pinia'
import { nextTick } from 'vue' import { nextTick } from 'vue'
import { useUsersStore } from 'src/stores/users.js'
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue' import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
import { $t, mountOpts, waitForEvent } from '../../../fixtures/setup_test' import { $t, mountOpts, waitForEvent } from '../../../fixtures/setup_test'
import { useMergedConfigStore } from 'src/stores/merged_config.js' import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useUsersStore } from 'src/stores/users.js'
const autoSaveOrNot = (caseFn, caseTitle, runFn) => { const autoSaveOrNot = (caseFn, caseTitle, runFn) => {
caseFn(`${caseTitle} with auto-save`, function () { caseFn(`${caseTitle} with auto-save`, function () {

View file

@ -1,9 +1,9 @@
import { createTestingPinia } from '@pinia/testing' import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { mount, shallowMount } from '@vue/test-utils' 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 RichContent from 'src/components/rich_content/rich_content.jsx'
import { mountOpts } from '../../../fixtures/setup_test'
const attentions = [] const attentions = []
@ -30,15 +30,18 @@ describe('RichContent', () => {
it('renders simple post without exploding', () => { it('renders simple post without exploding', () => {
const html = p('Hello world!') const html = p('Hello world!')
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: true, props: {
greentext: true, attentions,
emoji: [], handleLinks: true,
html, greentext: true,
}, emoji: [],
})) html,
},
}),
)
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(html)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(html))
}) })
@ -46,30 +49,36 @@ describe('RichContent', () => {
it('unescapes everything as needed', () => { it('unescapes everything as needed', () => {
const html = [p('Testing 'em all'), 'Testing 'em all'].join('') const html = [p('Testing 'em all'), 'Testing 'em all'].join('')
const expected = [p("Testing 'em all"), "Testing 'em all"].join('') const expected = [p("Testing 'em all"), "Testing 'em all"].join('')
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: true, props: {
greentext: true, attentions,
emoji: [], handleLinks: true,
html, greentext: true,
}, emoji: [],
})) html,
},
}),
)
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
}) })
it('replaces mention with mentionsline', () => { it('replaces mention with mentionsline', () => {
const html = p(makeMention('John'), ' how are you doing today?') const html = p(makeMention('John'), ' how are you doing today?')
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: true, props: {
greentext: true, attentions,
emoji: [], handleLinks: true,
html, greentext: true,
}, emoji: [],
})) html,
},
}),
)
expect(wrapper.html().replaceAll('\n', '')).to.eql( expect(wrapper.html().replaceAll('\n', '')).to.eql(
compwrap(p(mentionsLine(1), ' how are you doing today?')), compwrap(p(mentionsLine(1), ' how are you doing today?')),
@ -93,15 +102,18 @@ describe('RichContent', () => {
), ),
].join('') ].join('')
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: true, props: {
greentext: true, attentions,
emoji: [], handleLinks: true,
html, greentext: true,
}, emoji: [],
})) html,
},
}),
)
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
}) })
@ -128,15 +140,18 @@ describe('RichContent', () => {
].join(''), ].join(''),
].join('\n') ].join('\n')
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: false, props: {
greentext: true, attentions,
emoji: [], handleLinks: false,
html, greentext: true,
}, emoji: [],
})) html,
},
}),
)
expect(wrapper.html()).to.eql(compwrap(strippedHtml)) expect(wrapper.html()).to.eql(compwrap(strippedHtml))
}) })
@ -148,15 +163,18 @@ describe('RichContent', () => {
'<span class="greentext">&gt;any year</span>', '<span class="greentext">&gt;any year</span>',
].join('\n') ].join('\n')
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: false, props: {
greentext: true, attentions,
emoji: [], handleLinks: false,
html, greentext: true,
}, emoji: [],
})) html,
},
}),
)
expect(wrapper.html()).to.eql(compwrap(expected)) 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', () => { it('Does not add greentext and cyantext if setting is set to false', () => {
const html = ['&gt;preordering videogames', '&gt;any year'].join('\n') const html = ['&gt;preordering videogames', '&gt;any year'].join('\n')
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: false, props: {
greentext: false, attentions,
emoji: [], handleLinks: false,
html, greentext: false,
}, emoji: [],
})) html,
},
}),
)
expect(wrapper.html()).to.eql(compwrap(html)) expect(wrapper.html()).to.eql(compwrap(html))
}) })
@ -184,15 +205,18 @@ describe('RichContent', () => {
'<anonymous-stub shortcode="spurdo" islocal="true" class="emoji img" src="about:blank" title=":spurdo:" alt=":spurdo:"></anonymous-stub>', '<anonymous-stub shortcode="spurdo" islocal="true" class="emoji img" src="about:blank" title=":spurdo:" alt=":spurdo:"></anonymous-stub>',
) )
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: false, props: {
greentext: false, attentions,
emoji: [{ url: 'about:blank', shortcode: 'spurdo' }], handleLinks: false,
html, greentext: false,
}, emoji: [{ url: 'about:blank', shortcode: 'spurdo' }],
})) html,
},
}),
)
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
}) })
@ -200,15 +224,18 @@ describe('RichContent', () => {
it("Doesn't add nonexistent emoji to post", () => { it("Doesn't add nonexistent emoji to post", () => {
const html = p('Lol :lol:') const html = p('Lol :lol:')
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: false, props: {
greentext: false, attentions,
emoji: [], handleLinks: false,
html, greentext: false,
}, emoji: [],
})) html,
},
}),
)
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(html)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(html))
}) })
@ -227,15 +254,18 @@ describe('RichContent', () => {
'<span class="greentext">&gt;quote</span>', '<span class="greentext">&gt;quote</span>',
].join('\n') ].join('\n')
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: true, props: {
greentext: true, attentions,
emoji: [], handleLinks: true,
html, greentext: true,
}, emoji: [],
})) html,
},
}),
)
expect(wrapper.html()).to.eql(compwrap(expected)) expect(wrapper.html()).to.eql(compwrap(expected))
}) })
@ -249,15 +279,18 @@ describe('RichContent', () => {
].join('<br>') ].join('<br>')
const expected = ['Bruh', 'Bruh', mentionsLine(3), 'Bruh'].join('<br>') const expected = ['Bruh', 'Bruh', mentionsLine(3), 'Bruh'].join('<br>')
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: true, props: {
greentext: true, attentions,
emoji: [], handleLinks: true,
html, greentext: true,
}, emoji: [],
})) html,
},
}),
)
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
}) })
@ -284,15 +317,18 @@ describe('RichContent', () => {
' </p>', ' </p>',
].join('') ].join('')
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: true, props: {
greentext: true, attentions,
emoji: [], handleLinks: true,
html, greentext: true,
}, emoji: [],
})) html,
},
}),
)
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
}) })
@ -330,15 +366,18 @@ describe('RichContent', () => {
p('Testing'), p('Testing'),
].join('') ].join('')
const wrapper = mount(RichContent, mountOpts({ const wrapper = mount(
props: { RichContent,
attentions, mountOpts({
handleLinks: true, props: {
greentext: true, attentions,
emoji: [], handleLinks: true,
html, greentext: true,
}, emoji: [],
})) html,
},
}),
)
expect( expect(
wrapper wrapper
@ -402,15 +441,18 @@ describe('RichContent', () => {
'Testing', 'Testing',
].join('') ].join('')
const wrapper = mount(RichContent, mountOpts({ const wrapper = mount(
props: { RichContent,
attentions, mountOpts({
handleLinks: true, props: {
greentext: true, attentions,
emoji: [], handleLinks: true,
html, greentext: true,
}, emoji: [],
})) html,
},
}),
)
expect( expect(
wrapper wrapper
@ -450,15 +492,18 @@ describe('RichContent', () => {
'</p>', '</p>',
].join('') ].join('')
const wrapper = shallowMount(RichContent, mountOpts({ const wrapper = shallowMount(
props: { RichContent,
attentions, mountOpts({
handleLinks: true, props: {
greentext: true, attentions,
emoji: [], handleLinks: true,
html, greentext: true,
}, emoji: [],
})) html,
},
}),
)
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected)) expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
}) })
@ -495,13 +540,16 @@ describe('RichContent', () => {
const ptest = (handleLinks, vhtml) => { const ptest = (handleLinks, vhtml) => {
const t0 = performance.now() const t0 = performance.now()
const wrapper = mount(TestComponent, mountOpts({ const wrapper = mount(
props: { TestComponent,
attentions, mountOpts({
handleLinks, props: {
vhtml, attentions,
}, handleLinks,
})) vhtml,
},
}),
)
const t1 = performance.now() const t1 = performance.now()

View file

@ -1,8 +1,8 @@
import { setActivePinia } from 'pinia'
import { createTestingPinia } from '@pinia/testing' 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 { 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' import * as NotificationUtils from 'src/services/notification_utils/notification_utils.js'

View file

@ -85,14 +85,6 @@ const mockStatusNotification = ({
from_profile: user, from_profile: user,
}) })
const DEFAULT_OPTIONS = (method = 'POST') => ({
method,
credentials: 'same-origin',
headers: {
Accept: 'application/json',
},
})
describe('Notifications store', () => { describe('Notifications store', () => {
beforeEach(() => { beforeEach(() => {
vi.useFakeTimers() vi.useFakeTimers()
@ -328,7 +320,6 @@ describe('Notifications store', () => {
vi.stubGlobal('fetch', mockFetch) vi.stubGlobal('fetch', mockFetch)
const store = useNotificationsStore() const store = useNotificationsStore()
const mockedNotification = mockStatusNotification()
store.addNewNotifications({ store.addNewNotifications({
timestamp: 1337, timestamp: 1337,
@ -366,7 +357,6 @@ describe('Notifications store', () => {
vi.stubGlobal('fetch', mockFetch) vi.stubGlobal('fetch', mockFetch)
const store = useNotificationsStore() const store = useNotificationsStore()
const mockedNotification = mockStatusNotification()
// FormData is weird to test // FormData is weird to test
store.addNewNotifications({ store.addNewNotifications({