How to use groupDefinitions method in wpt

Best JavaScript code snippet using wpt

test_mw.echo.dm.CrossWikiNotificationItem.js

Source:test_mw.echo.dm.CrossWikiNotificationItem.js Github

copy

Full Screen

1( function () {2 var defaults = {3 getModelName: 'xwiki',4 getSourceNames: [],5 getCount: 0,6 hasUnseen: false,7 getItems: [],8 isEmpty: true9 };10 QUnit.module( 'ext.echo.dm - mw.echo.dm.CrossWikiNotificationItem' );11 QUnit.test( 'Constructing the model', function ( assert ) {12 var i, method, model,13 cases = [14 {15 params: {16 id: -1,17 config: {}18 },19 expected: defaults,20 msg: 'Default values'21 },22 {23 params: {24 id: -1,25 config: { modelName: 'foo' }26 },27 expected: $.extend( true, {}, defaults, {28 getModelName: 'foo'29 } ),30 msg: 'Overriding model name'31 },32 {33 params: {34 id: -1,35 config: { count: 10 }36 },37 expected: $.extend( true, {}, defaults, {38 getCount: 1039 } ),40 msg: 'Overriding model count'41 }42 ];43 for ( i = 0; i < cases.length; i++ ) {44 model = new mw.echo.dm.CrossWikiNotificationItem(45 cases[ i ].params.id,46 cases[ i ].params.config47 );48 for ( method in defaults ) {49 assert.deepEqual(50 // Method51 model[ method ](),52 // Expected value53 cases[ i ].expected[ method ],54 cases[ i ].msg + ' (' + method + ')'55 );56 }57 }58 } );59 QUnit.test( 'Managing notification lists', function ( assert ) {60 var i, j,61 model = new mw.echo.dm.CrossWikiNotificationItem( 1 ),62 groupDefinitions = [63 {64 name: 'foo',65 sourceData: {66 title: 'Foo Wiki',67 base: 'http://foo.wiki.sample/$1'68 },69 items: [70 new mw.echo.dm.NotificationItem( 0, { source: 'foo', read: false, seen: false, timestamp: '201601010100' } ),71 new mw.echo.dm.NotificationItem( 1, { source: 'foo', read: false, seen: false, timestamp: '201601010200' } ),72 new mw.echo.dm.NotificationItem( 2, { source: 'foo', read: false, seen: false, timestamp: '201601010300' } )73 ]74 },75 {76 name: 'bar',77 sourceData: {78 title: 'Bar Wiki',79 base: 'http://bar.wiki.sample/$1'80 },81 items: [82 new mw.echo.dm.NotificationItem( 3, { source: 'bar', read: false, seen: false, timestamp: '201601020000' } ),83 new mw.echo.dm.NotificationItem( 4, { source: 'bar', read: false, seen: false, timestamp: '201601020100' } ),84 new mw.echo.dm.NotificationItem( 5, { source: 'bar', read: false, seen: false, timestamp: '201601020200' } ),85 new mw.echo.dm.NotificationItem( 6, { source: 'bar', read: false, seen: false, timestamp: '201601020300' } )86 ]87 },88 {89 name: 'baz',90 sourceData: {91 title: 'Baz Wiki',92 base: 'http://baz.wiki.sample/$1'93 },94 items: [95 new mw.echo.dm.NotificationItem( 7, { source: 'baz', timestamp: '201601050100' } )96 ]97 }98 ];99 // Add groups to model100 for ( i = 0; i < groupDefinitions.length; i++ ) {101 model.getList().addGroup(102 groupDefinitions[ i ].name,103 groupDefinitions[ i ].sourceData,104 groupDefinitions[ i ].items105 );106 }107 assert.deepEqual(108 model.getSourceNames(),109 [ 'baz', 'bar', 'foo' ],110 'Model source names exist in order'111 );112 assert.strictEqual(113 model.hasUnseen(),114 true,115 'hasUnseen is true if there are unseen items in any group'116 );117 // Mark all items as seen except one118 for ( i = 0; i < groupDefinitions.length; i++ ) {119 for ( j = 0; j < groupDefinitions[ i ].items.length; j++ ) {120 groupDefinitions[ i ].items[ j ].toggleSeen( true );121 }122 }123 groupDefinitions[ 0 ].items[ 0 ].toggleSeen( false );124 assert.strictEqual(125 model.hasUnseen(),126 true,127 'hasUnseen is true even if only one item in one group is unseen'128 );129 groupDefinitions[ 0 ].items[ 0 ].toggleSeen( true );130 assert.strictEqual(131 model.hasUnseen(),132 false,133 'hasUnseen is false if there are no unseen items in any of the groups'134 );135 // Discard group136 model.getList().removeGroup( 'foo' );137 assert.deepEqual(138 model.getSourceNames(),139 [ 'baz', 'bar' ],140 'Group discarded successfully'141 );142 } );143 QUnit.test( 'Update seen state', function ( assert ) {144 var i, numUnseenItems, numAllItems,145 model = new mw.echo.dm.CrossWikiNotificationItem( 1 ),146 groupDefinitions = [147 {148 name: 'foo',149 sourceData: {150 title: 'Foo Wiki',151 base: 'http://foo.wiki.sample/$1'152 },153 items: [154 new mw.echo.dm.NotificationItem( 0, { source: 'foo', read: false, seen: false, timestamp: '201601010100' } ),155 new mw.echo.dm.NotificationItem( 1, { source: 'foo', read: false, seen: false, timestamp: '201601010200' } ),156 new mw.echo.dm.NotificationItem( 2, { source: 'foo', read: false, seen: false, timestamp: '201601010300' } )157 ]158 },159 {160 name: 'bar',161 sourceData: {162 title: 'Bar Wiki',163 base: 'http://bar.wiki.sample/$1'164 },165 items: [166 new mw.echo.dm.NotificationItem( 3, { source: 'bar', read: false, seen: false, timestamp: '201601020000' } ),167 new mw.echo.dm.NotificationItem( 4, { source: 'bar', read: false, seen: false, timestamp: '201601020100' } ),168 new mw.echo.dm.NotificationItem( 5, { source: 'bar', read: false, seen: false, timestamp: '201601020200' } ),169 new mw.echo.dm.NotificationItem( 6, { source: 'bar', read: false, seen: false, timestamp: '201601020300' } )170 ]171 },172 {173 name: 'baz',174 sourceData: {175 title: 'Baz Wiki',176 base: 'http://baz.wiki.sample/$1'177 },178 items: [179 new mw.echo.dm.NotificationItem( 7, { source: 'baz', timestamp: '201601050100' } )180 ]181 }182 ];183 // Count all actual items184 numAllItems = groupDefinitions.reduce( function ( prev, curr ) {185 return prev + curr.items.length;186 }, 0 );187 // Add groups to model188 for ( i = 0; i < groupDefinitions.length; i++ ) {189 model.getList().addGroup(190 groupDefinitions[ i ].name,191 groupDefinitions[ i ].sourceData,192 groupDefinitions[ i ].items193 );194 }195 numUnseenItems = model.getItems().filter( function ( item ) {196 return !item.isSeen();197 } ).length;198 assert.strictEqual(199 numUnseenItems,200 numAllItems,201 'Starting state: all items are unseen'202 );203 // Update seen time to be bigger than 'foo' but smaller than the other groups204 model.updateSeenState( '201601010400' );205 numUnseenItems = model.getItems().filter( function ( item ) {206 return !item.isSeen();207 } ).length;208 assert.strictEqual(209 numUnseenItems,210 numAllItems - groupDefinitions[ 0 ].items.length,211 'Only some items are seen'212 );213 // Update seen time to be bigger than all214 model.updateSeenState( '201701010000' );215 numUnseenItems = model.getItems().filter( function ( item ) {216 return !item.isSeen();217 } ).length;218 assert.strictEqual(219 numUnseenItems,220 0,221 'All items are seen'222 );223 } );224 QUnit.test( 'Emit discard event', function ( assert ) {225 var i,226 results = [],227 model = new mw.echo.dm.CrossWikiNotificationItem( -1 ),228 groupDefinitions = [229 {230 name: 'foo',231 sourceData: {232 title: 'Foo Wiki',233 base: 'http://foo.wiki.sample/$1'234 },235 items: [236 new mw.echo.dm.NotificationItem( 0, { source: 'foo', read: false, seen: false, timestamp: '201601010100' } ),237 new mw.echo.dm.NotificationItem( 1, { source: 'foo', read: false, seen: false, timestamp: '201601010200' } ),238 new mw.echo.dm.NotificationItem( 2, { source: 'foo', read: false, seen: false, timestamp: '201601010300' } )239 ]240 },241 {242 name: 'bar',243 sourceData: {244 title: 'Bar Wiki',245 base: 'http://bar.wiki.sample/$1'246 },247 items: [248 new mw.echo.dm.NotificationItem( 3, { source: 'bar', read: false, seen: false, timestamp: '201601020000' } ),249 new mw.echo.dm.NotificationItem( 4, { source: 'bar', read: false, seen: false, timestamp: '201601020100' } ),250 new mw.echo.dm.NotificationItem( 5, { source: 'bar', read: false, seen: false, timestamp: '201601020200' } ),251 new mw.echo.dm.NotificationItem( 6, { source: 'bar', read: false, seen: false, timestamp: '201601020300' } )252 ]253 },254 {255 name: 'baz',256 sourceData: {257 title: 'Baz Wiki',258 base: 'http://baz.wiki.sample/$1'259 },260 items: [261 new mw.echo.dm.NotificationItem( 7, { source: 'baz', timestamp: '201601050100' } )262 ]263 }264 ];265 // Add groups to model266 for ( i = 0; i < groupDefinitions.length; i++ ) {267 model.getList().addGroup(268 groupDefinitions[ i ].name,269 groupDefinitions[ i ].sourceData,270 groupDefinitions[ i ].items271 );272 }273 // Listen to event274 model.on( 'discard', function ( name ) {275 results.push( name );276 } );277 // Trigger278 model.getList().removeGroup( 'foo' ); // [ 'foo' ]279 // Empty a list280 model.getList().getGroupByName( 'baz' ).discardItems( groupDefinitions[ 2 ].items ); // [ 'foo', 'baz' ]281 assert.deepEqual(282 results,283 [ 'foo', 'baz' ],284 'Discard event emitted'285 );286 } );...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools')2const fs = require('fs')3let page = wptools.page('Eiffel Tower').get()4page.then(function (res) {5 let groups = res.data.groupDefinitions()6 fs.writeFileSync('test.json', JSON.stringify(groups, null, 2))7})8{9 "Eiffel Tower": {10 "infobox": {11 "height": "324 m (1,063 ft)",12 "visitors": "7 million (2015)",13 },14 "tables": {15 "Eiffel Tower": {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest(options);5wpt.getLocations(function(err, data) {6 if (err) return console.log(err);7 console.log(JSON.stringify(data));8});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful