cleanup
This commit is contained in:
parent
1aff1ac4e7
commit
c611788e77
19 changed files with 59 additions and 122 deletions
18
test/fixtures/setup_test.js
vendored
18
test/fixtures/setup_test.js
vendored
|
|
@ -5,26 +5,15 @@ import VueVirtualScroller from 'vue-virtual-scroller'
|
|||
import RichContent from 'src/components/rich_content/rich_content.jsx'
|
||||
import Status from 'src/components/status/status.vue'
|
||||
import StillImage from 'src/components/still-image/still-image.vue'
|
||||
import makeMockStore from './mock_store'
|
||||
|
||||
import routes from 'src/boot/routes'
|
||||
|
||||
export const $t = (msg) => msg
|
||||
const $i18n = { t: (msg) => msg }
|
||||
|
||||
const applyAfterStore = (store, afterStore) => {
|
||||
afterStore(store)
|
||||
return store
|
||||
}
|
||||
|
||||
const getDefaultOpts = ({
|
||||
afterStore = () => {
|
||||
/* no-op */
|
||||
},
|
||||
} = {}) => ({
|
||||
const getDefaultOpts = () => ({
|
||||
global: {
|
||||
plugins: [
|
||||
applyAfterStore(makeMockStore(), afterStore),
|
||||
VueVirtualScroller,
|
||||
createRouter({
|
||||
history: createMemoryHistory(),
|
||||
|
|
@ -87,9 +76,8 @@ const customBehaviors = () => {
|
|||
|
||||
config.plugins.VueWrapper.install(customBehaviors)
|
||||
|
||||
export const mountOpts = (allOpts = {}) => {
|
||||
const { afterStore, ...opts } = allOpts
|
||||
const defaultOpts = getDefaultOpts({ afterStore })
|
||||
export const mountOpts = (opts = {}) => {
|
||||
const defaultOpts = getDefaultOpts()
|
||||
const mergedOpts = {
|
||||
...opts,
|
||||
global: {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import { $t, mountOpts, waitForEvent } from 'test/fixtures/setup_test.js'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
|
||||
import { $t, mountOpts, waitForEvent } from '../../../fixtures/setup_test'
|
||||
|
||||
import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
||||
import { useUsersStore } from 'src/stores/users.js'
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import { mountOpts } from 'test/fixtures/setup_test.js'
|
||||
import { vi } from 'vitest'
|
||||
|
||||
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
|
||||
import { mountOpts } from '../../../fixtures/setup_test'
|
||||
|
||||
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
|
||||
import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { createTestingPinia } from '@pinia/testing'
|
||||
import { mount, shallowMount } from '@vue/test-utils'
|
||||
import { setActivePinia } from 'pinia'
|
||||
import { mountOpts } from 'test/fixtures/setup_test.js'
|
||||
|
||||
import RichContent from 'src/components/rich_content/rich_content.jsx'
|
||||
import { mountOpts } from '../../../fixtures/setup_test'
|
||||
|
||||
const attentions = []
|
||||
|
||||
|
|
|
|||
|
|
@ -37,10 +37,7 @@ describe('The SyncConfig store', () => {
|
|||
|
||||
it('should initialize storage if none present', async () => {
|
||||
const store = useSyncConfigStore()
|
||||
// PushSyncConfig is very simple but uses vuex to push data
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
await store.initSyncConfig({ ...user })
|
||||
expect(store.cache._version).to.eql(VERSION)
|
||||
expect(store.cache._timestamp).to.be.a('number')
|
||||
|
|
@ -50,10 +47,7 @@ describe('The SyncConfig store', () => {
|
|||
|
||||
it('should initialize storage with proper flags for new users if none present', async () => {
|
||||
const store = useSyncConfigStore()
|
||||
// PushSyncConfig is very simple but uses vuex to push data
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
await store.initSyncConfig({ ...user, created_at: new Date() })
|
||||
expect(store.cache._version).to.eql(VERSION)
|
||||
expect(store.cache._timestamp).to.be.a('number')
|
||||
|
|
@ -63,10 +57,7 @@ describe('The SyncConfig store', () => {
|
|||
|
||||
it('should merge flags even if remote timestamp is older', async () => {
|
||||
const store = useSyncConfigStore()
|
||||
// PushSyncConfig is very simple but uses vuex to push data
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
store.cache = {
|
||||
_timestamp: Date.now(),
|
||||
_version: VERSION,
|
||||
|
|
@ -96,10 +87,7 @@ describe('The SyncConfig store', () => {
|
|||
|
||||
it('should trim journal to 500 entries', async () => {
|
||||
const store = useSyncConfigStore()
|
||||
// PushSyncConfig is very simple but uses vuex to push data
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
store.cache = {
|
||||
_timestamp: Date.now(),
|
||||
_version: VERSION,
|
||||
|
|
@ -138,10 +126,7 @@ describe('The SyncConfig store', () => {
|
|||
it('should reset local timestamp to remote if contents are the same', async () => {
|
||||
const store = useSyncConfigStore()
|
||||
store.cache = null
|
||||
// PushSyncConfig is very simple but uses vuex to push data
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
|
||||
await store.initSyncConfig({
|
||||
...user,
|
||||
|
|
@ -161,10 +146,7 @@ describe('The SyncConfig store', () => {
|
|||
|
||||
it('should use remote version if local missing', async () => {
|
||||
const store = useSyncConfigStore()
|
||||
// PushSyncConfig is very simple but uses vuex to push data
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
await store.initSyncConfig(store, user)
|
||||
expect(store.cache._version).to.eql(VERSION)
|
||||
expect(store.cache._timestamp).to.be.a('number')
|
||||
|
|
@ -208,9 +190,7 @@ describe('The SyncConfig store', () => {
|
|||
})
|
||||
vi.spyOn(storage, 'setItem').mockResolvedValue()
|
||||
const store = useSyncConfigStore()
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
|
||||
await store.initSyncConfig({
|
||||
...user,
|
||||
|
|
@ -240,9 +220,7 @@ describe('The SyncConfig store', () => {
|
|||
})
|
||||
vi.spyOn(storage, 'setItem').mockResolvedValue()
|
||||
const store = useSyncConfigStore()
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
|
||||
await store.initSyncConfig({
|
||||
...user,
|
||||
|
|
@ -282,9 +260,7 @@ describe('The SyncConfig store', () => {
|
|||
vi.spyOn(storage, 'setItem').mockResolvedValue()
|
||||
const store = useSyncConfigStore()
|
||||
const setPreference = vi.spyOn(store, 'setPreference')
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
|
||||
await store.initSyncConfig({
|
||||
...user,
|
||||
|
|
@ -318,9 +294,7 @@ describe('The SyncConfig store', () => {
|
|||
})
|
||||
vi.spyOn(storage, 'setItem').mockResolvedValue()
|
||||
const store = useSyncConfigStore()
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
|
||||
await store.initSyncConfig({
|
||||
...user,
|
||||
|
|
@ -357,9 +331,7 @@ describe('The SyncConfig store', () => {
|
|||
const localStore = useLocalConfigStore()
|
||||
localStore.set({ path: 'fontInterface', value: 'Current interface' })
|
||||
const store = useSyncConfigStore()
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
|
||||
await store.initSyncConfig({ ...user })
|
||||
|
||||
|
|
@ -372,10 +344,7 @@ describe('The SyncConfig store', () => {
|
|||
describe('setPreference', () => {
|
||||
it('should set preference and update journal log accordingly', () => {
|
||||
const store = useSyncConfigStore()
|
||||
// PushSyncConfig is very simple but uses vuex to push data
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
store.setPreference({ path: 'simple.palette', value: '1' })
|
||||
expect(store.prefsStorage.simple.palette).to.eql('1')
|
||||
expect(store.prefsStorage._journal).to.have.length(1)
|
||||
|
|
@ -390,10 +359,7 @@ describe('The SyncConfig store', () => {
|
|||
|
||||
it('should keep journal to a minimum', () => {
|
||||
const store = useSyncConfigStore()
|
||||
// PushSyncConfig is very simple but uses vuex to push data
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
store.setPreference({ path: 'simple.palette', value: 1 })
|
||||
store.setPreference({ path: 'simple.palette', value: 2 })
|
||||
store.addCollectionPreference({ path: 'collections.palette', value: 2 })
|
||||
|
|
@ -423,10 +389,7 @@ describe('The SyncConfig store', () => {
|
|||
|
||||
it('should remove duplicate entries from journal', () => {
|
||||
const store = useSyncConfigStore()
|
||||
// PushSyncConfig is very simple but uses vuex to push data
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
store.setPreference({ path: 'simple.palette', value: 1 })
|
||||
store.setPreference({ path: 'simple.palette', value: 1 })
|
||||
store.addCollectionPreference({ path: 'collections.palette', value: 2 })
|
||||
|
|
@ -440,10 +403,7 @@ describe('The SyncConfig store', () => {
|
|||
// TODO We need a proper test for object-based stores
|
||||
it.skip('should remove depth = 3 set/unset entries from journal', () => {
|
||||
const store = useSyncConfigStore()
|
||||
// PushSyncConfig is very simple but uses vuex to push data
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
store.setPreference({ path: 'simple.fontInput', value: 'test' })
|
||||
store.unsetPreference({ path: 'simple.fontInput' })
|
||||
store.updateCache(store, { username: 'test' })
|
||||
|
|
@ -455,10 +415,7 @@ describe('The SyncConfig store', () => {
|
|||
|
||||
it('should not allow unsetting depth <= 2', () => {
|
||||
const store = useSyncConfigStore()
|
||||
// PushSyncConfig is very simple but uses vuex to push data
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
store.setPreference({ path: 'simple.object.foo', value: 1 })
|
||||
expect(() => store.unsetPreference({ path: 'simple' })).to.throw()
|
||||
expect(() =>
|
||||
|
|
@ -468,10 +425,7 @@ describe('The SyncConfig store', () => {
|
|||
|
||||
it('should not allow (un)setting depth > 3', () => {
|
||||
const store = useSyncConfigStore()
|
||||
// PushSyncConfig is very simple but uses vuex to push data
|
||||
store.pushSyncConfig = () => {
|
||||
/* no-op */
|
||||
}
|
||||
store.pushSyncConfig = vi.fn()
|
||||
store.setPreference({ path: 'simple.object', value: {} })
|
||||
expect(() =>
|
||||
store.setPreference({ path: 'simple.object.lv3', value: 1 }),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue