Merge "Adds tests for stickyHeader A/B test logic"

This commit is contained in:
jenkins-bot 2022-06-01 16:22:13 +00:00 committed by Gerrit Code Review
commit 8c4ed23069
1 changed files with 96 additions and 1 deletions

View File

@ -1,5 +1,8 @@
const { test } = require( '../../../resources/skins.vector.es6/main.js' );
const {
STICKY_HEADER_EXPERIMENT_NAME,
STICKY_HEADER_EDIT_EXPERIMENT_NAME
} = require( '../../../resources/skins.vector.es6/stickyHeader.js' );
describe( 'main.js', () => {
it( 'getHeadingIntersectionHandler', () => {
const section = document.createElement( 'div' );
@ -25,4 +28,96 @@ describe( 'main.js', () => {
expect( fn ).toHaveBeenCalledWith( testCase[ 1 ] );
} );
} );
it( 'initStickyHeaderABTests', () => {
const STICKY_HEADER_AB = {
name: STICKY_HEADER_EXPERIMENT_NAME,
enabled: true
};
const STICKY_HEADER_AB_EDIT = {
name: STICKY_HEADER_EDIT_EXPERIMENT_NAME,
enabled: true
};
[
{
abConfig: STICKY_HEADER_AB_EDIT,
isEnabled: false,
isUserInTreatmentBucket: false,
expectedResult: {
showStickyHeader: false,
disableEditIcons: true
}
},
{
abConfig: STICKY_HEADER_AB_EDIT,
isEnabled: true,
isUserInTreatmentBucket: false,
expectedResult: {
showStickyHeader: true,
disableEditIcons: true
}
},
{
abConfig: STICKY_HEADER_AB_EDIT,
isEnabled: true,
isUserInTreatmentBucket: true,
expectedResult: {
showStickyHeader: true,
disableEditIcons: false
}
},
{
abConfig: STICKY_HEADER_AB,
isEnabled: false, // sticky header unavailable
isUserInTreatmentBucket: false, // not in treament bucket
expectedResult: {
showStickyHeader: false,
disableEditIcons: true
}
},
{
abConfig: STICKY_HEADER_AB,
isEnabled: true, // sticky header available
isUserInTreatmentBucket: false, // not in treament bucket
expectedResult: {
showStickyHeader: false,
disableEditIcons: true
}
},
{
abConfig: STICKY_HEADER_AB,
isEnabled: false, // sticky header is not available
isUserInTreatmentBucket: true, // but the user is in the treament bucket
expectedResult: {
showStickyHeader: false,
disableEditIcons: true
}
},
{
abConfig: STICKY_HEADER_AB,
isEnabled: true,
isUserInTreatmentBucket: true,
expectedResult: {
showStickyHeader: true,
disableEditIcons: true
}
}
].forEach( ( { abConfig, isEnabled, isUserInTreatmentBucket, expectedResult } ) => {
document.documentElement.classList.add( 'vector-sticky-header-enabled' );
const result = test.initStickyHeaderABTests(
abConfig,
isEnabled,
( experiment ) => ( {
name: experiment.name,
isInBucket: () => true,
isInSample: () => true,
getBucket: () => 'bucket',
isInTreatmentBucket: () => {
return isUserInTreatmentBucket;
}
} )
);
expect( result ).toMatchObject( expectedResult );
} );
} );
} );