2022-03-17 16:54:26 +00:00
|
|
|
const { test } = require( '../../../resources/skins.vector.es6/main.js' );
|
2022-05-31 22:32:50 +00:00
|
|
|
const {
|
|
|
|
STICKY_HEADER_EXPERIMENT_NAME,
|
|
|
|
STICKY_HEADER_EDIT_EXPERIMENT_NAME
|
|
|
|
} = require( '../../../resources/skins.vector.es6/stickyHeader.js' );
|
2022-03-17 16:54:26 +00:00
|
|
|
describe( 'main.js', () => {
|
|
|
|
it( 'getHeadingIntersectionHandler', () => {
|
|
|
|
const section = document.createElement( 'div' );
|
|
|
|
section.setAttribute( 'class', 'mw-body-content' );
|
|
|
|
section.setAttribute( 'id', 'mw-content-text' );
|
|
|
|
const heading = document.createElement( 'h2' );
|
|
|
|
const headline = document.createElement( 'span' );
|
|
|
|
headline.classList.add( 'mw-headline' );
|
|
|
|
headline.setAttribute( 'id', 'headline' );
|
|
|
|
heading.appendChild( headline );
|
|
|
|
section.appendChild(
|
|
|
|
heading
|
|
|
|
);
|
|
|
|
|
|
|
|
[
|
|
|
|
[ section, 'toc-mw-content-text' ],
|
|
|
|
[ heading, 'toc-headline' ]
|
|
|
|
].forEach( ( testCase ) => {
|
|
|
|
const node = /** @type {HTMLElement} */ ( testCase[ 0 ] );
|
|
|
|
const fn = jest.fn();
|
|
|
|
const handler = test.getHeadingIntersectionHandler( fn );
|
|
|
|
handler( node );
|
|
|
|
expect( fn ).toHaveBeenCalledWith( testCase[ 1 ] );
|
|
|
|
} );
|
|
|
|
} );
|
2022-05-31 22:32:50 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
};
|
2022-06-15 22:01:02 +00:00
|
|
|
const DISABLED_STICKY_HEADER_AB_EDIT = {
|
|
|
|
name: STICKY_HEADER_EDIT_EXPERIMENT_NAME,
|
|
|
|
enabled: false
|
|
|
|
};
|
|
|
|
const TABLE_OF_CONTENTS_AB = {
|
|
|
|
name: 'skin-vector-toc-experiment',
|
|
|
|
enabled: true,
|
|
|
|
buckets: {}
|
|
|
|
};
|
2022-05-31 22:32:50 +00:00
|
|
|
[
|
|
|
|
{
|
|
|
|
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
|
|
|
|
}
|
2022-06-15 22:01:02 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
abConfig: TABLE_OF_CONTENTS_AB,
|
|
|
|
isEnabled: true,
|
|
|
|
isUserInTreatmentBucket: false,
|
|
|
|
expectedResult: {
|
|
|
|
showStickyHeader: true,
|
|
|
|
disableEditIcons: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
abConfig: DISABLED_STICKY_HEADER_AB_EDIT,
|
|
|
|
isEnabled: true,
|
|
|
|
isUserInTreatmentBucket: false,
|
|
|
|
expectedResult: {
|
|
|
|
showStickyHeader: true,
|
|
|
|
disableEditIcons: false
|
|
|
|
}
|
2022-05-31 22:32:50 +00:00
|
|
|
}
|
|
|
|
].forEach( ( { abConfig, isEnabled, isUserInTreatmentBucket, expectedResult } ) => {
|
|
|
|
document.documentElement.classList.add( 'vector-sticky-header-enabled' );
|
|
|
|
const result = test.initStickyHeaderABTests(
|
|
|
|
abConfig,
|
2022-06-15 22:01:02 +00:00
|
|
|
// isStickyHeaderFeatureAllowed
|
2022-05-31 22:32:50 +00:00
|
|
|
isEnabled,
|
|
|
|
( experiment ) => ( {
|
|
|
|
name: experiment.name,
|
|
|
|
isInBucket: () => true,
|
|
|
|
isInSample: () => true,
|
|
|
|
getBucket: () => 'bucket',
|
|
|
|
isInTreatmentBucket: () => {
|
|
|
|
return isUserInTreatmentBucket;
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
expect( result ).toMatchObject( expectedResult );
|
2022-05-31 22:33:31 +00:00
|
|
|
// Check that there are no side effects
|
|
|
|
expect(
|
|
|
|
document.documentElement.classList.contains( 'vector-sticky-header-enabled' )
|
|
|
|
).toBe( true );
|
2022-05-31 22:32:50 +00:00
|
|
|
} );
|
|
|
|
} );
|
2022-03-17 16:54:26 +00:00
|
|
|
} );
|