Test that if the saveLocale Method is called the mocked apollo call is send.

This commit is contained in:
Hannes Heine 2021-08-06 20:00:27 +02:00
parent ac91c59a59
commit 154b56ce57

View File

@ -3,6 +3,16 @@ import LanguageSwitch from './LanguageSwitch'
const localVue = global.localVue
const updateUserInfosQueryMock = jest.fn().mockResolvedValue({
data: {
updateUserInfos: {
sessionId: 1234,
email: 'he@ho.he',
locale: 'de',
},
},
})
describe('LanguageSwitch', () => {
let wrapper
@ -20,6 +30,9 @@ describe('LanguageSwitch', () => {
$i18n: {
locale: 'en',
},
$apollo: {
query: updateUserInfosQueryMock,
},
}
const Wrapper = () => {
@ -91,5 +104,33 @@ describe('LanguageSwitch', () => {
})
})
})
describe('calls the API', () => {
it("with locale 'en'", () => {
wrapper.vm.saveLocale('en')
expect(updateUserInfosQueryMock).toBeCalledWith(
expect.objectContaining({
variables: {
sessionId: 1234,
email: 'he@ho.he',
locale: 'en',
},
}),
)
})
it("with locale 'de'", () => {
wrapper.vm.saveLocale('de')
expect(updateUserInfosQueryMock).toBeCalledWith(
expect.objectContaining({
variables: {
sessionId: 1234,
email: 'he@ho.he',
locale: 'de',
},
}),
)
})
})
})
})