AndyRussG has uploaded a new change for review.
https://gerrit.wikimedia.org/r/182695
Change subject: Remove defaults for choices in test fixtures
......................................................................
Remove defaults for choices in test fixtures
The use of default values in test fixtures helped make the fixtures
more compact, but as the fixtures become more complex, it will
make them more difficult to read. This is the first step in removing
them. The next step will be to remove them for the setup property
of test fixtures (used by PHPUnit tests).
Also added a tidbit of fixture documentation (since comments are not
allowed in json).
Change-Id: I1e1e807deb86806f9c19e42dabeb857529e43e22
---
M tests/data/AllocationsFixtures.json
A tests/data/allocation_fixtures_doc.md
M
tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
3 files changed, 219 insertions(+), 56 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice
refs/changes/95/182695/1
diff --git a/tests/data/AllocationsFixtures.json
b/tests/data/AllocationsFixtures.json
index 6e239d6..3a44e22 100644
--- a/tests/data/AllocationsFixtures.json
+++ b/tests/data/AllocationsFixtures.json
@@ -24,25 +24,30 @@
},
"choices": [
{
+ "name": "c1",
+ "start": 0,
+ "end": 1,
"preferred": 1,
"throttle": 50,
"bucket_count": 1,
"geotargeted": true,
- "countries": [
- "FR",
- "GR",
- "XX"
- ],
"banners": [
{
"name": "b1",
- "weight": 5,
"bucket": 0,
+ "weight": 5,
"category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
"devices": [
"desktop"
]
}
+ ],
+ "countries": [
+ "FR",
+ "GR",
+ "XX"
]
}
],
@@ -77,36 +82,67 @@
"choices": [
{
"name": "c1",
- "geotargeted": false,
+ "start": 0,
+ "end": 1,
"preferred": 3,
"throttle": 60,
+ "bucket_count": 1,
+ "geotargeted": false,
"banners": [
{
"name": "c1b1",
+ "bucket": 0,
"weight": 25,
- "category": "fundraising"
+ "category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
},
{
"name": "c1b2",
+ "bucket": 0,
"weight": 25,
- "category": "fundraising"
+ "category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
}
]
},
{
"name": "c2",
+ "start": 0,
+ "end": 1,
"preferred": 1,
"throttle": 100,
+ "bucket_count": 1,
+ "geotargeted": false,
"banners": [
{
"name": "c2b1",
+ "bucket": 0,
"weight": 25,
- "category": "fundraising"
+ "category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
},
{
"name": "c2b2",
+ "bucket": 0,
"weight": 25,
- "category": "fundraising"
+ "category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
}
]
}
@@ -142,19 +178,46 @@
},
"choices": [
{
+ "name": "c1",
+ "start": 0,
+ "end": 1,
+ "preferred": 1,
"throttle": 100,
+ "bucket_count": 1,
+ "geotargeted": false,
"banners": [
{
"name": "b1",
- "weight": 5
+ "bucket": 0,
+ "weight": 5,
+ "category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
},
{
"name": "b2",
- "weight": 100
+ "bucket": 0,
+ "weight": 100,
+ "category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
},
{
"name": "b3",
- "weight": 100
+ "bucket": 0,
+ "weight": 100,
+ "category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
}
]
}
@@ -179,9 +242,25 @@
},
"choices": [
{
+ "name": "c1",
+ "start": 0,
+ "end": 1,
+ "preferred": 1,
"throttle": 10,
+ "bucket_count": 1,
+ "geotargeted": false,
"banners": [
- { "name": "b1" }
+ {
+ "name": "b1",
+ "bucket": 0,
+ "weight": 5,
+ "category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
+ }
]
}
],
@@ -212,16 +291,46 @@
"choices": [
{
"name": "c1",
+ "start": 0,
+ "end": 1,
"preferred": 1,
+ "throttle": 100,
+ "bucket_count": 1,
+ "geotargeted": false,
"banners": [
- { "name": "c1b1" }
+ {
+ "name": "c1b1",
+ "bucket": 0,
+ "weight": 5,
+ "category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
+ }
]
},
{
"name": "c2",
+ "start": 0,
+ "end": 1,
"preferred": 2,
+ "throttle": 100,
+ "bucket_count": 1,
+ "geotargeted": false,
"banners": [
- { "name": "c2b1" }
+ {
+ "name": "c2b1",
+ "bucket": 0,
+ "weight": 5,
+ "category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
+ }
]
}
],
@@ -251,16 +360,29 @@
},
"choices": [
{
+ "name": "c1",
+ "start": 0,
+ "end": 1,
+ "preferred": 1,
+ "throttle": 100,
+ "bucket_count": 1,
"geotargeted": true,
- "countries": [
- "FR",
- "XX"
- ],
"banners": [
{
"name": "b1",
- "weight": 5
+ "weight": 5,
+ "bucket": 0,
+ "category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
}
+ ],
+ "countries": [
+ "FR",
+ "XX"
]
}
],
@@ -289,16 +411,29 @@
},
"choices": [
{
+ "name": "c1",
+ "start": 0,
+ "end": 1,
+ "preferred": 1,
+ "throttle": 10,
+ "bucket_count": 1,
"geotargeted": true,
- "countries": [
- "FR",
- "GR"
- ],
"banners": [
{
"name": "b1",
- "weight": 5
+ "bucket": 0,
+ "weight": 5,
+ "category": "fundraising",
+ "display_anon": true,
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
}
+ ],
+ "countries": [
+ "FR",
+ "GR"
]
}
],
@@ -383,12 +518,24 @@
},
"choices": [
{
+ "name": "c1",
+ "start": 0,
+ "end": 1,
+ "preferred": 1,
+ "throttle": 10,
+ "bucket_count": 1,
+ "geotargeted": false,
"banners": [
{
"name": "b1",
+ "bucket": 0,
"weight": 5,
+ "category": "fundraising",
"display_anon": false,
- "display_account": true
+ "display_account": true,
+ "devices": [
+ "desktop"
+ ]
}
]
}
diff --git a/tests/data/allocation_fixtures_doc.md
b/tests/data/allocation_fixtures_doc.md
new file mode 100644
index 0000000..0889602
--- /dev/null
+++ b/tests/data/allocation_fixtures_doc.md
@@ -0,0 +1,14 @@
+Allocation Fixtures Documentation
+=================================
+
+Documentation for AllocationFixtures.json
+
+TODO: Complete this documentation
+
+
+Test Cases
+----------
+
+In the allocation fixture data, times are represented as offsets in days from
the
+current time. When the fixtures are loaded, these are converted to UNIX
+timestamps (the format used by the code being tested).
\ No newline at end of file
diff --git
a/tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
b/tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
index a18b257..04df05f 100644
---
a/tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
+++
b/tests/qunit/ext.centralNotice.bannerController.lib/bannerController.lib.tests.js
@@ -1,21 +1,6 @@
( function( mw, $ ) {
'use strict';
- var defaultCampaignData = {
- banners: [],
- bucket_count: 1,
- countries: [],
- geotargeted: 0,
- preferred: 1,
- throttle: 100
- }, defaultBannerData = {
- bucket: 0,
- devices: [ 'desktop' ],
- weight: 25,
- display_anon: true,
- display_account: true
- };
-
QUnit.module( 'ext.centralNotice.bannerController.lib',
QUnit.newMwEnvironment( {
setup: function() {
mw.centralNotice.data.country = 'XX';
@@ -38,19 +23,10 @@
i,
allocatedBanner;
- // Flesh out choice data with some default values
- // BOOM on priority case
- choices = $.map( testCase.choices, function( campaign )
{
- return $.extend(
- { },
- defaultCampaignData,
- campaign,
- {
- banners: $.map(
campaign.banners, function( banner ) {
- return $.extend( {},
defaultBannerData, banner );
- } )
- } );
- } );
+ // BOOM on priority case FIXME ???
+
+ prepareTestCase( testCase );
+ choices = testCase.choices;
// Set per-campaign buckets to 0 for all campaigns
// FIXME Allow testing of different buckets
@@ -91,6 +67,32 @@
} );
} );
+ /**
+ * Return a UNIX timestamp for the current time offset by the number of
days
+ * indicated.
+ */
+ function makeTimestamp( offsetInDays ) {
+ var date = new Date();
+ date.setDate( date.getDate() + offsetInDays );
+ return Math.round( date.getTime() / 1000 );
+ }
+
+ /**
+ * Prepare a test case for use in a test. Currently just substitutes
UNIX
+ * timestamps for times in the fixtures, which are represented as
offsets
+ * in days from the current time. Note: this logic is repeated in PHP
for
+ * PHPUnit tests that use the same fixtures. (TODO)
+ * @see TODO
+ */
+ function prepareTestCase( testCase ) {
+ var i, choice;
+ for ( i = 0; i < testCase.choices.length; i++ ) {
+ choice = testCase.choices[i];
+ choice.start = makeTimestamp( choice.start );
+ choice.end = makeTimestamp( choice.end);
+ }
+ }
+
// TODO: chooser tests
} ( mediaWiki, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/182695
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1e1e807deb86806f9c19e42dabeb857529e43e22
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: AndyRussG <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits