jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/373279 )
Change subject: Unit tests for MWLink translation unit class ...................................................................... Unit tests for MWLink translation unit class Change-Id: I25ffb50cf7c27ca1f5cf71176d31465fde470db0 --- M lib/translationunits/MWLink.js M test/index.js A test/translationunits/MWLink.test.js A test/translationunits/MWLink.test.json 4 files changed, 265 insertions(+), 0 deletions(-) Approvals: jenkins-bot: Verified Nikerabbit: Looks good to me, approved diff --git a/lib/translationunits/MWLink.js b/lib/translationunits/MWLink.js index c6c7bc5..51455e1 100644 --- a/lib/translationunits/MWLink.js +++ b/lib/translationunits/MWLink.js @@ -30,6 +30,7 @@ if ( linkPairInfo.targetTitle ) { // NOTE: This paths we are setting here are not relative paths. this.node.attributes[ 'href' ] = linkPairInfo.targetTitle; + this.node.attributes[ 'title' ] = linkPairInfo.targetTitle; adaptationInfo.targetTitle = yield apiRequestManager.titleInfoRequest( linkPairInfo.targetTitle, this.targetLanguage ); diff --git a/test/index.js b/test/index.js index b6feadd..142b56e 100644 --- a/test/index.js +++ b/test/index.js @@ -13,6 +13,7 @@ 'lib/pageloader', 'lib/routes', 'lib/segmentation', + 'lib/translationunits', 'tests/**/*.js' ]; diff --git a/test/translationunits/MWLink.test.js b/test/translationunits/MWLink.test.js new file mode 100644 index 0000000..13e6f7b --- /dev/null +++ b/test/translationunits/MWLink.test.js @@ -0,0 +1,36 @@ +'use strict'; + +var assert = require( '../utils/assert.js' ), + server = require( '../utils/server.js' ), + async = require( 'async' ), + Adapter = require( '../../lib/Adapter' ), + tests = require( './MWLink.test.json' ); + +describe( 'Link Adaptation tests', function () { + async.forEach( tests, function ( test ) { + it( 'should not have any errors when: ' + test.desc, function () { + var translationunit, adapter; + + adapter = new Adapter( test.from, test.to, server.config ); + translationunit = adapter.getAdapter( test.source ); + return translationunit.adapt( test.source ).then( function ( adaptedNode ) { + let expectedDataCX, actualDataCX; + assert.deepEqual( adaptedNode.attributes.href, test.result.attributes.href ); + assert.deepEqual( adaptedNode.attributes.rel, test.result.attributes.rel ); + assert.deepEqual( adaptedNode.attributes.title, test.result.attributes.title ); + expectedDataCX = JSON.parse( adaptedNode.attributes[ 'data-cx' ] ); + actualDataCX = test.result.attributes[ 'data-cx' ]; + assert.deepEqual( expectedDataCX.adapted, actualDataCX.adapted ); + assert.deepEqual( !!actualDataCX.sourceTitle.thumbnail, !!expectedDataCX.sourceTitle.thumbnail ); + assert.deepEqual( !!actualDataCX.sourceTitle.pageimage, !!expectedDataCX.sourceTitle.pageimage ); + assert.ok( !!actualDataCX.sourceTitle.terms, !!expectedDataCX.sourceTitle.terms ); + if ( expectedDataCX.adapted ) { + assert.deepEqual( expectedDataCX.targetTitle.pageid, actualDataCX.targetTitle.pageid ); + assert.deepEqual( !!actualDataCX.targetTitle.thumbnail, !!expectedDataCX.targetTitle.thumbnail ); + assert.deepEqual( !!actualDataCX.targetTitle.pageimage, !!expectedDataCX.targetTitle.pageimage ); + assert.deepEqual( !!actualDataCX.targetTitle.terms, !!expectedDataCX.targetTitle.terms ); + } + } ); + } ); + } ); +} ); diff --git a/test/translationunits/MWLink.test.json b/test/translationunits/MWLink.test.json new file mode 100644 index 0000000..118137c --- /dev/null +++ b/test/translationunits/MWLink.test.json @@ -0,0 +1,227 @@ +[ + { + "desc": "Basic test", + "from": "en", + "to": "es", + "source": { + "attributes": { + "rel": "mw:WikiLink", + "href": "Oxygen", + "title": "Oxygen" + } + }, + "result": { + "attributes": { + "rel": "mw:WikiLink", + "href": "Oxígeno", + "title": "Oxígeno", + "data-cx": { + "adapted": true, + "targetTitle": { + "pageid": 3267, + "ns": 0, + "title": "Oxígeno", + "thumbnail": { + "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/O%2C8.jpg/80px-O%2C8.jpg", + "width": 80, + "height": 40 + }, + "pageimage": "O,8.jpg", + "terms": { + "description": ["elemento químico", "elemento químico"] + } + }, + "sourceTitle": { + "pageid": 22303, + "ns": 0, + "title": "Oxygen", + "thumbnail": { + "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Liquid_oxygen_in_a_beaker_4.jpg/66px-Liquid_oxygen_in_a_beaker_4.jpg", + "width": 66, + "height": 80 + }, + "pageimage": "Liquid_oxygen_in_a_beaker_4.jpg", + "terms": { + "description": ["element with the atomic number of 8", "element with the atomic number of 8"] + } + } + } + + } + } + }, + { + "desc": "Space in the title", + "from": "en", + "to": "es", + "source": { + "attributes": { + "rel": "mw:WikiLink", + "href": "Atomic number", + "title": "Atomic number" + } + }, + "result": { + "attributes": { + "rel": "mw:WikiLink", + "href": "Número atómico", + "title": "Número atómico", + "data-cx": { + "adapted": true, + "targetTitle": { + "pageid": 1980, + "ns": 0, + "title": "Número atómico", + "thumbnail": { + "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/db/Element_identity.png/80px-Element_identity.png", + "width": 80, + "height": 80 + }, + "pageimage": "Element_identity.png", + "terms": { + "description": ["número total de protones que tiene el átomo", "número total de protones que tiene el átomo"] + } + }, + "sourceTitle": { + "pageid": 673, + "ns": 0, + "title": "Atomic number", + "thumbnail": { + "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Atomic_number_depiction.jpg/80px-Atomic_number_depiction.jpg", + "width": 80, + "height": 49 + }, + "pageimage": "Atomic_number_depiction.jpg", + "terms": { + "description": ["number of protons found in the nucleus of an atom", "number of protons found in the nucleus of an atom"] + } + } + } + } + } + }, + { + "desc": "Relative URL", + "from": "en", + "to": "es", + "source": { + "attributes": { + "rel": "mw:WikiLink", + "href": "./Atomic number", + "title": "Atomic number" + } + }, + "result": { + "attributes": { + "rel": "mw:WikiLink", + "href": "Número atómico", + "title": "Número atómico", + "data-cx": { + "adapted": true, + "targetTitle": { + "pageid": 1980, + "ns": 0, + "title": "Número atómico", + "thumbnail": { + "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/db/Element_identity.png/80px-Element_identity.png", + "width": 80, + "height": 80 + }, + "pageimage": "Element_identity.png", + "terms": { + "description": ["número total de protones que tiene el átomo", "número total de protones que tiene el átomo"] + } + }, + "sourceTitle": { + "pageid": 673, + "ns": 0, + "title": "Atomic number", + "thumbnail": { + "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Atomic_number_depiction.jpg/80px-Atomic_number_depiction.jpg", + "width": 80, + "height": 49 + }, + "pageimage": "Atomic_number_depiction.jpg", + "terms": { + "description": ["number of protons found in the nucleus of an atom", "number of protons found in the nucleus of an atom"] + } + } + } + } + } + }, + { + "desc": "Title with paranthesis", + "from": "en", + "to": "es", + "source": { + "attributes": { + "rel": "mw:WikiLink", + "href": "./The_Godfather_(wrestler)", + "title": "The Godfather (wrestler)" + } + }, + "result": { + "attributes": { + "rel": "mw:WikiLink", + "href": "Charles Wright (luchador)", + "title": "Charles Wright (luchador)", + "data-cx": { + "adapted": true, + "targetTitle": { + "pageid": 2834764, + "ns": 0, + "title": "Charles Wright (luchador)", + "thumbnail": { + "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/6/65/Paul_Wright_AKA_%28The_Godfather%29.jpg/50px-Paul_Wright_AKA_%28The_Godfather%29.jpg", + "width": 50, + "height": 80 + }, + "pageimage": "Paul_Wright_AKA_(The_Godfather).jpg" + }, + "sourceTitle": { + "pageid": 591648, + "ns": 0, + "title": "The Godfather (wrestler)", + "thumbnail": { + "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f9/Charles_Wright_AKA_The_Godfather_WrestleMania_32_Axxess.jpg/51px-Charles_Wright_AKA_The_Godfather_WrestleMania_32_Axxess.jpg", + "width": 51, + "height": 80 + }, + "pageimage": "Charles_Wright_AKA_The_Godfather_WrestleMania_32_Axxess.jpg", + "terms": { + "description": ["professional wrestler, strip club manager"] + } + } + } + } + } + }, + { + "desc": "Target title does not exist", + "from": "en", + "to": "es", + "source": { + "attributes": { + "rel": "mw:WikiLink", + "href": "./List_of_planets_with_life", + "title": "List of planets with life" + } + }, + "result": { + "attributes": { + "rel": "mw:WikiLink", + "href": "./List_of_planets_with_life", + "title": "List of planets with life", + "data-cx": { + "adapted": false, + "sourceTitle": { + "title": "List of planets with life", + "terms": {} + }, + "targetTitle": {} + } + } + } + } +] -- To view, visit https://gerrit.wikimedia.org/r/373279 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I25ffb50cf7c27ca1f5cf71176d31465fde470db0 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com> Gerrit-Reviewer: Santhosh <santhosh.thottin...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits