User:Evad37/Covery/sandbox.js: Difference between revisions

Content deleted Content added
.
Version 1.3.0: Platform input field
Line 3:
var SCRIPT = {
name: 'Covery',
version: '1.23.0',
ad: ' (using [[User:Evad37/Covery|Covery]])'
};
Line 182:
};
 
/**
var makeDescriptionText = function makeDescriptionText(articleTitle, developer, publisher) {
*
* @param {String} articleTitle
* @param {String} developer
* @param {String} publisher
* @param {String[]} platforms
*/
var makeDescriptionText = function makeDescriptionText(
articleTitle,
developer,
publisher,
platforms
) {
return (
'==Summary==\n{{Non-free use rationale video game cover\n' +
Line 427 ⟶ 439:
this.developerInput = new OO.ui.TextInputWidget({ required: true });
this.publisherInput = new OO.ui.TextInputWidget({ required: true });
this.platformInput = new OO.ui.MenuTagMultiselectWidget({
 
inputPosition: 'inline',
allowDisplayInvalidTags: true,
allowArbitrary: true
});
this.platformInput.on('add', function(item) {
console.log(item);
fetch('https://doc.wikimedia.org').then(function() {
item.toggleValid(false);
});
// widget.onChangeTags( );
});
this.fileSelectField = new OO.ui.FieldLayout(this.fileSelect, {
label: 'Upload a file...',
Line 460 ⟶ 483:
this.publisherInputField = new OO.ui.FieldLayout(this.publisherInput, {
label: 'Publisher',
align: 'left'
});
this.platformInputField = new OO.ui.FieldLayout(this.platformInput, {
label: 'Platform(s)',
align: 'left'
});
Line 471 ⟶ 498:
this.altTextInputField,
this.developerInputField,
this.publisherInputField,
this.platformInputField
]);
 
Line 510 ⟶ 538:
this,
{ change: 'onRequiredInputChange' }
);
this.platformInput.connect(
this,
{ add: 'onPlatformInputAdd' }
);
};
Line 605 ⟶ 637:
}
);
};
 
CoveryDialog.prototype.onPlatformInputAdd = function(item) {
this.api
.get({
action: 'query',
format: 'json',
titles: 'Category:' + item.data + ' game covers'
})
.then(function(response) {
return $.map(response.query.pages, function(page) {
return page.missing !== '';
})[0];
})
.then(function(isValid) {
item.toggleValid(isValid);
});
};
 
Line 685 ⟶ 734:
new mw.Title(this.pageName),
this.developerInput.getValue(),
this.publisherInput.getValue(),
this.platformInput.getValue()
),
fileTitle
Line 1,524 ⟶ 1,574:
var wikitext1 = makeInfoboxWikitext(infobox1, newParams);
var expected1 = '{{Infobox Video Game\n| image = Foo.png\n}}';
var infobox2 = getInfoboxTemplate(
'{{Infobox Video Game\n| image = \n| developer = DEV\n}}');
);
var wikitext2 = makeInfoboxWikitext(infobox2, newParams);
var expected2 =
'{{Infobox Video Game\n| image = Foo.png\n| developer = DEV\n}}';
assert.equal(wikitext1, expected1, 'Otherwise empty infobox');
assert.equal(wikitext2, expected2, 'With one other param');
});
QUnit.test('Override 1 empty param, 1 non-empty param', function(assert) {
var newParams = [
{ name: 'image', value: 'Foo.png' },
{ name: 'developer', value: '[[DEV]]' }];
];
var infobox1 = getInfoboxTemplate('{{Infobox Video Game\n| image = \n| developer = NotTheDev\n}}');
var infobox1 = getInfoboxTemplate(
'{{Infobox Video Game\n| image = \n| developer = NotTheDev\n}}'
);
var wikitext1 = makeInfoboxWikitext(infobox1, newParams);
var expected1 =
'{{Infobox Video Game\n| image = Foo.png\n| developer = [[DEV]]\n}}';
var infobox2 = getInfoboxTemplate(
'{{Infobox Video Game\n| image = \n| publisher = PUB\n| developer = NotTheDev\n}}');
);
var wikitext2 = makeInfoboxWikitext(infobox2, newParams);
var expected2 =
'{{Infobox Video Game\n| image = Foo.png\n| publisher = PUB\n| developer = [[DEV]]\n}}';
assert.equal(wikitext1, expected1, 'No other params');
assert.equal(wikitext2, expected2, 'With one other param');
});
 
QUnit.module('Make description text');
QUnit.test('No platforms', function(assert) {
var description = makeDescriptionText(new mw.Title('title'), 'dev', 'pub', []);
var expected =
'==Summary==\n{{Non-free use rationale video game cover\n' +
'| Article = title\n' +
'| Use = Infobox\n' +
'| Publisher = pub\n' +
'| Developer = dev\n' +
'}}\n' +
'==Licensing==\n{{Non-free video game cover}}';
assert.equal(description, expected, 'No platforms');
});
QUnit.test('One platform', function(assert) {
var description = makeDescriptionText(new mw.Title('title'), 'dev', 'pub', [
'Platform'
]);
var expected =
'==Summary==\n{{Non-free use rationale video game cover\n' +
'| Article = title\n' +
'| Use = Infobox\n' +
'| Publisher = pub\n' +
'| Developer = dev\n' +
'}}\n' +
'==Licensing==\n{{Non-free video game cover|Platform}}';
assert.equal(description, expected, 'One platform');
});
QUnit.test('Two platforms', function(assert) {
var description = makeDescriptionText(new mw.Title('title'), 'dev', 'pub', [
'Platform1',
'Platform2'
]);
var expected =
'==Summary==\n{{Non-free use rationale video game cover\n' +
'| Article = title\n' +
'| Use = Infobox\n' +
'| Publisher = pub\n' +
'| Developer = dev\n' +
'}}\n' +
'==Licensing==\n{{Non-free video game cover|Platform1|Platform2}}';
assert.equal(description, expected, 'Two platforms');
});
}); // end of "get script QUnit"