mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Add test cases for LocaleSwitch
- if there is a currentUser then update their locale in the database, otherwise, do not.
This commit is contained in:
parent
821ea6d671
commit
5c12914e02
@ -2,26 +2,43 @@ import { mount, createLocalVue } from '@vue/test-utils'
|
||||
import Styleguide from '@human-connection/styleguide'
|
||||
import VTooltip from 'v-tooltip'
|
||||
import LocaleSwitch from './LocaleSwitch.vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
const localVue = createLocalVue()
|
||||
|
||||
localVue.use(Styleguide)
|
||||
localVue.use(VTooltip)
|
||||
localVue.use(Vuex)
|
||||
|
||||
describe('LocaleSwitch.vue', () => {
|
||||
let wrapper
|
||||
let mocks
|
||||
let computed
|
||||
let deutschLanguageItem
|
||||
let wrapper, mocks, computed, deutschLanguageItem, getters
|
||||
|
||||
beforeEach(() => {
|
||||
mocks = {
|
||||
$i18n: {
|
||||
locale: () => 'de',
|
||||
set: jest.fn(),
|
||||
locale: () => 'en',
|
||||
set: jest.fn(locale => locale),
|
||||
},
|
||||
$t: jest.fn(),
|
||||
$toast: {
|
||||
success: jest.fn(a => a),
|
||||
error: jest.fn(a => a),
|
||||
},
|
||||
setPlaceholderText: jest.fn(),
|
||||
$apollo: {
|
||||
mutate: jest
|
||||
.fn()
|
||||
.mockResolvedValueOnce({
|
||||
data: {
|
||||
UpdateUser: {
|
||||
locale: 'de',
|
||||
},
|
||||
},
|
||||
})
|
||||
.mockRejectedValueOnce({
|
||||
message: 'Please log in!',
|
||||
}),
|
||||
},
|
||||
}
|
||||
computed = {
|
||||
current: () => {
|
||||
@ -40,12 +57,21 @@ describe('LocaleSwitch.vue', () => {
|
||||
]
|
||||
},
|
||||
}
|
||||
getters = {
|
||||
'auth/user': () => {
|
||||
return { id: 'u35' }
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
describe('mount', () => {
|
||||
const Wrapper = () => {
|
||||
return mount(LocaleSwitch, { mocks, localVue, computed })
|
||||
}
|
||||
const Wrapper = () => {
|
||||
const store = new Vuex.Store({
|
||||
getters,
|
||||
})
|
||||
return mount(LocaleSwitch, { mocks, localVue, computed, store })
|
||||
}
|
||||
|
||||
describe('with current user', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = Wrapper()
|
||||
wrapper.find('.locale-menu').trigger('click')
|
||||
@ -53,8 +79,30 @@ describe('LocaleSwitch.vue', () => {
|
||||
deutschLanguageItem.trigger('click')
|
||||
})
|
||||
|
||||
it("changes a user's locale", () => {
|
||||
it("sets a user's locale", () => {
|
||||
expect(mocks.$i18n.set).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it("updates the user's locale in the database", () => {
|
||||
expect(mocks.$apollo.mutate).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('no current user', () => {
|
||||
beforeEach(() => {
|
||||
getters = {
|
||||
'auth/user': () => {
|
||||
return null
|
||||
},
|
||||
}
|
||||
wrapper = Wrapper()
|
||||
wrapper.find('.locale-menu').trigger('click')
|
||||
deutschLanguageItem = wrapper.findAll('li').at(1)
|
||||
deutschLanguageItem.trigger('click')
|
||||
})
|
||||
|
||||
it('does not send a UpdateUser mutation', () => {
|
||||
expect(mocks.$apollo.mutate).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user