-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reload page after a consent gets revoked (#817)
* feat: reload page after a cookie gets revoked * fix: remove any types * test: cookiebar reload behavior * chore: readability --------- Co-authored-by: Maximilian Röll <[email protected]>
- Loading branch information
1 parent
2bf6bbe
commit 4bb70d6
Showing
5 changed files
with
88 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
apps/web/composables/useReadCookieBar/__tests__/useReadCookieBar.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { mockNuxtImport } from '@nuxt/test-utils/runtime'; | ||
import { useReadCookieBar } from '../useReadCookieBar'; | ||
|
||
const { useCookie } = vi.hoisted(() => ({ | ||
useCookie: vi.fn().mockReturnValue({}), | ||
})); | ||
|
||
const { useRouter } = vi.hoisted(() => ({ | ||
useRouter: vi.fn().mockReturnValue({ | ||
go: vi.fn(), | ||
}), | ||
})); | ||
|
||
mockNuxtImport('useRouter', () => useRouter); | ||
mockNuxtImport('useCookie', () => useCookie); | ||
|
||
|
||
describe('useReadCookieBar', () => { | ||
|
||
describe('setConsent', () => { | ||
beforeEach(() => { | ||
useCookie.mockImplementation(() => ({ | ||
value: { | ||
'CookieBar.functional.label': { | ||
'CookieBar.functional.cookies.payPal.name': true, | ||
'CookieBar.functional.cookies.scriptDemo.name': true, | ||
} | ||
}, | ||
})); | ||
}); | ||
|
||
it('should reload the page if a consent cookie is revoked', () => { | ||
const { setConsent, initializeCookies, data } = useReadCookieBar(); | ||
const RouterGoSpy = vi.fn(); | ||
|
||
useRouter.mockReturnValue({ | ||
go: RouterGoSpy, | ||
}); | ||
|
||
initializeCookies(); | ||
|
||
data.value.groups[2].cookies[1].accepted = false; | ||
setConsent(); | ||
|
||
expect(RouterGoSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should not reload the page if a consent cookie is accepted', () => { | ||
const { setConsent, initializeCookies } = useReadCookieBar(); | ||
const RouterGoSpy = vi.fn(); | ||
|
||
useRouter.mockReturnValue({ | ||
go: RouterGoSpy, | ||
}); | ||
|
||
initializeCookies(); | ||
setConsent(); | ||
|
||
expect(RouterGoSpy).toHaveBeenCalledTimes(0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters