diff --git a/.eslintrc.json b/.eslintrc.json index 04f9da7ac3..337ee67050 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,5 +2,10 @@ "root": true, "extends": [ "wikimedia/server" - ] + ], + "env": { + "commonjs": true, + "node": true, + "mocha": true + } } diff --git a/.gitignore b/.gitignore index c4bbae6dcb..1f6bc178b0 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ vendor screenshots/*.png .eslintcache tests/selenium/log +.api-testing.config.json # OS .DS_Store diff --git a/package.json b/package.json index 4136defbb6..6fb3a5316a 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,8 @@ "private": true, "description": "Build tools for the VisualEditor-MediaWiki extension.", "scripts": { + "eslint": "eslint --cache --ext .js,.json .", + "eslint-fix": "eslint --cache --ext .js,.json --fix .", "api-testing": "mocha --timeout 0 --parallel --recursive tests/api-testing", "test": "grunt test", "doc": "jsduck", diff --git a/tests/api-testing/edit.js b/tests/api-testing/edit.js index 49f9593068..94d317e709 100644 --- a/tests/api-testing/edit.js +++ b/tests/api-testing/edit.js @@ -1,3 +1,53 @@ 'use strict'; -// TBD +const { action, assert, utils } = require( 'api-testing' ); + +describe( 'Visual Editor API', function () { + // const titles = ( list ) => list.map( ( p ) => utils.dbkey( p.title ) ); + + const title = utils.title( 'VisualEditor' ); + + let alice; + let pageInfo; + + before( async () => { + alice = await action.alice(); + + const textX = 'Hello World! {{Template Requests}}'; + + pageInfo = await + alice.edit( title, { text: textX } ); + + } ); + // https://en.wikipedia.org/w/api.php?action=visualeditor&format=json&page=Davido%20Adeleke&paction=metadata + + it( 'can load metadata', async () => { + const result = await alice.action( 'visualeditor', { page: title, paction: 'metadata' } ); + assert.equal( result.visualeditor.oldid, pageInfo.newrevid ); + } ); + + it( 'able to parse', async () => { + const result = await alice.action( 'visualeditor', { page: title, paction: 'parse' } ); + assert.equal( result.visualeditor.result, 'success' ); + } ); + + it( 'able to parsedoc', async () => { + const result = await alice.action( 'visualeditor', { page: title, paction: 'parsedoc', wikitext: 'test' } ); + assert.equal( result.visualeditor.result, 'success' ); + } ); + + it( 'able to parsefragment', async () => { + const result = await alice.action( 'visualeditor', { page: title, paction: 'parsefragment', wikitext: 'test' } ); + assert.equal( result.visualeditor.result, 'success' ); + } ); + + it( 'templatesUsed', async () => { + const result = await alice.action( 'visualeditor', { page: title, paction: 'templatesused', wikitext: 'test' } ); + assert.include( result.visualeditor, 'Template Requests' ); + } ); + + it( 'can load metadata', async () => { + const result = await alice.action( 'visualeditor', { page: title, paction: 'wikitext' } ); + assert.equal( result.visualeditor.result, 'success' ); + } ); +} );