-
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.
- Loading branch information
Karol Tatala
authored and
Karol Tatala
committed
Oct 7, 2023
1 parent
27cb7d5
commit 05cdb0d
Showing
10 changed files
with
1,865 additions
and
41 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 |
---|---|---|
|
@@ -10,3 +10,4 @@ dist | |
standalone-dist | ||
/vault-gcs.json | ||
stats.html | ||
coverage |
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,6 @@ | ||
module.exports = { | ||
testEnvironment: 'jsdom', | ||
moduleDirectories: ['node_modules', 'src'], | ||
restoreMocks: true, | ||
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!**/node_modules/**'], | ||
}; |
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
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,24 @@ | ||
import { getForcedOptimizely } from './getForcedOptimizely'; | ||
|
||
const originalLocation = window.location; | ||
describe('getForcedOptimizely', () => { | ||
it('should return undefined if there is no forced variation', () => { | ||
expect(getForcedOptimizely()).toBe(undefined); | ||
}); | ||
|
||
it('should return experimentId and variationId if there is a forced variation', () => { | ||
const experimentId = '123456789'; | ||
const variationId = '987654321'; | ||
const searchParams = new URLSearchParams(); | ||
searchParams.set('video_optimizely_force', `${experimentId}_${variationId}`); | ||
jest.spyOn(window, 'location', 'get').mockImplementation(() => ({ | ||
...originalLocation, | ||
search: searchParams.toString(), | ||
})); | ||
|
||
expect(getForcedOptimizely()).toEqual({ | ||
experimentId, | ||
variationId, | ||
}); | ||
}); | ||
}); |
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,77 @@ | ||
import React from 'react'; | ||
import { renderHook, act } from '@testing-library/react'; | ||
|
||
import { getCommunicationService } from 'jwplayer/utils/communication/communicationService'; | ||
|
||
import { OptimizelyContextProvider, WindowWithOptimizely } from './OptimizelyContext'; | ||
import { useOptimizelyVariation } from './useOptimizelyVariation'; | ||
|
||
const communicationService = getCommunicationService(); | ||
|
||
declare let window: WindowWithOptimizely; | ||
|
||
const originalLocation = window.location; | ||
|
||
afterEach(() => { | ||
delete window.optimizely; | ||
}); | ||
|
||
const setup = (experimentId = '1234') => { | ||
return renderHook( | ||
() => { | ||
return useOptimizelyVariation(experimentId); | ||
}, | ||
{ | ||
wrapper: ({ children }) => <OptimizelyContextProvider>{children}</OptimizelyContextProvider>, | ||
}, | ||
); | ||
}; | ||
|
||
describe('useOptimizelyVariation', () => { | ||
it('should return undefined if the optimizely is not available and the experiment is not forced', () => { | ||
const { result } = setup(); | ||
|
||
expect(result.current).toBeUndefined(); | ||
}); | ||
|
||
it('should return the forced variation if the experiment is forced', () => { | ||
const experimentId = '1234'; | ||
const variationId = '5678'; | ||
const searchParams = new URLSearchParams(); | ||
searchParams.set('video_optimizely_force', `${experimentId}_${variationId}`); | ||
|
||
jest.spyOn(window, 'location', 'get').mockImplementation(() => ({ | ||
...originalLocation, | ||
search: searchParams.toString(), | ||
})); | ||
|
||
const { result } = setup(experimentId); | ||
|
||
expect(result.current).toBe(variationId); | ||
}); | ||
|
||
it('should return the variation if the experiment is available', async () => { | ||
const experimentId = '1234'; | ||
const variationId = '5678'; | ||
const variationName = 'test'; | ||
|
||
window.optimizely = { | ||
get: () => ({ | ||
getVariationMap: () => ({ | ||
[experimentId]: { | ||
id: variationId, | ||
name: variationName, | ||
}, | ||
}), | ||
}), | ||
}; | ||
|
||
const { result } = setup(experimentId); | ||
|
||
act(() => { | ||
communicationService.dispatch({ type: '[Platform] optimizely loaded' }); | ||
}); | ||
|
||
expect(result.current).toBe(variationId); | ||
}); | ||
}); |
File renamed without changes.
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
Oops, something went wrong.