koel/resources/assets/js/stores/userStore.spec.ts

29 lines
870 B
TypeScript
Raw Normal View History

2022-05-15 14:57:28 +00:00
import UnitTestCase from '@/__tests__/UnitTestCase'
import data from '@/__tests__/blobs/data'
import { expect, it } from 'vitest'
import { userStore } from '@/stores/userStore'
const { users, currentUser } = data
new class extends UnitTestCase {
protected beforeEach () {
2022-06-10 10:47:46 +00:00
super.beforeEach(() => userStore.init(currentUser))
2022-05-15 14:57:28 +00:00
}
protected test () {
it('sets data state', () => {
expect(userStore.state.users).toEqual(users)
expect(userStore.state.current).toEqual(currentUser)
})
it('returns all users', () => expect(userStore.all).toEqual(users))
it('gets a user by ID', () => expect(userStore.byId(1)).toEqual(users[0]))
it('gets the current user', () => expect(userStore.current.id).toBe(1))
it('sets the current user', () => {
userStore.current = users[1]
expect(userStore.current.id).toBe(2)
})
}
}