fix tests
This commit is contained in:
parent
080a2b00ba
commit
25d0d16dbb
10 changed files with 203 additions and 204 deletions
|
|
@ -8,7 +8,7 @@ import { useInstanceStore } from 'src/stores/instance.js'
|
|||
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
|
||||
import { useUsersStore } from 'src/stores/users.js'
|
||||
|
||||
export default (store) => {
|
||||
export default () => {
|
||||
const validateAuthenticatedRoute = (to, from, next) => {
|
||||
if (useUsersStore().currentUser) {
|
||||
next()
|
||||
|
|
|
|||
|
|
@ -571,9 +571,7 @@ const PostStatusForm = {
|
|||
},
|
||||
|
||||
// Global stuff
|
||||
currentUser() {
|
||||
return useUsersStore().currentUser
|
||||
},
|
||||
...mapState(useUsersStore, ['currentUser']),
|
||||
...mapState(useMergedConfigStore, ['mergedConfig']),
|
||||
...mapState(useInterfaceStore, {
|
||||
mobileLayout: (store) => store.mobileLayout,
|
||||
|
|
|
|||
|
|
@ -119,9 +119,7 @@ export const useNotificationsStore = defineStore('notifications', {
|
|||
addNewNotifications(result, older) {
|
||||
const { timestamp, data } = result
|
||||
|
||||
const notifications = older
|
||||
? data
|
||||
: [...data].reverse()
|
||||
const notifications = older ? data : [...data].reverse()
|
||||
|
||||
useUsersStore().addNewUsers({
|
||||
timestamp,
|
||||
|
|
@ -199,7 +197,9 @@ export const useNotificationsStore = defineStore('notifications', {
|
|||
|
||||
maybeShowNotification(
|
||||
useMergedConfigStore().mergedConfig.notificationVisibility,
|
||||
Object.values(useSyncConfigStore().prefsStorage.simple.muteFilters ?? {}),
|
||||
Object.values(
|
||||
useSyncConfigStore().prefsStorage.simple.muteFilters ?? {},
|
||||
),
|
||||
notification,
|
||||
useI18nStore().i18n,
|
||||
)
|
||||
|
|
@ -275,7 +275,8 @@ export const useNotificationsStore = defineStore('notifications', {
|
|||
wipeStatuses(ids) {
|
||||
const set = new Set(ids)
|
||||
this.data.forEach((notification) => {
|
||||
const status = isStatusNotification(notification.type) && notification.status
|
||||
const status =
|
||||
isStatusNotification(notification.type) && notification.status
|
||||
if (status && set.has(status.id)) {
|
||||
this.idStore.delete(notification.id)
|
||||
}
|
||||
|
|
|
|||
1
test/fixtures/setup_test.js
vendored
1
test/fixtures/setup_test.js
vendored
|
|
@ -26,7 +26,6 @@ const getDefaultOpts = ({
|
|||
global: {
|
||||
plugins: [
|
||||
applyAfterStore(makeMockStore(), afterStore),
|
||||
createTestingPinia(),
|
||||
VueVirtualScroller,
|
||||
createRouter({
|
||||
history: createMemoryHistory(),
|
||||
|
|
|
|||
|
|
@ -7,16 +7,10 @@ import { createStore } from 'vuex'
|
|||
|
||||
import routes from 'src/boot/routes'
|
||||
|
||||
const store = createStore({
|
||||
state: {
|
||||
instance: {},
|
||||
},
|
||||
})
|
||||
|
||||
describe('routes', () => {
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: routes(store),
|
||||
routes: routes(),
|
||||
})
|
||||
|
||||
it('root path', async () => {
|
||||
|
|
@ -24,12 +18,9 @@ describe('routes', () => {
|
|||
|
||||
const matchedComponents = router.currentRoute.value.matched
|
||||
|
||||
expect(
|
||||
Object.hasOwn(
|
||||
matchedComponents[0].components.default.components,
|
||||
'Timeline',
|
||||
),
|
||||
).to.eql(true)
|
||||
expect(matchedComponents[0].components.default.__file).to.contain(
|
||||
'/timeline.vue',
|
||||
)
|
||||
})
|
||||
|
||||
it("user's profile", async () => {
|
||||
|
|
@ -38,7 +29,7 @@ describe('routes', () => {
|
|||
const matchedComponents = router.currentRoute.value.matched
|
||||
|
||||
expect(matchedComponents[0].components.default.__file).to.contain(
|
||||
'user_profile.vue',
|
||||
'/user_profile.vue',
|
||||
)
|
||||
})
|
||||
|
||||
|
|
@ -48,7 +39,7 @@ describe('routes', () => {
|
|||
const matchedComponents = router.currentRoute.value.matched
|
||||
|
||||
expect(matchedComponents[0].components.default.__file).to.contain(
|
||||
'user_profile.vue',
|
||||
'/user_profile.vue',
|
||||
)
|
||||
})
|
||||
|
||||
|
|
@ -57,7 +48,7 @@ describe('routes', () => {
|
|||
|
||||
const matchedComponents = router.currentRoute.value.matched
|
||||
expect(matchedComponents[0].components.default.__file).to.contain(
|
||||
'lists.vue',
|
||||
'/lists.vue',
|
||||
)
|
||||
})
|
||||
|
||||
|
|
@ -67,7 +58,7 @@ describe('routes', () => {
|
|||
const matchedComponents = router.currentRoute.value.matched
|
||||
|
||||
expect(matchedComponents[0].components.default.__file).to.contain(
|
||||
'lists_timeline.vue',
|
||||
'/timeline.vue',
|
||||
)
|
||||
})
|
||||
|
||||
|
|
@ -77,7 +68,7 @@ describe('routes', () => {
|
|||
const matchedComponents = router.currentRoute.value.matched
|
||||
|
||||
expect(matchedComponents[0].components.default.__file).to.contain(
|
||||
'lists_edit.vue',
|
||||
'/lists_edit.vue',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ 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'
|
||||
|
|
@ -34,13 +35,20 @@ const saveManually = async (wrapper) => {
|
|||
|
||||
const waitSaveTime = 4000
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
const currentUser = {
|
||||
id: 'current-user',
|
||||
default_scope: 'public',
|
||||
locked: false,
|
||||
}
|
||||
|
||||
describe('Draft saving', () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createTestingPinia())
|
||||
useUsersStore().currentUser = currentUser
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
autoSaveOrNot(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import { vi } from 'vitest'
|
||||
|
||||
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
|
||||
|
|
@ -33,24 +35,18 @@ const repliedStatus2 = {
|
|||
user: repliedUser,
|
||||
}
|
||||
|
||||
const replyMountOpts = (props) =>
|
||||
mountOpts({
|
||||
props,
|
||||
afterStore(store) {
|
||||
useUsersStore().currentUser = currentUser
|
||||
useStatusesStore().allStatuses = {
|
||||
[repliedStatus.id]: repliedStatus,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
describe('PostStatusForm', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
setActivePinia(createTestingPinia())
|
||||
useUsersStore().currentUser = currentUser
|
||||
useStatusesStore().allStatuses = new Map([
|
||||
[repliedStatus.id, repliedStatus],
|
||||
])
|
||||
})
|
||||
|
||||
it('Clean empty initial state', () => {
|
||||
const wrapper = mount(PostStatusForm, replyMountOpts())
|
||||
const wrapper = mount(PostStatusForm, mountOpts())
|
||||
|
||||
expect(wrapper.vm.statusType).to.equal('new')
|
||||
expect(wrapper.vm.newStatus.spoilerText).to.eql('')
|
||||
|
|
@ -59,7 +55,7 @@ describe('PostStatusForm', () => {
|
|||
})
|
||||
|
||||
it('Reset cleans form to pristine state equal to state form was when created', () => {
|
||||
const wrapper = mount(PostStatusForm, replyMountOpts())
|
||||
const wrapper = mount(PostStatusForm, mountOpts())
|
||||
|
||||
const initial = { ...wrapper.vm.newStatus }
|
||||
wrapper.vm.clearStatus()
|
||||
|
|
@ -70,8 +66,10 @@ describe('PostStatusForm', () => {
|
|||
it('Initializes a reply form', () => {
|
||||
const wrapper = mount(
|
||||
PostStatusForm,
|
||||
replyMountOpts({
|
||||
repliedStatus: repliedStatus,
|
||||
mountOpts({
|
||||
props: {
|
||||
repliedStatus: repliedStatus,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -93,8 +91,10 @@ describe('PostStatusForm', () => {
|
|||
it('Copies scope and subject line, disables quoting for locked posts', () => {
|
||||
const wrapper = mount(
|
||||
PostStatusForm,
|
||||
replyMountOpts({
|
||||
repliedStatus: repliedStatus2,
|
||||
mountOpts({
|
||||
props: {
|
||||
repliedStatus: repliedStatus2,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -123,8 +123,10 @@ describe('PostStatusForm', () => {
|
|||
|
||||
it('Forces direct mode when replying to a DM, mastodon style subject handling', () => {
|
||||
// We need to initialize pinia first which is happening here...
|
||||
const options = replyMountOpts({
|
||||
repliedStatus: { ...repliedStatus2, visibility: 'direct' },
|
||||
const options = mountOpts({
|
||||
props: {
|
||||
repliedStatus: { ...repliedStatus2, visibility: 'direct' },
|
||||
},
|
||||
})
|
||||
|
||||
// ...set our settings...
|
||||
|
|
@ -152,10 +154,12 @@ describe('PostStatusForm', () => {
|
|||
it('Sets status to statusText without mentions if mentions line is enabled', () => {
|
||||
const wrapper = mount(
|
||||
PostStatusForm,
|
||||
replyMountOpts({
|
||||
repliedStatus: repliedStatus2,
|
||||
statusText: 'testing',
|
||||
mentionsLine: true,
|
||||
mountOpts({
|
||||
props: {
|
||||
repliedStatus: repliedStatus2,
|
||||
statusText: 'testing',
|
||||
mentionsLine: true,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -168,8 +172,10 @@ describe('PostStatusForm', () => {
|
|||
it('Sets mention when asked for it', () => {
|
||||
const wrapper = mount(
|
||||
PostStatusForm,
|
||||
replyMountOpts({
|
||||
profileMention: repliedUser,
|
||||
mountOpts({
|
||||
props: {
|
||||
profileMention: repliedUser,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -182,8 +188,10 @@ describe('PostStatusForm', () => {
|
|||
it('Initializes quote when reply/quote toggled to quote', () => {
|
||||
const wrapper = mount(
|
||||
PostStatusForm,
|
||||
replyMountOpts({
|
||||
repliedStatus: repliedStatus2,
|
||||
mountOpts({
|
||||
props: {
|
||||
repliedStatus: repliedStatus2,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -198,8 +206,10 @@ describe('PostStatusForm', () => {
|
|||
it('Resets quote when reply/quote toggled to reply', () => {
|
||||
const wrapper = mount(
|
||||
PostStatusForm,
|
||||
replyMountOpts({
|
||||
repliedStatus: repliedStatus2,
|
||||
mountOpts({
|
||||
props: {
|
||||
repliedStatus: repliedStatus2,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -215,8 +225,10 @@ describe('PostStatusForm', () => {
|
|||
it('Initializes and reset quote when toggling quote attachment', () => {
|
||||
const wrapper = mount(
|
||||
PostStatusForm,
|
||||
replyMountOpts({
|
||||
repliedStatus: repliedStatus2,
|
||||
mountOpts({
|
||||
props: {
|
||||
repliedStatus: repliedStatus2,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -236,17 +248,19 @@ describe('PostStatusForm', () => {
|
|||
it('Status editing', () => {
|
||||
const wrapper = mount(
|
||||
PostStatusForm,
|
||||
replyMountOpts({
|
||||
statusId: 'edited',
|
||||
statusText: 'text',
|
||||
statusSubject: 'heading',
|
||||
statusIsSensitive: true,
|
||||
statusPoll: {},
|
||||
statusQuote: {},
|
||||
statusFiles: [],
|
||||
statusMediaDescriptions: {},
|
||||
statusVisibility: 'unlisted',
|
||||
statusContentType: 'text/markdown',
|
||||
mountOpts({
|
||||
props: {
|
||||
statusId: 'edited',
|
||||
statusText: 'text',
|
||||
statusSubject: 'heading',
|
||||
statusIsSensitive: true,
|
||||
statusPoll: {},
|
||||
statusQuote: {},
|
||||
statusFiles: [],
|
||||
statusMediaDescriptions: {},
|
||||
statusVisibility: 'unlisted',
|
||||
statusContentType: 'text/markdown',
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
@ -266,7 +280,7 @@ describe('PostStatusForm', () => {
|
|||
|
||||
it('Posting should reset idempotency key', async () => {
|
||||
vi.setSystemTime(new Date(2027, 1, 1, 13))
|
||||
const wrapper = mount(PostStatusForm, replyMountOpts())
|
||||
const wrapper = mount(PostStatusForm, mountOpts())
|
||||
const oldIdempotency = wrapper.vm.idempotencyKey
|
||||
|
||||
vi.setSystemTime(new Date(2028, 1, 1, 13))
|
||||
|
|
@ -280,7 +294,7 @@ describe('PostStatusForm', () => {
|
|||
// TODO Probably better to separate attachment upload/manipulation into its own component?
|
||||
// we need to upload-on-submit for compression setting anyway
|
||||
it('Attachments manipulations (moving, adding, removing)', () => {
|
||||
const wrapper = mount(PostStatusForm, replyMountOpts())
|
||||
const wrapper = mount(PostStatusForm, mountOpts())
|
||||
|
||||
const i1 = { id: '1', url: 'a' }
|
||||
const i2 = { id: '2', url: 'b' }
|
||||
|
|
@ -310,7 +324,7 @@ describe('PostStatusForm', () => {
|
|||
})
|
||||
|
||||
it('Attachment descriptions', () => {
|
||||
const wrapper = mount(PostStatusForm, replyMountOpts())
|
||||
const wrapper = mount(PostStatusForm, mountOpts())
|
||||
|
||||
const i1 = { id: '1', url: 'a' }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +1,11 @@
|
|||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import { mount, shallowMount } from '@vue/test-utils'
|
||||
import { mountOpts } from '../../../fixtures/setup_test'
|
||||
|
||||
import RichContent from 'src/components/rich_content/rich_content.jsx'
|
||||
|
||||
const attentions = []
|
||||
const global = {
|
||||
mocks: {
|
||||
$store: {
|
||||
state: {},
|
||||
getters: {
|
||||
mergedConfig: () => ({
|
||||
mentionLinkShowTooltip: true,
|
||||
}),
|
||||
findUserByUrl: () => null,
|
||||
},
|
||||
},
|
||||
},
|
||||
stubs: {
|
||||
FAIcon: true,
|
||||
},
|
||||
}
|
||||
|
||||
const makeMention = (who, noClass) => {
|
||||
attentions.push({ statusnet_profile_url: `https://fake.tld/@${who}` })
|
||||
|
|
@ -37,10 +24,13 @@ const mentionsLine = (times) =>
|
|||
].join('')
|
||||
|
||||
describe('RichContent', () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createTestingPinia())
|
||||
})
|
||||
|
||||
it('renders simple post without exploding', () => {
|
||||
const html = p('Hello world!')
|
||||
const wrapper = shallowMount(RichContent, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: true,
|
||||
|
|
@ -48,7 +38,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(html))
|
||||
})
|
||||
|
|
@ -56,8 +46,7 @@ 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, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: true,
|
||||
|
|
@ -65,15 +54,14 @@ describe('RichContent', () => {
|
|||
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, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: true,
|
||||
|
|
@ -81,7 +69,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(wrapper.html().replaceAll('\n', '')).to.eql(
|
||||
compwrap(p(mentionsLine(1), ' how are you doing today?')),
|
||||
|
|
@ -105,8 +93,7 @@ describe('RichContent', () => {
|
|||
),
|
||||
].join('')
|
||||
|
||||
const wrapper = shallowMount(RichContent, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: true,
|
||||
|
|
@ -114,7 +101,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
|
||||
})
|
||||
|
|
@ -141,8 +128,7 @@ describe('RichContent', () => {
|
|||
].join(''),
|
||||
].join('\n')
|
||||
|
||||
const wrapper = shallowMount(RichContent, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: false,
|
||||
|
|
@ -150,7 +136,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(wrapper.html()).to.eql(compwrap(strippedHtml))
|
||||
})
|
||||
|
|
@ -162,8 +148,7 @@ describe('RichContent', () => {
|
|||
'<span class="greentext">>any year</span>',
|
||||
].join('\n')
|
||||
|
||||
const wrapper = shallowMount(RichContent, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: false,
|
||||
|
|
@ -171,7 +156,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(wrapper.html()).to.eql(compwrap(expected))
|
||||
})
|
||||
|
|
@ -179,8 +164,7 @@ 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, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: false,
|
||||
|
|
@ -188,7 +172,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(wrapper.html()).to.eql(compwrap(html))
|
||||
})
|
||||
|
|
@ -200,8 +184,7 @@ describe('RichContent', () => {
|
|||
'<anonymous-stub shortcode="spurdo" islocal="true" class="emoji img" src="about:blank" title=":spurdo:" alt=":spurdo:"></anonymous-stub>',
|
||||
)
|
||||
|
||||
const wrapper = shallowMount(RichContent, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: false,
|
||||
|
|
@ -209,7 +192,7 @@ describe('RichContent', () => {
|
|||
emoji: [{ url: 'about:blank', shortcode: 'spurdo' }],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
|
||||
})
|
||||
|
|
@ -217,8 +200,7 @@ describe('RichContent', () => {
|
|||
it("Doesn't add nonexistent emoji to post", () => {
|
||||
const html = p('Lol :lol:')
|
||||
|
||||
const wrapper = shallowMount(RichContent, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: false,
|
||||
|
|
@ -226,7 +208,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(html))
|
||||
})
|
||||
|
|
@ -245,8 +227,7 @@ describe('RichContent', () => {
|
|||
'<span class="greentext">>quote</span>',
|
||||
].join('\n')
|
||||
|
||||
const wrapper = shallowMount(RichContent, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: true,
|
||||
|
|
@ -254,7 +235,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(wrapper.html()).to.eql(compwrap(expected))
|
||||
})
|
||||
|
|
@ -268,8 +249,7 @@ describe('RichContent', () => {
|
|||
].join('<br>')
|
||||
const expected = ['Bruh', 'Bruh', mentionsLine(3), 'Bruh'].join('<br>')
|
||||
|
||||
const wrapper = shallowMount(RichContent, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: true,
|
||||
|
|
@ -277,7 +257,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
|
||||
})
|
||||
|
|
@ -304,8 +284,7 @@ describe('RichContent', () => {
|
|||
' </p>',
|
||||
].join('')
|
||||
|
||||
const wrapper = shallowMount(RichContent, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: true,
|
||||
|
|
@ -313,7 +292,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
|
||||
})
|
||||
|
|
@ -351,8 +330,7 @@ describe('RichContent', () => {
|
|||
p('Testing'),
|
||||
].join('')
|
||||
|
||||
const wrapper = mount(RichContent, {
|
||||
global,
|
||||
const wrapper = mount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: true,
|
||||
|
|
@ -360,7 +338,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
|
@ -424,8 +402,7 @@ describe('RichContent', () => {
|
|||
'Testing',
|
||||
].join('')
|
||||
|
||||
const wrapper = mount(RichContent, {
|
||||
global,
|
||||
const wrapper = mount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: true,
|
||||
|
|
@ -433,7 +410,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(
|
||||
wrapper
|
||||
|
|
@ -473,8 +450,7 @@ describe('RichContent', () => {
|
|||
'</p>',
|
||||
].join('')
|
||||
|
||||
const wrapper = shallowMount(RichContent, {
|
||||
global,
|
||||
const wrapper = shallowMount(RichContent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks: true,
|
||||
|
|
@ -482,7 +458,7 @@ describe('RichContent', () => {
|
|||
emoji: [],
|
||||
html,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
expect(wrapper.html().replaceAll('\n', '')).to.eql(compwrap(expected))
|
||||
})
|
||||
|
|
@ -519,14 +495,13 @@ describe('RichContent', () => {
|
|||
const ptest = (handleLinks, vhtml) => {
|
||||
const t0 = performance.now()
|
||||
|
||||
const wrapper = mount(TestComponent, {
|
||||
global,
|
||||
const wrapper = mount(TestComponent, mountOpts({
|
||||
props: {
|
||||
attentions,
|
||||
handleLinks,
|
||||
vhtml,
|
||||
},
|
||||
})
|
||||
}))
|
||||
|
||||
const t1 = performance.now()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
import { setActivePinia } from 'pinia'
|
||||
import { createTestingPinia } from '@pinia/testing'
|
||||
|
||||
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
||||
import { useNotificationsStore } from 'src/stores/notifications.js'
|
||||
|
||||
import * as NotificationUtils from 'src/services/notification_utils/notification_utils.js'
|
||||
|
||||
describe('NotificationUtils', () => {
|
||||
beforeEach(() => {
|
||||
const store = useSyncConfigStore(createTestingPinia())
|
||||
store.mergedConfig = {
|
||||
setActivePinia(createTestingPinia())
|
||||
useSyncConfigStore().mergedConfig = {
|
||||
notificationVisibility: {
|
||||
likes: true,
|
||||
repeats: true,
|
||||
|
|
@ -16,31 +18,26 @@ describe('NotificationUtils', () => {
|
|||
}
|
||||
})
|
||||
|
||||
describe('filteredNotificationsFromStore', () => {
|
||||
describe('filteredNotifications', () => {
|
||||
it('should return sorted notifications with configured types', () => {
|
||||
const store = {
|
||||
state: {
|
||||
notifications: {
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
action: { id: '1' },
|
||||
type: 'like',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
action: { id: '2' },
|
||||
type: 'mention',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
action: { id: '3' },
|
||||
type: 'repeat',
|
||||
},
|
||||
],
|
||||
},
|
||||
useNotificationsStore().data = [
|
||||
{
|
||||
id: 1,
|
||||
action: { id: '1' },
|
||||
type: 'like',
|
||||
},
|
||||
}
|
||||
{
|
||||
id: 2,
|
||||
action: { id: '2' },
|
||||
type: 'mention',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
action: { id: '3' },
|
||||
type: 'repeat',
|
||||
},
|
||||
]
|
||||
|
||||
const expected = [
|
||||
{
|
||||
action: { id: '3' },
|
||||
|
|
@ -54,7 +51,7 @@ describe('NotificationUtils', () => {
|
|||
},
|
||||
]
|
||||
expect(
|
||||
NotificationUtils.filteredNotificationsFromStore(store, {
|
||||
NotificationUtils.filteredNotifications({
|
||||
mentions: false,
|
||||
likes: true,
|
||||
repeats: true,
|
||||
|
|
@ -63,26 +60,21 @@ describe('NotificationUtils', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('unseenNotificationsFromStore', () => {
|
||||
describe('unseenNotifications', () => {
|
||||
it('should return only notifications not marked as seen', () => {
|
||||
const store = {
|
||||
state: {
|
||||
notifications: {
|
||||
data: [
|
||||
{
|
||||
action: { id: '1' },
|
||||
type: 'like',
|
||||
seen: false,
|
||||
},
|
||||
{
|
||||
action: { id: '2' },
|
||||
type: 'mention',
|
||||
seen: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
useNotificationsStore().data = [
|
||||
{
|
||||
action: { id: '1' },
|
||||
type: 'like',
|
||||
seen: false,
|
||||
},
|
||||
}
|
||||
{
|
||||
action: { id: '2' },
|
||||
type: 'mention',
|
||||
seen: true,
|
||||
},
|
||||
]
|
||||
|
||||
const expected = [
|
||||
{
|
||||
action: { id: '1' },
|
||||
|
|
@ -91,7 +83,7 @@ describe('NotificationUtils', () => {
|
|||
},
|
||||
]
|
||||
expect(
|
||||
NotificationUtils.unseenNotificationsFromStore(store, {
|
||||
NotificationUtils.unseenNotifications({
|
||||
likes: true,
|
||||
repeats: true,
|
||||
mentions: false,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { setActivePinia } from 'pinia'
|
||||
|
||||
import { useNotificationsStore } from 'src/stores/notifications.js'
|
||||
import { useStatusesStore } from 'src/stores/statuses.js'
|
||||
import { useUsersStore } from 'src/stores/users.js'
|
||||
import { useReportsStore } from 'src/stores/reports.js'
|
||||
import { useStreamingStore } from 'src/stores/streaming.js'
|
||||
import { useI18nStore } from 'src/stores/i18n.js'
|
||||
import { useNotificationsStore } from 'src/stores/notifications.js'
|
||||
import { useReportsStore } from 'src/stores/reports.js'
|
||||
import { useStatusesStore } from 'src/stores/statuses.js'
|
||||
import { useStreamingStore } from 'src/stores/streaming.js'
|
||||
import { useUsersStore } from 'src/stores/users.js'
|
||||
|
||||
import * as USER_API from 'src/api/user.js'
|
||||
|
||||
|
|
@ -97,7 +97,11 @@ describe('Notifications store', () => {
|
|||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
setActivePinia(createTestingPinia({ stubActions: false }))
|
||||
useI18nStore().i18n = { t: () => { /* no-op */} }
|
||||
useI18nStore().i18n = {
|
||||
t: () => {
|
||||
/* no-op */
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
|
|
@ -209,13 +213,16 @@ describe('Notifications store', () => {
|
|||
],
|
||||
})
|
||||
|
||||
store.addNewNotifications({
|
||||
timestamp: 1,
|
||||
data: [
|
||||
mockStatusNotification({ id: '2' }),
|
||||
mockStatusNotification({ id: '1' }),
|
||||
],
|
||||
}, true)
|
||||
store.addNewNotifications(
|
||||
{
|
||||
timestamp: 1,
|
||||
data: [
|
||||
mockStatusNotification({ id: '2' }),
|
||||
mockStatusNotification({ id: '1' }),
|
||||
],
|
||||
},
|
||||
true,
|
||||
)
|
||||
|
||||
// must be ordered
|
||||
expect(store.data.map(({ id }) => id)).to.eql(['4', '3', '2', '1'])
|
||||
|
|
@ -236,13 +243,17 @@ describe('Notifications store', () => {
|
|||
|
||||
expect(mock).to.have.been.called
|
||||
expect(mock.mock.calls[0][0]).to.have.property('timestamp', 1337)
|
||||
expect(mock.mock.calls[0][0].data[0]).to.eql(mockedNotification.from_profile)
|
||||
expect(mock.mock.calls[0][0].data[0]).to.eql(
|
||||
mockedNotification.from_profile,
|
||||
)
|
||||
})
|
||||
|
||||
it('should update reportsStore', (notificationType) => {
|
||||
const store = useNotificationsStore()
|
||||
const mock = vi.spyOn(useReportsStore(), 'addReport')
|
||||
const mockedNotification = mockStatusNotification({ type: 'pleroma:report' })
|
||||
const mockedNotification = mockStatusNotification({
|
||||
type: 'pleroma:report',
|
||||
})
|
||||
mockedNotification.report = { data: '123' }
|
||||
|
||||
store.addNewNotifications({
|
||||
|
|
@ -264,7 +275,9 @@ describe('Notifications store', () => {
|
|||
const store = useNotificationsStore()
|
||||
const mock = vi.fn()
|
||||
useStatusesStore().addNewStatuses = mock
|
||||
const mockedNotification = mockStatusNotification({ type: notificationType })
|
||||
const mockedNotification = mockStatusNotification({
|
||||
type: notificationType,
|
||||
})
|
||||
|
||||
store.addNewNotifications({
|
||||
timestamp: 1337,
|
||||
|
|
@ -273,7 +286,9 @@ describe('Notifications store', () => {
|
|||
|
||||
expect(mock).to.have.been.called
|
||||
expect(mock.mock.calls[0][0]).to.have.property('timestamp', 1337)
|
||||
expect(mock.mock.calls[0][0].statuses[0]).to.eql(mockedNotification.status)
|
||||
expect(mock.mock.calls[0][0].statuses[0]).to.eql(
|
||||
mockedNotification.status,
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -284,8 +299,14 @@ describe('Notifications store', () => {
|
|||
store.addNewNotifications({
|
||||
timestamp: 1,
|
||||
data: [
|
||||
mockStatusNotification({ id: 'n2', status: mockStatus({ id: 's2' }) }),
|
||||
mockStatusNotification({ id: 'n1', status: mockStatus({ id: 's1' }) }),
|
||||
mockStatusNotification({
|
||||
id: 'n2',
|
||||
status: mockStatus({ id: 's2' }),
|
||||
}),
|
||||
mockStatusNotification({
|
||||
id: 'n1',
|
||||
status: mockStatus({ id: 's1' }),
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue