Jhernandez has uploaded a new change for review.
https://gerrit.wikimedia.org/r/171551
Change subject: WikiGrokDialog UI tests
......................................................................
WikiGrokDialog UI tests
Tests for the views, steps and the html.
Change-Id: I45bc944204a3cecf4f368cdd6579d07c9b090146
---
M tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
1 file changed, 103 insertions(+), 6 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/51/171551/1
diff --git a/tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
b/tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
index e742286..c53ddd3 100644
--- a/tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
+++ b/tests/qunit/modules/wikigrok/test_WikiGrokDialog.js
@@ -1,15 +1,37 @@
( function ( $, M ) {
- var WikiGrokDialog = M.require( 'modules/wikigrok/WikiGrokDialog' );
+ var WikiGrokDialog = M.require( 'modules/wikigrok/WikiGrokDialog' ),
+ WikiDataApi = M.require( 'modules/wikigrok/WikiDataApi' ),
+ WikiGrokResponseApi = M.require(
'modules/wikigrok/WikiGrokResponseApi' ),
+ suggestions = [ {
+ "id": "P106",
+ "name": "occupations",
+ "list": [ "Q285759" ]
+ } ],
+ labels = {
+ Q285759: "insurance broker"
+ },
+ pageTitle = 'Some guy';
QUnit.module( 'MobileFrontend: WikiGrokDialog', {
- setup: function() {
+ teardown: function () {
+ this.wk.remove();
},
- teardown: function() {
+ setup: function () {
+ this.$el = $( '<div id="test">' );
+ this.wk = new WikiGrokDialog( {
+ el: this.$el,
+ itemId: '1234',
+ title: pageTitle,
+ userToken: 'token',
+ testing: false,
+ // Set suggestions to go to the second screen.
+ suggestions: suggestions
+ } );
}
} );
- QUnit.test( 'randomly choose items form array', 7, function( assert ) {
+ QUnit.test( '#chooseRandomItemsFromArray - randomly choose items form
array', 7, function ( assert ) {
var array = [],
chooseRandomItemsFromArray =
WikiGrokDialog.prototype.chooseRandomItemsFromArray;
@@ -19,7 +41,7 @@
'picking 1 element from an array with 0 elements'
);
- array = [1];
+ array = [ 1 ];
assert.strictEqual(
chooseRandomItemsFromArray( array, 1 ).length,
1,
@@ -31,7 +53,7 @@
'picking 2 elements from an array with 1 element'
);
- array = [4, {3: 2}, ['a', 'b', 0], -1];
+ array = [ 4, { 3: 2 }, [ 'a', 'b', 0 ], -1 ];
assert.strictEqual(
chooseRandomItemsFromArray( array, 1 ).length,
1,
@@ -54,4 +76,79 @@
);
} );
+ /**
+ * Debug the wikigrok dialog by showing it in screen
+ * Use in tests like:
+ * debugDialog.apply( this );
+ */
+ /*
+ function debugDialog() {
+ this.wk.remove = function() {};
+ this.wk.prependTo( '#content' ).show();
+ }
+ */
+
+ QUnit.test( '#UI renders initial screen', 4, function ( assert ) {
+ // Lets check that we've got the header, info, buttons and
'Tell me more'
+ assert.strictEqual( this.$el.find( '.wg-header' ).length, 1 );
+ assert.ok( this.$el.find( '.wg-content' ).text().length > 0 );
+ assert.strictEqual( this.$el.find( '.wg-buttons button'
).length, 2 );
+ assert.ok( this.$el.find( '.wg-notice>a' ).attr('href').length
> 0 );
+ } );
+
+ QUnit.test( '#UI clicking no thanks hides the dialog', 1, function (
assert ) {
+ var spy = this.sandbox.stub( WikiGrokDialog.prototype, 'hide' );
+ this.$el.find('.cancel').click();
+ assert.ok( spy.called );
+ } );
+
+ function getToQuestion() {
+ this.sandbox.stub( WikiDataApi.prototype, 'getLabels' )
+ .returns( $.Deferred().resolve( labels ) );
+
+ this.$el.find('.proceed').click();
+ }
+
+ QUnit.test( '#UI clicking OK, takes you to the question dialog', 1,
function ( assert ) {
+ getToQuestion.apply(this);
+ // The name of the page is on the question
+ assert.ok( this.$el.text().indexOf(pageTitle) !== -1 );
+ } );
+
+ function answerQuestion( sel ) {
+ this.sandbox.stub( WikiGrokResponseApi.prototype,
'recordClaims' )
+ .returns( $.Deferred().resolve() );
+ this.$el.find( sel ).click();
+ }
+
+ QUnit.test( '#UI - Question - Click Yes', 2, function ( assert ) {
+ getToQuestion.apply( this );
+
+ answerQuestion.call( this, '.yes' );
+
+ // I'm in thanks page now!
+ assert.equal( this.$el.find( '.wg-link' ).length, 1 );
+ assert.equal( this.$el.find( '.wg-link>a' ).length, 1 );
+ } );
+
+ QUnit.test( '#UI - Question - Click No', 2, function ( assert ) {
+ getToQuestion.apply( this );
+
+ answerQuestion.call( this, '.no' );
+
+ // I'm in thanks page now!
+ assert.equal( this.$el.find( '.wg-link' ).length, 1 );
+ assert.equal( this.$el.find( '.wg-link>a' ).length, 1 );
+ } );
+
+ QUnit.test( '#UI - Question - Click Not sure', 2, function ( assert ) {
+ getToQuestion.apply( this );
+
+ answerQuestion.call( this, '.not-sure' );
+
+ // I'm in thanks page now!
+ assert.equal( this.$el.find( '.wg-link' ).length, 1 );
+ assert.equal( this.$el.find( '.wg-link>a' ).length, 1 );
+ } );
+
}( jQuery, mw.mobileFrontend ) );
--
To view, visit https://gerrit.wikimedia.org/r/171551
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I45bc944204a3cecf4f368cdd6579d07c9b090146
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits