mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-09-23 10:21:40 +00:00
Refactor: Separate A/B test configuration from site configuration
Making it easier to add configuration variables to JavaScript in future. This will be used for the pointer indicator. Change-Id: I65396a3867e7e92d7385ebaa573fb48105ecb9fd
This commit is contained in:
parent
dd146468ff
commit
28ada2dc78
|
@ -46,10 +46,14 @@ class Hooks implements
|
|||
}
|
||||
|
||||
/**
|
||||
* @param RL\Context $context
|
||||
* @param Config $config
|
||||
* @return array
|
||||
*/
|
||||
private static function getActiveABTest( $config ) {
|
||||
public static function getActiveABTest(
|
||||
RL\Context $context,
|
||||
Config $config
|
||||
) {
|
||||
$ab = $config->get(
|
||||
Constants::CONFIG_WEB_AB_TEST_ENROLLMENT
|
||||
);
|
||||
|
@ -80,22 +84,6 @@ class Hooks implements
|
|||
return $ab;
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes config variables to Vector (modern) ResourceLoader module.
|
||||
* @param RL\Context $context
|
||||
* @param Config $config
|
||||
* @return array
|
||||
*/
|
||||
public static function getVectorResourceLoaderConfig(
|
||||
RL\Context $context,
|
||||
Config $config
|
||||
) {
|
||||
return [
|
||||
'wgVectorSearchApiUrl' => $config->get( 'VectorSearchApiUrl' ),
|
||||
'wgVectorWebABTestEnrollment' => self::getActiveABTest( $config ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates config variables for skins.vector.search Resource Loader module (defined in
|
||||
* skin.json).
|
||||
|
@ -140,8 +128,6 @@ class Hooks implements
|
|||
// and from its point of view they are the same thing.
|
||||
// Please see the modules `skins.vector.js` and `skins.vector.legacy.js`
|
||||
// for the wire up of search.
|
||||
// The related method self::getVectorResourceLoaderConfig handles which
|
||||
// search to load.
|
||||
$config['search'] = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/** See Vector\Hooks::getVectorResourceLoaderConfig */
|
||||
/** For virtual configuration of resources/skins.vector.js/config.json */
|
||||
interface VectorResourceLoaderVirtualConfig {
|
||||
wgVectorSearchApiUrl: string;
|
||||
VectorSearchApiUrl: string;
|
||||
}
|
||||
|
|
3
resources/skins.vector.es6/activeABTest.json
Normal file
3
resources/skins.vector.es6/activeABTest.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"@doc": "This file describes the shape of the AB config. It exists to support jest"
|
||||
}
|
|
@ -11,7 +11,7 @@ const
|
|||
popupNotification = require( './popupNotification.js' ),
|
||||
features = require( './features.js' ),
|
||||
deferUntilFrame = require( './deferUntilFrame.js' ),
|
||||
ABTestConfig = require( /** @type {string} */ ( './config.json' ) ).wgVectorWebABTestEnrollment || {},
|
||||
ABTestConfig = require( /** @type {string} */ ( './activeABTest.json' ) ),
|
||||
STICKY_HEADER_VISIBLE_CLASS = 'vector-sticky-header-visible',
|
||||
TOC_ID = 'vector-toc',
|
||||
BODY_CONTENT_ID = 'bodyContent',
|
||||
|
|
|
@ -141,8 +141,8 @@ function initSearchLoader( document ) {
|
|||
var searchBoxes = document.querySelectorAll( '.vector-search-box' );
|
||||
|
||||
// Allow developers to defined $wgVectorSearchApiUrl in LocalSettings to target different APIs
|
||||
if ( config.wgVectorSearchApiUrl ) {
|
||||
mw.config.set( 'wgVectorSearchApiUrl', config.wgVectorSearchApiUrl );
|
||||
if ( config.VectorSearchApiUrl ) {
|
||||
mw.config.set( 'wgVectorSearchApiUrl', config.VectorSearchApiUrl );
|
||||
}
|
||||
|
||||
if ( !searchBoxes.length ) {
|
||||
|
|
|
@ -353,9 +353,13 @@
|
|||
"resources/skins.vector.es6/features.js",
|
||||
"resources/skins.vector.es6/limitedWidthToggle.js",
|
||||
"resources/skins.vector.es6/popupNotification.js",
|
||||
{
|
||||
"name": "resources/skins.vector.es6/activeABTest.json",
|
||||
"callback": "MediaWiki\\Skins\\Vector\\Hooks::getActiveABTest"
|
||||
},
|
||||
{
|
||||
"name": "resources/skins.vector.es6/config.json",
|
||||
"callback": "MediaWiki\\Skins\\Vector\\Hooks::getVectorResourceLoaderConfig"
|
||||
"config": [ "VectorSearchApiUrl" ]
|
||||
},
|
||||
{
|
||||
"name": "resources/skins.vector.es6/tableOfContentsConfig.json",
|
||||
|
@ -401,7 +405,7 @@
|
|||
"resources/skins.vector.js/skin.js",
|
||||
{
|
||||
"name": "resources/skins.vector.js/config.json",
|
||||
"callback": "MediaWiki\\Skins\\Vector\\Hooks::getVectorResourceLoaderConfig"
|
||||
"config": [ "VectorSearchApiUrl" ]
|
||||
},
|
||||
"resources/skins.vector.js/watchstar.js",
|
||||
"resources/skins.vector.js/dropdownMenus.js",
|
||||
|
|
|
@ -53,17 +53,13 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
];
|
||||
}
|
||||
|
||||
public function provideGetVectorResourceLoaderConfig() {
|
||||
public function provideGetActiveABTest() {
|
||||
return [
|
||||
[
|
||||
[
|
||||
'VectorWebABTestEnrollment' => [],
|
||||
'VectorSearchApiUrl' => 'https://en.wikipedia.org/w/rest.php'
|
||||
],
|
||||
[
|
||||
'wgVectorSearchApiUrl' => 'https://en.wikipedia.org/w/rest.php',
|
||||
'wgVectorWebABTestEnrollment' => [],
|
||||
]
|
||||
[]
|
||||
],
|
||||
[
|
||||
[
|
||||
|
@ -85,34 +81,30 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
],
|
||||
],
|
||||
'VectorSearchApiUrl' => 'https://en.wikipedia.org/w/rest.php'
|
||||
],
|
||||
[
|
||||
'wgVectorSearchApiUrl' => 'https://en.wikipedia.org/w/rest.php',
|
||||
'wgVectorWebABTestEnrollment' => [
|
||||
'name' => 'vector.sticky_header',
|
||||
'enabled' => true,
|
||||
'buckets' => [
|
||||
'unsampled' => [
|
||||
'samplingRate' => 1,
|
||||
],
|
||||
'control' => [
|
||||
'samplingRate' => 0
|
||||
],
|
||||
'stickyHeaderEnabled' => [
|
||||
'samplingRate' => 0
|
||||
],
|
||||
'stickyHeaderDisabled' => [
|
||||
'samplingRate' => 0
|
||||
],
|
||||
],
|
||||
'name' => 'vector.sticky_header',
|
||||
'enabled' => true,
|
||||
'buckets' => [
|
||||
'unsampled' => [
|
||||
'samplingRate' => 1,
|
||||
],
|
||||
'control' => [
|
||||
'samplingRate' => 0
|
||||
],
|
||||
'stickyHeaderEnabled' => [
|
||||
'samplingRate' => 0
|
||||
],
|
||||
'stickyHeaderDisabled' => [
|
||||
'samplingRate' => 0
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function provideGetVectorResourceLoaderConfigWithExceptions() {
|
||||
public function provideGetActiveABTestWithExceptions() {
|
||||
return [
|
||||
# Bad experiment (no buckets)
|
||||
[
|
||||
|
@ -343,12 +335,12 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::getVectorResourceLoaderConfig
|
||||
* @dataProvider provideGetVectorResourceLoaderConfig
|
||||
* @covers ::getActiveABTest
|
||||
* @dataProvider provideGetActiveABTest
|
||||
*/
|
||||
public function testGetVectorResourceLoaderConfig( $configData, $expected ) {
|
||||
public function testGetActiveABTest( $configData, $expected ) {
|
||||
$config = new HashConfig( $configData );
|
||||
$vectorConfig = Hooks::getVectorResourceLoaderConfig(
|
||||
$vectorConfig = Hooks::getActiveABTest(
|
||||
$this->createMock( ResourceLoaderContext::class ),
|
||||
$config
|
||||
);
|
||||
|
@ -360,13 +352,13 @@ class VectorHooksTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ::getVectorResourceLoaderConfig
|
||||
* @dataProvider provideGetVectorResourceLoaderConfigWithExceptions
|
||||
* @covers ::getActiveABTest
|
||||
* @dataProvider provideGetActiveABTestWithExceptions
|
||||
*/
|
||||
public function testGetVectorResourceLoaderConfigWithExceptions( $configData ) {
|
||||
public function testGetActiveABTestWithExceptions( $configData ) {
|
||||
$config = new HashConfig( $configData );
|
||||
$this->expectException( RuntimeException::class );
|
||||
Hooks::getVectorResourceLoaderConfig(
|
||||
Hooks::getActiveABTest(
|
||||
$this->createMock( ResourceLoaderContext::class ),
|
||||
$config
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue