diff --git a/package.json b/package.json
index bdd1acfbe..20c01a0b3 100644
--- a/package.json
+++ b/package.json
@@ -63,6 +63,7 @@
"@babel/preset-env": "7.28.5",
"@babel/register": "7.28.3",
"@biomejs/biome": "2.3.11",
+ "@pinia/testing": "1.0.3",
"@ungap/event-target": "0.2.4",
"@vitejs/plugin-vue": "^5.2.1",
"@vitejs/plugin-vue-jsx": "^4.1.1",
diff --git a/src/components/emoji_input/emoji_input.js b/src/components/emoji_input/emoji_input.js
index 22631dc1d..24794640e 100644
--- a/src/components/emoji_input/emoji_input.js
+++ b/src/components/emoji_input/emoji_input.js
@@ -9,8 +9,6 @@ import genRandomSeed from '../../services/random_seed/random_seed.service.js'
import EmojiPicker from '../emoji_picker/emoji_picker.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 { faSmileBeam } from '@fortawesome/free-regular-svg-icons'
@@ -133,7 +131,7 @@ const EmojiInput = {
},
computed: {
padEmoji() {
- return useEmojiStore().mergedConfig.padEmoji
+ return this.$store.getters.mergedConfig.padEmoji
},
defaultCandidateIndex() {
return this.$store.getters.mergedConfig.autocompleteSelect ? 0 : -1
diff --git a/src/components/features_panel/features_panel.js b/src/components/features_panel/features_panel.js
index dc46f5e6f..106da1487 100644
--- a/src/components/features_panel/features_panel.js
+++ b/src/components/features_panel/features_panel.js
@@ -3,17 +3,18 @@ import { mapState } from 'pinia'
import fileSizeFormatService from '../../services/file_size_format/file_size_format.js'
import { useInstanceStore } from 'src/stores/instance.js'
+import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
const FeaturesPanel = {
computed: {
+ ...mapState(useInstanceCapabilitiesStore, [
+ 'shoutAvailable',
+ 'pleromaChatMessagesAvailable',
+ 'gopherAvailable',
+ 'suggestionsEnabled',
+ 'mediaProxyAvailable',
+ ]),
...mapState(useInstanceStore, {
- shout: (store) => store.shoutAvailable,
- pleromaChatMessages: (store) =>
- store.featureSet.pleromaChatMessagesAvailable,
- gopher: (store) => store.featureSet.gopherAvailable,
- whoToFollow: (store) => store.featureSet.suggestionsEnabled,
- mediaProxy: (store) => store.featureSet.mediaProxyAvailable,
- minimalScopesMode: (store) => store.prefsStorage.minimalScopesMode,
textlimit: (store) => store.limits.textlimit,
uploadlimit: (store) =>
fileSizeFormatService.fileSizeFormat(store.limits.uploadlimit),
diff --git a/src/components/features_panel/features_panel.vue b/src/components/features_panel/features_panel.vue
index d91ef1eff..4270436fa 100644
--- a/src/components/features_panel/features_panel.vue
+++ b/src/components/features_panel/features_panel.vue
@@ -8,19 +8,19 @@
- -
+
-
{{ $t('features_panel.shout') }}
- -
+
-
{{ $t('features_panel.pleroma_chat_messages') }}
- -
+
-
{{ $t('features_panel.gopher') }}
- -
+
-
{{ $t('features_panel.who_to_follow') }}
- -
+
-
{{ $t('features_panel.media_proxy') }}
- {{ $t('features_panel.scope_options') }}
diff --git a/src/modules/adminSettings.js b/src/modules/adminSettings.js
index 470c72b74..33cc8a595 100644
--- a/src/modules/adminSettings.js
+++ b/src/modules/adminSettings.js
@@ -107,6 +107,12 @@ const adminSettingsStorage = {
if (Array.isArray(value) && value.length > 0 && value[0].tuple) {
if (!preserveTuples) {
return value.reduce((acc, c) => {
+ if (c.tuple == null) {
+ return {
+ ...acc,
+ [c]: c,
+ }
+ }
return {
...acc,
[c.tuple[0]]: convert(c.tuple[1], preserveTuplesLv2),
diff --git a/src/services/new_api/oauth.js b/src/services/new_api/oauth.js
index b803e2146..ead2153a6 100644
--- a/src/services/new_api/oauth.js
+++ b/src/services/new_api/oauth.js
@@ -20,8 +20,10 @@ export const getJsonOrError = async (response) => {
}
export const createApp = (instance) => {
+ console.log('NAP', instance)
const url = `${instance}/api/v1/apps`
const form = new window.FormData()
+ console.log(url)
form.append('client_name', 'PleromaFE')
form.append('website', 'https://pleroma.social')
diff --git a/src/stores/oauth.js b/src/stores/oauth.js
index 2a79c2fa9..ef0f5ba35 100644
--- a/src/stores/oauth.js
+++ b/src/stores/oauth.js
@@ -83,6 +83,7 @@ export const useOAuthStore = defineStore('oauth', {
},
async getAppToken() {
const instance = useInstanceStore().server
+ console.log(this.clientId)
const res = await getClientToken({
clientId: this.clientId,
clientSecret: this.clientSecret,
diff --git a/test/unit/specs/boot/routes.spec.js b/test/unit/specs/boot/routes.spec.js
index ed6838d7e..8795ea04e 100644
--- a/test/unit/specs/boot/routes.spec.js
+++ b/test/unit/specs/boot/routes.spec.js
@@ -1,3 +1,5 @@
+import { createTestingPinia } from '@pinia/testing'
+ createTestingPinia()
import { createMemoryHistory, createRouter } from 'vue-router'
import { createStore } from 'vuex'
diff --git a/test/unit/specs/components/draft.spec.js b/test/unit/specs/components/draft.spec.js
index 2b9ade95d..eb35cb58f 100644
--- a/test/unit/specs/components/draft.spec.js
+++ b/test/unit/specs/components/draft.spec.js
@@ -1,5 +1,6 @@
import { flushPromises, mount } from '@vue/test-utils'
import { nextTick } from 'vue'
+import { createTestingPinia } from '@pinia/testing'
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
import { $t, mountOpts, waitForEvent } from '../../../fixtures/setup_test'
@@ -35,6 +36,8 @@ afterEach(() => {
})
describe('Draft saving', () => {
+ createTestingPinia()
+
autoSaveOrNot(
it,
'should save when the button is clicked',
diff --git a/test/unit/specs/components/emoji_input.spec.js b/test/unit/specs/components/emoji_input.spec.js
index 80f5a9c74..83ffd13d2 100644
--- a/test/unit/specs/components/emoji_input.spec.js
+++ b/test/unit/specs/components/emoji_input.spec.js
@@ -1,6 +1,8 @@
import { shallowMount } from '@vue/test-utils'
import vClickOutside from 'click-outside-vue3'
import { h } from 'vue'
+import { createTestingPinia } from '@pinia/testing'
+ createTestingPinia()
import EmojiInput from 'src/components/emoji_input/emoji_input.vue'
diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js
index 379b7795d..3d1027ad4 100644
--- a/test/unit/specs/modules/statuses.spec.js
+++ b/test/unit/specs/modules/statuses.spec.js
@@ -3,6 +3,8 @@ import {
mutations,
prepareStatus,
} from '../../../../src/modules/statuses.js'
+import { createTestingPinia } from '@pinia/testing'
+ createTestingPinia()
const makeMockStatus = ({ id, text, type = 'status' }) => {
return {
diff --git a/test/unit/specs/stores/oauth.spec.js b/test/unit/specs/stores/oauth.spec.js
index 54a489479..977b15432 100644
--- a/test/unit/specs/stores/oauth.spec.js
+++ b/test/unit/specs/stores/oauth.spec.js
@@ -1,7 +1,6 @@
import { HttpResponse, http } from 'msw'
-import { createPinia, setActivePinia } from 'pinia'
-import { createApp } from 'vue'
-import { createStore } from 'vuex'
+import { setActivePinia, createPinia } from 'pinia'
+import { createTestingPinia } from '@pinia/testing'
import {
authApis,
@@ -10,202 +9,189 @@ import {
} from '/test/fixtures/mock_api.js'
import { useOAuthStore } from 'src/stores/oauth.js'
+import { useInstanceStore } from 'src/stores/instance.js'
const test = injectMswToTest(authApis)
-const vuexStore = createStore({
- modules: {
- instance: {
- state: () => ({ 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', () => {
- test('it should use create an app and record client id and secret', async () => {
- const store = getStore()
- const app = await store.createApp()
- expect(store.clientId).to.eql('test-id')
- expect(store.clientSecret).to.eql('test-secret')
- expect(app.clientId).to.eql('test-id')
- expect(app.clientSecret).to.eql('test-secret')
+describe('oauth store', () => {
+ beforeEach(() => {
+ setActivePinia(createTestingPinia({ stubActions: false }))
+ useInstanceStore().server = testServer
})
- test('it should throw and not update if failed', async ({ worker }) => {
- worker.use(
- http.post(`${testServer}/api/v1/apps`, () => {
- return HttpResponse.text('Throttled', { status: 429 })
- }),
- )
+ describe('createApp', () => {
+ test('it should use create an app and record client id and secret', async () => {
+ const store = useOAuthStore()
+ const app = await store.createApp()
+ expect(store.clientId).to.eql('test-id')
+ expect(store.clientSecret).to.eql('test-secret')
+ expect(app.clientId).to.eql('test-id')
+ expect(app.clientSecret).to.eql('test-secret')
+ })
- const store = getStore()
- const res = store.createApp()
- await expect(res).rejects.toThrowError('Throttled')
- expect(store.clientId).to.eql(false)
- expect(store.clientSecret).to.eql(false)
- })
-})
-
-describe('ensureApp', () => {
- test('it should create an app if it does not exist', async () => {
- const store = getStore()
- const app = await store.ensureApp()
- expect(store.clientId).to.eql('test-id')
- expect(store.clientSecret).to.eql('test-secret')
- expect(app.clientId).to.eql('test-id')
- expect(app.clientSecret).to.eql('test-secret')
- })
-
- test('it should not create an app if it exists', async ({ worker }) => {
- worker.use(
- http.post(`${testServer}/api/v1/apps`, () => {
- return HttpResponse.text('Should not call this API', { status: 400 })
- }),
- )
-
- const store = getStore({
- clientId: 'another-id',
- clientSecret: 'another-secret',
- })
- const app = await store.ensureApp()
- expect(store.clientId).to.eql('another-id')
- expect(store.clientSecret).to.eql('another-secret')
- expect(app.clientId).to.eql('another-id')
- expect(app.clientSecret).to.eql('another-secret')
- })
-})
-
-describe('getAppToken', () => {
- test('it should get app token and set it in state', async () => {
- const store = getStore({
- clientId: 'test-id',
- clientSecret: 'test-secret',
- })
- const token = await store.getAppToken()
- expect(token).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 () => {
- const store = getStore({
- clientId: 'bad-id',
- clientSecret: 'bad-secret',
- })
- await expect(store.getAppToken()).rejects.toThrowError('400')
- expect(store.appToken).to.eql(false)
- })
-})
-
-describe('ensureAppToken', () => {
- test('it should work if the state is empty', async () => {
- const store = getStore()
- const token = await store.ensureAppToken()
- expect(token).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 () => {
- const store = getStore({
- appToken: 'also-good-app-token',
- })
- const token = await store.ensureAppToken()
- expect(token).to.eql('also-good-app-token')
- expect(store.appToken).to.eql('also-good-app-token')
- })
-
- test('it should work if we have a bad token but good app credentials', async ({
- worker,
- }) => {
- worker.use(
- http.post(`${testServer}/api/v1/apps`, () => {
- return HttpResponse.text('Should not call this API', { status: 400 })
- }),
- )
- const store = getStore({
- appToken: 'bad-app-token',
- clientId: 'test-id',
- clientSecret: 'test-secret',
- })
- const token = await store.ensureAppToken()
- expect(token).to.eql('test-app-token')
- expect(store.appToken).to.eql('test-app-token')
- })
-
- test('it should work if we have no token but good app credentials', async ({
- worker,
- }) => {
- worker.use(
- http.post(`${testServer}/api/v1/apps`, () => {
- return HttpResponse.text('Should not call this API', { status: 400 })
- }),
- )
- const store = getStore({
- clientId: 'test-id',
- clientSecret: 'test-secret',
- })
- const token = await store.ensureAppToken()
- expect(token).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 () => {
- const store = getStore({
- clientId: 'bad-id',
- clientSecret: 'bad-secret',
- })
- const token = await store.ensureAppToken()
- expect(token).to.eql('test-app-token')
- expect(store.appToken).to.eql('test-app-token')
- expect(store.clientId).to.eql('test-id')
- expect(store.clientSecret).to.eql('test-secret')
- })
-
- test('it should work if we have bad token and bad app credentials', async () => {
- const store = getStore({
- appToken: 'bad-app-token',
- clientId: 'bad-id',
- clientSecret: 'bad-secret',
- })
- const token = await store.ensureAppToken()
- expect(token).to.eql('test-app-token')
- expect(store.appToken).to.eql('test-app-token')
- expect(store.clientId).to.eql('test-id')
- expect(store.clientSecret).to.eql('test-secret')
- })
-
- test('it should throw if we cannot create an app', async ({ worker }) => {
- worker.use(
- http.post(`${testServer}/api/v1/apps`, () => {
- return HttpResponse.text('Throttled', { status: 429 })
- }),
- )
-
- const store = getStore()
- await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
- })
-
- test('it should throw if we cannot obtain app token', async ({ worker }) => {
- worker.use(
- http.post(`${testServer}/oauth/token`, () => {
- return HttpResponse.text('Throttled', { status: 429 })
- }),
- )
-
- const store = getStore()
- await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
+ test('it should throw and not update if failed', async ({ worker }) => {
+ worker.use(
+ http.post(`${testServer}/api/v1/apps`, () => {
+ return HttpResponse.text('Throttled', { status: 429 })
+ }),
+ )
+
+ const store = useOAuthStore()
+ const res = store.createApp()
+ await expect(res).rejects.toThrowError('Throttled')
+ expect(store.clientId).to.eql(false)
+ expect(store.clientSecret).to.eql(false)
+ })
+ })
+
+ describe('ensureApp', () => {
+ test('it should create an app if it does not exist', async () => {
+ const store = useOAuthStore()
+ const app = await store.ensureApp()
+ expect(store.clientId).to.eql('test-id')
+ expect(store.clientSecret).to.eql('test-secret')
+ expect(app.clientId).to.eql('test-id')
+ expect(app.clientSecret).to.eql('test-secret')
+ })
+
+ test('it should not create an app if it exists', async ({ worker }) => {
+ worker.use(
+ http.post(`${testServer}/api/v1/apps`, () => {
+ return HttpResponse.text('Should not call this API', { status: 400 })
+ }),
+ )
+
+
+ const store = useOAuthStore()
+ store.clientId = 'another-id'
+ store.clientSecret = 'another-secret'
+
+ const app = await store.ensureApp()
+ expect(store.clientId).to.eql('another-id')
+ expect(store.clientSecret).to.eql('another-secret')
+ expect(app.clientId).to.eql('another-id')
+ expect(app.clientSecret).to.eql('another-secret')
+ })
+ })
+
+ describe('getAppToken', () => {
+ test('it should get app token and set it in state', async () => {
+ const store = useOAuthStore()
+ store.clientId = 'test-id'
+ store.clientSecret = 'test-secret'
+
+ const token = await store.getAppToken()
+ expect(token).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 () => {
+ const store = useOAuthStore()
+ store.clientId = 'bad-id'
+ store.clientSecret = 'bad-secret'
+
+ await expect(store.getAppToken()).rejects.toThrowError('400')
+ expect(store.appToken).to.eql(false)
+ })
+ })
+
+ describe('ensureAppToken', () => {
+ test('it should work if the state is empty', async () => {
+ const store = useOAuthStore()
+ const token = await store.ensureAppToken()
+ expect(token).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 () => {
+ const store = useOAuthStore()
+ store.appToken = 'also-good-app-token'
+
+ const token = await store.ensureAppToken()
+ expect(token).to.eql('also-good-app-token')
+ expect(store.appToken).to.eql('also-good-app-token')
+ })
+
+ test('it should work if we have a bad token but good app credentials', async ({
+ worker,
+ }) => {
+ worker.use(
+ http.post(`${testServer}/api/v1/apps`, () => {
+ return HttpResponse.text('Should not call this API', { status: 400 })
+ }),
+ )
+ const store = useOAuthStore()
+ store.appToken = 'bad-app-token'
+ store.clientId = 'test-id'
+ store.clientSecret = 'test-secret'
+
+ const token = await store.ensureAppToken()
+ expect(token).to.eql('test-app-token')
+ expect(store.appToken).to.eql('test-app-token')
+ })
+
+ test('it should work if we have no token but good app credentials', async ({
+ worker,
+ }) => {
+ worker.use(
+ http.post(`${testServer}/api/v1/apps`, () => {
+ return HttpResponse.text('Should not call this API', { status: 400 })
+ }),
+ )
+ const store = useOAuthStore()
+ store.clientId = 'test-id'
+ store.clientSecret = 'test-secret'
+
+ const token = await store.ensureAppToken()
+ expect(token).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 () => {
+ const store = useOAuthStore()
+ store.clientId = 'bad-id'
+ store.clientSecret = 'bad-secret'
+
+ const token = await store.ensureAppToken()
+ expect(token).to.eql('test-app-token')
+ expect(store.appToken).to.eql('test-app-token')
+ expect(store.clientId).to.eql('test-id')
+ expect(store.clientSecret).to.eql('test-secret')
+ })
+
+ test('it should work if we have bad token and bad app credentials', async () => {
+ const store = useOAuthStore()
+ store.appToken = 'bad-app-token'
+ store.clientId = 'bad-id'
+ store.clientSecret = 'bad-secret'
+
+ const token = await store.ensureAppToken()
+ expect(token).to.eql('test-app-token')
+ expect(store.appToken).to.eql('test-app-token')
+ expect(store.clientId).to.eql('test-id')
+ expect(store.clientSecret).to.eql('test-secret')
+ })
+
+ test('it should throw if we cannot create an app', async ({ worker }) => {
+ worker.use(
+ http.post(`${testServer}/api/v1/apps`, () => {
+ return HttpResponse.text('Throttled', { status: 429 })
+ }),
+ )
+
+ const store = useOAuthStore()
+ await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
+ })
+
+ test('it should throw if we cannot obtain app token', async ({ worker }) => {
+ worker.use(
+ http.post(`${testServer}/oauth/token`, () => {
+ return HttpResponse.text('Throttled', { status: 429 })
+ }),
+ )
+
+ const store = useOAuthStore()
+ await expect(store.ensureAppToken()).rejects.toThrowError('Throttled')
+ })
})
})
diff --git a/yarn.lock b/yarn.lock
index d053a6f51..54d81f139 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2040,6 +2040,11 @@
"@parcel/watcher-win32-ia32" "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":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"