From 154b56ce57cfbb49f7e1d5bf8755891b5196d8ba Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Fri, 6 Aug 2021 20:00:27 +0200 Subject: [PATCH] Test that if the saveLocale Method is called the mocked apollo call is send. --- .../src/components/LanguageSwitch.spec.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/frontend/src/components/LanguageSwitch.spec.js b/frontend/src/components/LanguageSwitch.spec.js index 14dc978ac..3fa8e51f9 100644 --- a/frontend/src/components/LanguageSwitch.spec.js +++ b/frontend/src/components/LanguageSwitch.spec.js @@ -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', + }, + }), + ) + }) + }) }) })