fix tests

This commit is contained in:
Henry Jameson 2026-03-25 15:38:31 +02:00
commit ff621d9d80
12 changed files with 78 additions and 63 deletions

View file

@ -1,8 +1,6 @@
import { cloneDeep } from 'lodash'
import { createPinia, setActivePinia } from 'pinia'
import { CURRENT_UPDATE_COUNTER } from 'src/components/update_notification/update_notification.js'
import {
_getAllFlags,
_getRecentData,
@ -75,7 +73,7 @@ describe('The SyncConfig store', () => {
_version: VERSION,
flagStorage: {
...defaultState.flagStorage,
updateCounter: CURRENT_UPDATE_COUNTER,
updateCounter: 1,
},
prefsStorage: {
...defaultState.prefsStorage,
@ -85,7 +83,7 @@ describe('The SyncConfig store', () => {
expect(store.flagStorage).to.eql({
...defaultState.flagStorage,
updateCounter: CURRENT_UPDATE_COUNTER,
updateCounter: 1,
})
})
@ -118,7 +116,7 @@ describe('The SyncConfig store', () => {
_version: VERSION,
flagStorage: {
...defaultState.flagStorage,
updateCounter: CURRENT_UPDATE_COUNTER,
updateCounter: 1,
},
prefsStorage: {
...defaultState.prefsStorage,

View file

@ -3,7 +3,7 @@ import { createPinia, setActivePinia } from 'pinia'
import {
_getRecentData,
_mergePrefs,
_mergeHighlights,
_moveItemInArray,
useUserHighlightStore,
} from 'src/stores/user_highlight.js'
@ -11,6 +11,15 @@ import {
describe('The UserHighlight store', () => {
beforeEach(() => {
setActivePinia(createPinia())
window.vuex = {
state: {
users: {
currentUser: {
fqn: 'foo@bar.tld',
},
},
},
}
})
describe('mutations', () => {
@ -20,23 +29,23 @@ describe('The UserHighlight store', () => {
storage: {},
}
it('should initialize storage if none present', () => {
it('should initialize storage if none present', async () => {
const store = useUserHighlightStore()
store.initUserHighlight({ ...user })
await store.initUserHighlight({ ...user })
expect(store.cache._timestamp).to.be.a('number')
expect(store.cache.highlight).to.eql({ _journal: [] })
})
it('should initialize storage for new users if none present', () => {
it('should initialize storage for new users if none present', async () => {
const store = useUserHighlightStore()
store.initUserHighlight({ ...user, created_at: new Date() })
await store.initUserHighlight({ ...user, created_at: new Date() })
expect(store.cache._timestamp).to.be.a('number')
expect(store.cache.highlight).to.eql({ _journal: [] })
})
it('should use remote version if local missing', () => {
it('should use remote version if local missing', async () => {
const store = useUserHighlightStore()
store.initUserHighlight(store, user)
await store.initUserHighlight(store, user)
expect(store.cache._timestamp).to.be.a('number')
})
})
@ -161,10 +170,10 @@ describe('The UserHighlight store', () => {
})
})
describe('_mergePrefs', () => {
describe('_mergeHighlights', () => {
it('should prefer recent and apply journal to it', () => {
expect(
_mergePrefs(
_mergeHighlights(
// RECENT
{
highlight: {
@ -227,7 +236,7 @@ describe('The UserHighlight store', () => {
it('should work with objects', () => {
expect(
_mergePrefs(
_mergeHighlights(
// RECENT
{
highlight: { 'a@test.xyz': { type: 'foo' } },
@ -268,7 +277,7 @@ describe('The UserHighlight store', () => {
it('should work with unset', () => {
expect(
_mergePrefs(
_mergeHighlights(
// RECENT
{
highlight: { 'a@test.xyz': { type: 'foo' } },