-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(add-consent): add missing tests for consent
- Loading branch information
Showing
9 changed files
with
303 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { getAllCheckboxes } from './get-all-checkboxes'; | ||
|
||
declare global { | ||
interface Window { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
zaraz: any; | ||
} | ||
} | ||
|
||
let windowObj: Window & typeof globalThis; | ||
|
||
beforeAll(() => { | ||
windowObj = window; | ||
}); | ||
|
||
afterAll(() => { | ||
window = windowObj; | ||
}); | ||
|
||
describe('getAllCheckboxes()', () => { | ||
it('should return all checkboxes from zaraz consent', () => { | ||
const checkboxesMock = { key1: true, key2: false }; | ||
window.zaraz = { | ||
consent: { | ||
getAllCheckboxes: jest.fn().mockReturnValue(checkboxesMock), | ||
}, | ||
}; | ||
|
||
const checkboxes = getAllCheckboxes(); | ||
|
||
expect(checkboxes).toEqual(checkboxesMock); | ||
}); | ||
}); |
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,33 @@ | ||
import { getAll } from './get-all'; | ||
|
||
declare global { | ||
interface Window { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
zaraz: any; | ||
} | ||
} | ||
|
||
let windowObj: Window & typeof globalThis; | ||
|
||
beforeAll(() => { | ||
windowObj = window; | ||
}); | ||
|
||
afterAll(() => { | ||
window = windowObj; | ||
}); | ||
|
||
describe('getAll()', () => { | ||
it('should return all consents from zaraz consent', () => { | ||
const consentsMock = { key1: true, key2: false }; | ||
window.zaraz = { | ||
consent: { | ||
getAll: jest.fn().mockReturnValue(consentsMock), | ||
}, | ||
}; | ||
|
||
const consents = getAll(); | ||
|
||
expect(consents).toEqual(consentsMock); | ||
}); | ||
}); |
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,36 @@ | ||
import { getPurposes } from './get-purposes'; | ||
|
||
declare global { | ||
interface Window { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
zaraz: any; | ||
} | ||
} | ||
|
||
let windowObj: Window & typeof globalThis; | ||
|
||
beforeAll(() => { | ||
windowObj = window; | ||
}); | ||
|
||
afterAll(() => { | ||
window = windowObj; | ||
}); | ||
|
||
describe('getPurposes()', () => { | ||
it('should return all purposes from zaraz consent', () => { | ||
const purposesMock = { | ||
key1: { name: 'Name 1', description: 'Description 1', order: 1 }, | ||
key2: { name: 'Name 2', description: 'Description 2', order: 2 }, | ||
}; | ||
window.zaraz = { | ||
consent: { | ||
purposes: purposesMock, | ||
}, | ||
}; | ||
|
||
const purposes = getPurposes(); | ||
|
||
expect(purposes).toEqual(purposesMock); | ||
}); | ||
}); |
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,34 @@ | ||
import { get } from './get'; | ||
|
||
declare global { | ||
interface Window { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
zaraz: any; | ||
} | ||
} | ||
|
||
let windowObj: Window & typeof globalThis; | ||
|
||
beforeAll(() => { | ||
windowObj = window; | ||
}); | ||
|
||
afterAll(() => { | ||
window = windowObj; | ||
}); | ||
|
||
describe('get()', () => { | ||
it('should return the consent status for a purpose from zaraz consent', () => { | ||
const getMock = jest.fn().mockReturnValue(true); | ||
window.zaraz = { | ||
consent: { | ||
get: getMock, | ||
}, | ||
}; | ||
|
||
const consentStatus = get('key'); | ||
|
||
expect(consentStatus).toBe(true); | ||
expect(getMock).toHaveBeenCalledWith('key'); | ||
}); | ||
}); |
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,33 @@ | ||
import { sendQueuedEvents } from './send-queued-events'; | ||
|
||
declare global { | ||
interface Window { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
zaraz: any; | ||
} | ||
} | ||
|
||
let windowObj: Window & typeof globalThis; | ||
|
||
beforeAll(() => { | ||
windowObj = window; | ||
}); | ||
|
||
afterAll(() => { | ||
window = windowObj; | ||
}); | ||
|
||
describe('sendQueuedEvents()', () => { | ||
it('should call sendQueuedEvents method on zaraz consent', () => { | ||
const sendQueuedEventsMock = jest.fn(); | ||
window.zaraz = { | ||
consent: { | ||
sendQueuedEvents: sendQueuedEventsMock, | ||
}, | ||
}; | ||
|
||
sendQueuedEvents(); | ||
|
||
expect(sendQueuedEventsMock).toHaveBeenCalled(); | ||
}); | ||
}); |
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,33 @@ | ||
import { setAllCheckboxes } from './set-all-checkboxes'; | ||
|
||
declare global { | ||
interface Window { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
zaraz: any; | ||
} | ||
} | ||
|
||
let windowObj: Window & typeof globalThis; | ||
|
||
beforeAll(() => { | ||
windowObj = window; | ||
}); | ||
|
||
afterAll(() => { | ||
window = windowObj; | ||
}); | ||
|
||
describe('setAllCheckboxes()', () => { | ||
it('should call setAllCheckboxes method on zaraz consent with the correct argument', () => { | ||
const setAllCheckboxesMock = jest.fn(); | ||
window.zaraz = { | ||
consent: { | ||
setAllCheckboxes: setAllCheckboxesMock, | ||
}, | ||
}; | ||
|
||
setAllCheckboxes(true); | ||
|
||
expect(setAllCheckboxesMock).toHaveBeenCalledWith(true); | ||
}); | ||
}); |
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,33 @@ | ||
import { setAll } from './set-all'; | ||
|
||
declare global { | ||
interface Window { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
zaraz: any; | ||
} | ||
} | ||
|
||
let windowObj: Window & typeof globalThis; | ||
|
||
beforeAll(() => { | ||
windowObj = window; | ||
}); | ||
|
||
afterAll(() => { | ||
window = windowObj; | ||
}); | ||
|
||
describe('setAll()', () => { | ||
it('should call setAll method on zaraz consent with the correct argument', () => { | ||
const setAllMock = jest.fn(); | ||
window.zaraz = { | ||
consent: { | ||
setAll: setAllMock, | ||
}, | ||
}; | ||
|
||
setAll(true); | ||
|
||
expect(setAllMock).toHaveBeenCalledWith(true); | ||
}); | ||
}); |
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,34 @@ | ||
import { setCheckboxes } from './set-checkboxes'; | ||
|
||
declare global { | ||
interface Window { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
zaraz: any; | ||
} | ||
} | ||
|
||
let windowObj: Window & typeof globalThis; | ||
|
||
beforeAll(() => { | ||
windowObj = window; | ||
}); | ||
|
||
afterAll(() => { | ||
window = windowObj; | ||
}); | ||
|
||
describe('setCheckboxes()', () => { | ||
it('should call setCheckboxes method on zaraz consent with the correct argument', () => { | ||
const setCheckboxesMock = jest.fn(); | ||
window.zaraz = { | ||
consent: { | ||
setCheckboxes: setCheckboxesMock, | ||
}, | ||
}; | ||
|
||
const checkboxesStatus = { key1: true, key2: false }; | ||
setCheckboxes(checkboxesStatus); | ||
|
||
expect(setCheckboxesMock).toHaveBeenCalledWith(checkboxesStatus); | ||
}); | ||
}); |
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,34 @@ | ||
import { set } from './set'; | ||
|
||
declare global { | ||
interface Window { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
zaraz: any; | ||
} | ||
} | ||
|
||
let windowObj: Window & typeof globalThis; | ||
|
||
beforeAll(() => { | ||
windowObj = window; | ||
}); | ||
|
||
afterAll(() => { | ||
window = windowObj; | ||
}); | ||
|
||
describe('set()', () => { | ||
it('should call set method on zaraz consent with the correct argument', () => { | ||
const setMock = jest.fn(); | ||
window.zaraz = { | ||
consent: { | ||
set: setMock, | ||
}, | ||
}; | ||
|
||
const consentPreferences = { key1: true, key2: false }; | ||
set(consentPreferences); | ||
|
||
expect(setMock).toHaveBeenCalledWith(consentPreferences); | ||
}); | ||
}); |