pleroma-fe/test/unit/specs/modules/users.spec.js

65 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-11-30 17:29:44 +00:00
import { cloneDeep } from 'lodash'
import { defaultState, mutations, getters } from '../../../../src/modules/users.js'
2016-11-30 17:29:44 +00:00
describe('The users module', () => {
describe('mutations', () => {
it('adds new users to the set, merging in new information for old users', () => {
const state = cloneDeep(defaultState)
const user = { id: '1', name: 'Guy' }
const modUser = { id: '1', name: 'Dude' }
mutations.addNewUsers(state, [user])
expect(state.users).to.have.length(1)
expect(state.users).to.eql([user])
mutations.addNewUsers(state, [modUser])
expect(state.users).to.have.length(1)
expect(state.users).to.eql([user])
expect(state.users[0].name).to.eql('Dude')
})
it('sets a mute bit on users', () => {
const state = cloneDeep(defaultState)
const user = { id: '1', name: 'Guy' }
2017-02-13 22:22:32 +00:00
mutations.addNewUsers(state, [user])
mutations.setMuted(state, {user, muted: true})
2017-02-13 22:22:32 +00:00
expect(user.muted).to.eql(true)
2017-02-13 22:22:32 +00:00
mutations.setMuted(state, {user, muted: false})
2017-02-13 22:22:32 +00:00
expect(user.muted).to.eql(false)
})
})
describe('findUser', () => {
it('returns user with matching screen_name', () => {
const user = { screen_name: 'Guy', id: '1' }
const state = {
usersObject: {
1: user,
Guy: user
}
}
const name = 'Guy'
const expected = { screen_name: 'Guy', id: '1' }
expect(getters.findUser(state)(name)).to.eql(expected)
})
2019-01-28 19:21:11 +00:00
it('returns user with matching id', () => {
const user = { screen_name: 'Guy', id: '1' }
const state = {
usersObject: {
1: user,
Guy: user
}
}
const id = '1'
const expected = { screen_name: 'Guy', id: '1' }
expect(getters.findUser(state)(id)).to.eql(expected)
})
2017-02-13 22:22:32 +00:00
})
2016-11-30 17:29:44 +00:00
})