fix tests

This commit is contained in:
Henry Jameson 2026-02-10 21:29:48 +02:00
commit fd2986ea85
10 changed files with 199 additions and 197 deletions

View file

@ -63,6 +63,7 @@
"@babel/preset-env": "7.28.5", "@babel/preset-env": "7.28.5",
"@babel/register": "7.28.3", "@babel/register": "7.28.3",
"@biomejs/biome": "2.3.11", "@biomejs/biome": "2.3.11",
"@pinia/testing": "1.0.3",
"@ungap/event-target": "0.2.4", "@ungap/event-target": "0.2.4",
"@vitejs/plugin-vue": "^5.2.1", "@vitejs/plugin-vue": "^5.2.1",
"@vitejs/plugin-vue-jsx": "^4.1.1", "@vitejs/plugin-vue-jsx": "^4.1.1",

View file

@ -9,8 +9,6 @@ import genRandomSeed from '../../services/random_seed/random_seed.service.js'
import EmojiPicker from '../emoji_picker/emoji_picker.vue' import EmojiPicker from '../emoji_picker/emoji_picker.vue'
import UnicodeDomainIndicator from '../unicode_domain_indicator/unicode_domain_indicator.vue' import UnicodeDomainIndicator from '../unicode_domain_indicator/unicode_domain_indicator.vue'
import { useEmojiStore } from 'src/stores/emoji.js'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
import { faSmileBeam } from '@fortawesome/free-regular-svg-icons' import { faSmileBeam } from '@fortawesome/free-regular-svg-icons'
@ -133,7 +131,7 @@ const EmojiInput = {
}, },
computed: { computed: {
padEmoji() { padEmoji() {
return useEmojiStore().mergedConfig.padEmoji return this.$store.getters.mergedConfig.padEmoji
}, },
defaultCandidateIndex() { defaultCandidateIndex() {
return this.$store.getters.mergedConfig.autocompleteSelect ? 0 : -1 return this.$store.getters.mergedConfig.autocompleteSelect ? 0 : -1

View file

@ -20,8 +20,10 @@ export const getJsonOrError = async (response) => {
} }
export const createApp = (instance) => { export const createApp = (instance) => {
console.log('NAP', instance)
const url = `${instance}/api/v1/apps` const url = `${instance}/api/v1/apps`
const form = new window.FormData() const form = new window.FormData()
console.log(url)
form.append('client_name', 'PleromaFE') form.append('client_name', 'PleromaFE')
form.append('website', 'https://pleroma.social') form.append('website', 'https://pleroma.social')

View file

@ -83,6 +83,7 @@ export const useOAuthStore = defineStore('oauth', {
}, },
async getAppToken() { async getAppToken() {
const instance = useInstanceStore().server const instance = useInstanceStore().server
console.log(this.clientId)
const res = await getClientToken({ const res = await getClientToken({
clientId: this.clientId, clientId: this.clientId,
clientSecret: this.clientSecret, clientSecret: this.clientSecret,

View file

@ -1,3 +1,5 @@
import { createTestingPinia } from '@pinia/testing'
createTestingPinia()
import { createMemoryHistory, createRouter } from 'vue-router' import { createMemoryHistory, createRouter } from 'vue-router'
import { createStore } from 'vuex' import { createStore } from 'vuex'

View file

@ -1,5 +1,6 @@
import { flushPromises, mount } from '@vue/test-utils' import { flushPromises, mount } from '@vue/test-utils'
import { nextTick } from 'vue' import { nextTick } from 'vue'
import { createTestingPinia } from '@pinia/testing'
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'
@ -35,6 +36,8 @@ afterEach(() => {
}) })
describe('Draft saving', () => { describe('Draft saving', () => {
createTestingPinia()
autoSaveOrNot( autoSaveOrNot(
it, it,
'should save when the button is clicked', 'should save when the button is clicked',

View file

@ -1,6 +1,8 @@
import { shallowMount } from '@vue/test-utils' import { shallowMount } from '@vue/test-utils'
import vClickOutside from 'click-outside-vue3' import vClickOutside from 'click-outside-vue3'
import { h } from 'vue' import { h } from 'vue'
import { createTestingPinia } from '@pinia/testing'
createTestingPinia()
import EmojiInput from 'src/components/emoji_input/emoji_input.vue' import EmojiInput from 'src/components/emoji_input/emoji_input.vue'

View file

@ -3,6 +3,8 @@ import {
mutations, mutations,
prepareStatus, prepareStatus,
} from '../../../../src/modules/statuses.js' } from '../../../../src/modules/statuses.js'
import { createTestingPinia } from '@pinia/testing'
createTestingPinia()
const makeMockStatus = ({ id, text, type = 'status' }) => { const makeMockStatus = ({ id, text, type = 'status' }) => {
return { return {

View file

@ -1,7 +1,6 @@
import { HttpResponse, http } from 'msw' import { HttpResponse, http } from 'msw'
import { createPinia, setActivePinia } from 'pinia' import { setActivePinia, createPinia } from 'pinia'
import { createApp } from 'vue' import { createTestingPinia } from '@pinia/testing'
import { createStore } from 'vuex'
import { import {
authApis, authApis,
@ -10,34 +9,19 @@ import {
} from '/test/fixtures/mock_api.js' } from '/test/fixtures/mock_api.js'
import { useOAuthStore } from 'src/stores/oauth.js' import { useOAuthStore } from 'src/stores/oauth.js'
import { useInstanceStore } from 'src/stores/instance.js'
const test = injectMswToTest(authApis) const test = injectMswToTest(authApis)
const vuexStore = createStore({ describe('oauth store', () => {
modules: { beforeEach(() => {
instance: { setActivePinia(createTestingPinia({ stubActions: false }))
state: () => ({ server: testServer }), useInstanceStore().server = testServer
},
},
}) })
const app = createApp({})
app.use(vuexStore)
window.vuex = vuexStore
const getStore = (defaultStateInjection) => {
const pinia = createPinia().use(({ store }) => {
if (store.$id === 'oauth') {
store.$patch(defaultStateInjection)
}
})
app.use(pinia)
setActivePinia(pinia)
return useOAuthStore()
}
describe('createApp', () => { describe('createApp', () => {
test('it should use create an app and record client id and secret', async () => { test('it should use create an app and record client id and secret', async () => {
const store = getStore() const store = useOAuthStore()
const app = await store.createApp() const app = await store.createApp()
expect(store.clientId).to.eql('test-id') expect(store.clientId).to.eql('test-id')
expect(store.clientSecret).to.eql('test-secret') expect(store.clientSecret).to.eql('test-secret')
@ -52,7 +36,7 @@ describe('createApp', () => {
}), }),
) )
const store = getStore() const store = useOAuthStore()
const res = store.createApp() const res = store.createApp()
await expect(res).rejects.toThrowError('Throttled') await expect(res).rejects.toThrowError('Throttled')
expect(store.clientId).to.eql(false) expect(store.clientId).to.eql(false)
@ -62,7 +46,7 @@ describe('createApp', () => {
describe('ensureApp', () => { describe('ensureApp', () => {
test('it should create an app if it does not exist', async () => { test('it should create an app if it does not exist', async () => {
const store = getStore() const store = useOAuthStore()
const app = await store.ensureApp() const app = await store.ensureApp()
expect(store.clientId).to.eql('test-id') expect(store.clientId).to.eql('test-id')
expect(store.clientSecret).to.eql('test-secret') expect(store.clientSecret).to.eql('test-secret')
@ -77,10 +61,11 @@ describe('ensureApp', () => {
}), }),
) )
const store = getStore({
clientId: 'another-id', const store = useOAuthStore()
clientSecret: 'another-secret', store.clientId = 'another-id'
}) store.clientSecret = 'another-secret'
const app = await store.ensureApp() const app = await store.ensureApp()
expect(store.clientId).to.eql('another-id') expect(store.clientId).to.eql('another-id')
expect(store.clientSecret).to.eql('another-secret') expect(store.clientSecret).to.eql('another-secret')
@ -91,20 +76,20 @@ describe('ensureApp', () => {
describe('getAppToken', () => { describe('getAppToken', () => {
test('it should get app token and set it in state', async () => { test('it should get app token and set it in state', async () => {
const store = getStore({ const store = useOAuthStore()
clientId: 'test-id', store.clientId = 'test-id'
clientSecret: 'test-secret', store.clientSecret = 'test-secret'
})
const token = await store.getAppToken() const token = await store.getAppToken()
expect(token).to.eql('test-app-token') expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token') expect(store.appToken).to.eql('test-app-token')
}) })
test('it should throw and not set state if it cannot get app token', async () => { test('it should throw and not set state if it cannot get app token', async () => {
const store = getStore({ const store = useOAuthStore()
clientId: 'bad-id', store.clientId = 'bad-id'
clientSecret: 'bad-secret', store.clientSecret = 'bad-secret'
})
await expect(store.getAppToken()).rejects.toThrowError('400') await expect(store.getAppToken()).rejects.toThrowError('400')
expect(store.appToken).to.eql(false) expect(store.appToken).to.eql(false)
}) })
@ -112,16 +97,16 @@ describe('getAppToken', () => {
describe('ensureAppToken', () => { describe('ensureAppToken', () => {
test('it should work if the state is empty', async () => { test('it should work if the state is empty', async () => {
const store = getStore() const store = useOAuthStore()
const token = await store.ensureAppToken() const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token') expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token') expect(store.appToken).to.eql('test-app-token')
}) })
test('it should work if we already have a working token', async () => { test('it should work if we already have a working token', async () => {
const store = getStore({ const store = useOAuthStore()
appToken: 'also-good-app-token', store.appToken = 'also-good-app-token'
})
const token = await store.ensureAppToken() const token = await store.ensureAppToken()
expect(token).to.eql('also-good-app-token') expect(token).to.eql('also-good-app-token')
expect(store.appToken).to.eql('also-good-app-token') expect(store.appToken).to.eql('also-good-app-token')
@ -135,11 +120,11 @@ describe('ensureAppToken', () => {
return HttpResponse.text('Should not call this API', { status: 400 }) return HttpResponse.text('Should not call this API', { status: 400 })
}), }),
) )
const store = getStore({ const store = useOAuthStore()
appToken: 'bad-app-token', store.appToken = 'bad-app-token'
clientId: 'test-id', store.clientId = 'test-id'
clientSecret: 'test-secret', store.clientSecret = 'test-secret'
})
const token = await store.ensureAppToken() const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token') expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token') expect(store.appToken).to.eql('test-app-token')
@ -153,20 +138,20 @@ describe('ensureAppToken', () => {
return HttpResponse.text('Should not call this API', { status: 400 }) return HttpResponse.text('Should not call this API', { status: 400 })
}), }),
) )
const store = getStore({ const store = useOAuthStore()
clientId: 'test-id', store.clientId = 'test-id'
clientSecret: 'test-secret', store.clientSecret = 'test-secret'
})
const token = await store.ensureAppToken() const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token') expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token') expect(store.appToken).to.eql('test-app-token')
}) })
test('it should work if we have no token and bad app credentials', async () => { test('it should work if we have no token and bad app credentials', async () => {
const store = getStore({ const store = useOAuthStore()
clientId: 'bad-id', store.clientId = 'bad-id'
clientSecret: 'bad-secret', store.clientSecret = 'bad-secret'
})
const token = await store.ensureAppToken() const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token') expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token') expect(store.appToken).to.eql('test-app-token')
@ -175,11 +160,11 @@ describe('ensureAppToken', () => {
}) })
test('it should work if we have bad token and bad app credentials', async () => { test('it should work if we have bad token and bad app credentials', async () => {
const store = getStore({ const store = useOAuthStore()
appToken: 'bad-app-token', store.appToken = 'bad-app-token'
clientId: 'bad-id', store.clientId = 'bad-id'
clientSecret: 'bad-secret', store.clientSecret = 'bad-secret'
})
const token = await store.ensureAppToken() const token = await store.ensureAppToken()
expect(token).to.eql('test-app-token') expect(token).to.eql('test-app-token')
expect(store.appToken).to.eql('test-app-token') expect(store.appToken).to.eql('test-app-token')
@ -194,7 +179,7 @@ describe('ensureAppToken', () => {
}), }),
) )
const store = getStore() const store = useOAuthStore()
await expect(store.ensureAppToken()).rejects.toThrowError('Throttled') await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
}) })
@ -205,7 +190,8 @@ describe('ensureAppToken', () => {
}), }),
) )
const store = getStore() const store = useOAuthStore()
await expect(store.ensureAppToken()).rejects.toThrowError('Throttled') await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
}) })
}) })
})

View file

@ -2040,6 +2040,11 @@
"@parcel/watcher-win32-ia32" "2.5.1" "@parcel/watcher-win32-ia32" "2.5.1"
"@parcel/watcher-win32-x64" "2.5.1" "@parcel/watcher-win32-x64" "2.5.1"
"@pinia/testing@1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@pinia/testing/-/testing-1.0.3.tgz#62e0813a7a8ac735505422bb7a4e38eb86f815dc"
integrity sha512-g+qR49GNdI1Z8rZxKrQC3GN+LfnGTNf5Kk8Nz5Cz6mIGva5WRS+ffPXQfzhA0nu6TveWzPNYTjGl4nJqd3Cu9Q==
"@pkgjs/parseargs@^0.11.0": "@pkgjs/parseargs@^0.11.0":
version "0.11.0" version "0.11.0"
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33" resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"