[MediaWiki-commits] [Gerrit] mediawiki...Echo[master]: Add proper QUnit tests
jenkins-bot has submitted this change and it was merged. Change subject: Add proper QUnit tests .. Add proper QUnit tests Change-Id: I7a4abf068a32d9cf65eb464eb036f72f319c54ff --- M Resources.php M modules/model/mw.echo.dm.CrossWikiNotificationItem.js M modules/model/mw.echo.dm.NotificationItem.js M modules/model/mw.echo.dm.NotificationsList.js M modules/model/mw.echo.dm.PaginationModel.js A tests/qunit/model/test_mw.echo.dm.BundleNotificationItem.js A tests/qunit/model/test_mw.echo.dm.CrossWikiNotificationItem.js A tests/qunit/model/test_mw.echo.dm.FiltersModel.js A tests/qunit/model/test_mw.echo.dm.NotificationGroupsList.js A tests/qunit/model/test_mw.echo.dm.NotificationItem.js A tests/qunit/model/test_mw.echo.dm.NotificationsList.js A tests/qunit/model/test_mw.echo.dm.PaginationModel.js A tests/qunit/model/test_mw.echo.dm.SeenTimeModel.js A tests/qunit/model/test_mw.echo.dm.SourcePagesModel.js D tests/qunit/viewmodel/test_mw.echo.dm.NotificationsModel.js 15 files changed, 1,354 insertions(+), 273 deletions(-) Approvals: Sbisson: Looks good to me, approved jenkins-bot: Verified diff --git a/Resources.php b/Resources.php index fc2b833..cef2749 100644 --- a/Resources.php +++ b/Resources.php @@ -197,7 +197,8 @@ ), 'dependencies' => array( 'oojs', - 'ext.echo.api' + 'ext.echo.api', // This is required by the UnreadNotificationCounter + 'moment', ), 'messages' => array( 'echo-api-failure', diff --git a/modules/model/mw.echo.dm.CrossWikiNotificationItem.js b/modules/model/mw.echo.dm.CrossWikiNotificationItem.js index eddf484..df57c43 100644 --- a/modules/model/mw.echo.dm.CrossWikiNotificationItem.js +++ b/modules/model/mw.echo.dm.CrossWikiNotificationItem.js @@ -20,6 +20,7 @@ this.foreign = true; this.source = null; this.count = config.count || 0; + this.modelName = config.modelName || 'xwiki'; this.list = new mw.echo.dm.NotificationGroupsList(); diff --git a/modules/model/mw.echo.dm.NotificationItem.js b/modules/model/mw.echo.dm.NotificationItem.js index fdd4d30..2420150 100644 --- a/modules/model/mw.echo.dm.NotificationItem.js +++ b/modules/model/mw.echo.dm.NotificationItem.js @@ -56,7 +56,6 @@ this.foreign = !!config.foreign; this.bundled = !!config.bundled; this.source = config.source || ''; - this.modelName = config.modelName || 'local'; this.iconType = config.iconType; this.iconURL = config.iconURL; diff --git a/modules/model/mw.echo.dm.NotificationsList.js b/modules/model/mw.echo.dm.NotificationsList.js index 67334f6..f2fe681 100644 --- a/modules/model/mw.echo.dm.NotificationsList.js +++ b/modules/model/mw.echo.dm.NotificationsList.js @@ -30,7 +30,7 @@ this.name = config.name || 'local'; this.source = config.source || 'local'; - this.sourceURL = config.sourceURL; + this.sourceURL = config.sourceURL || ''; this.title = config.title || ''; this.fallbackTimestamp = config.timestamp || 0; @@ -68,7 +68,7 @@ /** * @event update -* @param {mw.echo.dm.NotificationItem} items Current items in the list +* @param {mw.echo.dm.NotificationItem[]} items Current items in the list * * The list has been updated */ @@ -179,15 +179,6 @@ */ mw.echo.dm.NotificationsList.prototype.getSource = function () { return this.source; - }; - - /** -* Get the name associated with this list. -* -* @return {string} List name -*/ - mw.echo.dm.NotificationsList.prototype.getName = function () { - return this.name; }; /** diff --git a/modules/model/mw.echo.dm.PaginationModel.js b/modules/model/mw.echo.dm.PaginationModel.js index c116ba5..291410a 100644 --- a/modules/model/mw.echo.dm.PaginationModel.js +++ b/modules/model/mw.echo.dm.PaginationModel.js @@ -20,7 +20,7 @@ OO.EventEmitter.call( this ); this.pagesContinue = []; - this.itemsPerPage = this.itemsPerPage || 25; + this.itemsPerPage = config.itemsPerPage || 25; this.currentPageItemCount = config.currentPageItemCount || this.itemsPerPage; // Set initial page @@ -132,7 +132,7 @@ * @return {string} Previous page continue value */ mw.echo.dm.PaginationModel.prototype.getPrevPageContinue = function () { - return this.pagesContinue[ this.currPageIndex - 1 ]; + return this.pagesContinue[ this.currPageIndex - 1 ] || ''; }; /*
[MediaWiki-commits] [Gerrit] mediawiki...Echo[master]: Add proper QUnit tests
Mooeypoo has uploaded a new change for review. https://gerrit.wikimedia.org/r/311063 Change subject: Add proper QUnit tests .. Add proper QUnit tests Change-Id: I7a4abf068a32d9cf65eb464eb036f72f319c54ff --- A tests/qunit/model/test_mw.echo.dm.NotificationItem.js A tests/qunit/model/test_mw.echo.dm.SourcePagesModel.js 2 files changed, 310 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo refs/changes/63/311063/1 diff --git a/tests/qunit/model/test_mw.echo.dm.NotificationItem.js b/tests/qunit/model/test_mw.echo.dm.NotificationItem.js new file mode 100644 index 000..99ae6f8 --- /dev/null +++ b/tests/qunit/model/test_mw.echo.dm.NotificationItem.js @@ -0,0 +1,139 @@ +( function ( mw, $ ) { + QUnit.module( 'ext.echo.dm - mw.echo.dm.NotificationItem' ); + var fakeData = { + type: 'alert', + read: true, + seen: true, + timestamp: '2016-09-14T23:21:56Z', + content: { + header: 'Your edit on Moai was reverted.', + compactHeader: 'Your edit on Moai was reverted.', + body: 'undo' + }, + iconType: 'revert', + primaryUrl: 'http://dev.wiki.local.wmftest.net:8080/w/index.php?title=Moai&oldid=prev&diff=1978&markasread=2126', + secondaryUrls: [ + { + url: 'http://dev.wiki.local.wmftest.net:8080/wiki/User:RandomUser', + label: 'RandomUser', + icon: 'userAvatar' + }, + { + url: 'http://dev.wiki.local.wmftest.net:8080/wiki/Talk:Moai', + label: 'Moai', + tooltip: 'Talk:Moai', + icon: 'speechBubbles' + } + ] + }; + + QUnit.test( 'Constructing items', function ( assert ) { + var i, j, itemModel, checkMethods, + defaultValues = { + getId: undefined, + getContentHeader: '', + getContentBody: '', + getCategory: '', + getType: 'message', + isRead: false, + isSeen: false, + isForeign: false, + isBundled: false, + // getTimestamp: moment.utc().format( '-MM-DD[T]HH:mm:ss[Z]' ); + getPrimaryUrl: undefined, + getIconURL: undefined, + getIconType: undefined, + getSecondaryUrls: [], + getModelName: 'local', + getAllIds: [] + }, + tests = [ + { + msg: 'Empty data', + params: { id: 0, config: {} }, + tests: 'all', + expected: $.extend( true, {}, defaultValues, { getId: 0, getAllIds: [ 0 ] } ) + }, + { + msg: 'Fake data', + params: { id: 999, config: fakeData }, + tests: 'all', + expected: $.extend( true, {}, defaultValues, { + getId: 999, + getAllIds: [ 999 ], + getType: 'alert', + isRead: true, + isSeen: true, + getTimestamp: '2016-09-14T23:21:56Z', + getContentHeader: 'Your edit on Moai was reverted.', + getContentBody: 'undo', + getIconType: 'revert', + getPrimaryUrl: 'http://dev.wiki.local.wmftest.net:8080/w/index.php?title=Moai&oldid=prev&diff=1978&markasread=2126', + getSecondaryUrls: [ +