How to use toHaveId method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

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

list-view.js

Source: list-view.js Github

copy
1/*
2 * Copyright 2013-2017 Hewlett Packard Enterprise Development Company, L.P.
3 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
4 */
5
6define([
7    'underscore',
8    'backbone',
9    'js-whatever/js/list-view',
10    'js-testing/backbone-mock-factory'
11], function(_, Backbone, ListView, mockFactory) {
12    'use strict';
13
14    var itemTemplate = _.template('<p id="item-<%=data.id%>" class="<%=className%>"><%-data.age%></p>');
15    var itemTemplateOptions = {className: 'my-class'};
16
17    describe('List view', function() {
18        beforeEach(function() {
19            this.collection = new Backbone.Collection([
20                {id: 'Fred', age: 32},
21                {id: 'George', age: 46}
22            ], {comparator: 'age'});
23        });
24
25        it('should call the correct method on the correct ItemView on model change events when constructed with a collectionChangeEvents map', function() {
26            var ItemView = mockFactory.getView(['changeAge']);
27
28            var listView = new ListView({
29                collection: this.collection,
30                collectionChangeEvents: {age: 'changeAge'},
31                ItemView: ItemView
32            });
33
34            listView.render();
35
36            this.collection.get('Fred').set('age', 33);
37
38            var fredView = ItemView.instances[0];
39            expect(fredView.constructorArgs[0].model.id).toEqual('Fred');
40            expect(fredView.changeAge).toHaveBeenCalled();
41
42            expect(ItemView.instances[1].changeAge).not.toHaveBeenCalled();
43        });
44
45        it('should display the headerHtml before the ItemViews if specified', function() {
46            var listView = new ListView({
47                collection: this.collection,
48                headerHtml: '<option>funky</option><option>monkey</option>',
49                itemOptions: {
50                    tagName: 'option',
51                    template: _.template('<%=data.id%>')
52                }
53            });
54
55            listView.render();
56
57            var $options = listView.$('option');
58            expect($options).toHaveLength(4);
59            expect($options.eq(0)).toHaveText('funky');
60            expect($options.eq(1)).toHaveText('monkey');
61            expect($options.eq(2)).toHaveText('Fred');
62            expect($options.eq(3)).toHaveText('George');
63
64            this.collection.comparator = function(model) {
65                return -model.get('age');
66            };
67
68            this.collection.sort();
69
70            $options = listView.$('option');
71            expect($options).toHaveLength(4);
72            expect($options.eq(0)).toHaveText('funky');
73            expect($options.eq(1)).toHaveText('monkey');
74            expect($options.eq(2)).toHaveText('George');
75            expect($options.eq(3)).toHaveText('Fred');
76        });
77
78        it('displays the footerHtml after the ItemViews if specified', function() {
79            var listView = new ListView({
80                collection: this.collection,
81                footerHtml: '<option>Penultimate Option</option><option>THE ULTIMATE OPTION</option>',
82                itemOptions: {
83                    tagName: 'option',
84                    template: _.template('<%=data.id%>')
85                }
86            });
87
88            listView.render();
89
90            var $options = listView.$('option');
91            expect($options).toHaveLength(4);
92            expect($options.eq(0)).toHaveText('Fred');
93            expect($options.eq(1)).toHaveText('George');
94            expect($options.eq(2)).toHaveText('Penultimate Option');
95            expect($options.eq(3)).toHaveText('THE ULTIMATE OPTION');
96
97            this.collection.add({id: 'Penny', age: 75});
98
99            expect(listView.$('option').eq(2)).toHaveText('Penny');
100
101            this.collection.get('Penny').set('age', 22);
102            this.collection.sort();
103
104            $options = listView.$('option');
105            expect($options).toHaveLength(5);
106            expect($options.eq(0)).toHaveText('Penny');
107            expect($options.eq(1)).toHaveText('Fred');
108            expect($options.eq(2)).toHaveText('George');
109            expect($options.eq(3)).toHaveText('Penultimate Option');
110            expect($options.eq(4)).toHaveText('THE ULTIMATE OPTION');
111        });
112
113        it('handles a collection remove event before rendering', function() {
114            var list = new ListView({
115                collection: this.collection,
116                itemOptions: {
117                    template: itemTemplate,
118                    templateOptions: itemTemplateOptions
119                }
120            });
121
122            this.collection.remove('Fred');
123            list.render();
124
125            expect(list.$('p')).toHaveLength(1);
126        });
127
128        it('handles a collection sort event before rendering', function() {
129            this.collection.get('Fred').set('age', 50);
130
131            var list = new ListView({
132                collection: this.collection,
133                itemOptions: {
134                    template: itemTemplate,
135                    templateOptions: itemTemplateOptions
136                }
137            });
138
139            this.collection.sort();
140            list.render();
141
142            var $ps = list.$('p');
143            expect($ps).toHaveLength(2);
144            expect($ps.eq(0)).toHaveId('item-George');
145            expect($ps.eq(1)).toHaveId('item-Fred');
146        });
147
148        it('handles a collection change event before rendering', function() {
149            var list = new ListView({
150                collection: this.collection,
151                itemOptions: {
152                    template: itemTemplate,
153                    templateOptions: itemTemplateOptions
154                }
155            });
156
157            this.collection.get('Fred').set('age', 33);
158            list.render();
159
160            expect(list.$('#item-Fred')).toHaveText('33');
161        });
162
163        describe('with default ItemView and no headerHtml', function() {
164            beforeEach(function() {
165                this.list = new ListView({
166                    collection: this.collection,
167                    itemOptions: {
168                        template: itemTemplate,
169                        templateOptions: itemTemplateOptions
170                    }
171                });
172
173                this.list.render();
174            });
175
176            it('should populate itself with existing collection items on initialize and render', function() {
177                var $ps = this.list.$('p');
178                expect($ps).toHaveLength(2);
179                expect($ps).toHaveClass('my-class');
180
181                expect($ps.eq(0)).toHaveText('32');
182                expect($ps.eq(0)).toHaveId('item-Fred');
183                expect($ps.eq(1)).toHaveText('46');
184                expect($ps.eq(1)).toHaveId('item-George');
185            });
186
187            it('should set a data-id attribute on each item', function() {
188                expect(this.list.$el.children().eq(0)).toHaveAttr('data-id', 'Fred');
189            });
190
191            it('should respond to collection "add" events', function() {
192                this.collection.add({id: 'Penny', age: 26});
193
194                var $ps = this.list.$('p');
195                expect($ps).toHaveLength(3);
196                expect($ps).toHaveClass('my-class');
197
198                expect($ps.eq(0)).toHaveText('26');
199                expect($ps.eq(0)).toHaveId('item-Penny');
200
201                this.collection.add({id: 'Polly', age: 65});
202
203                expect(this.list.$('p').eq(3)).toHaveId('item-Polly');
204            });
205
206            it('should respond to collection "remove" events', function() {
207                this.collection.remove(this.collection.get('Fred'));
208
209                var $ps = this.list.$('p');
210                expect($ps).toHaveLength(1);
211                expect($ps).toHaveText('46');
212                expect($ps).toHaveId('item-George');
213            });
214
215            it('should respond to collection "change" events', function() {
216                this.collection.get('Fred').set('age', 33);
217
218                var $ps = this.list.$('p');
219                expect($ps).toHaveLength(2);
220
221                var $p = $ps.filter('#item-Fred');
222                expect($p).toHaveText('33');
223            });
224
225            it('should respond to collection "sort" events', function() {
226                this.collection.get('Fred').set('age', 105);
227                this.collection.sort();
228
229                var $ps = this.list.$('p');
230                expect($ps.eq(0)).toHaveId('item-George');
231                expect($ps.eq(1)).toHaveId('item-Fred');
232            });
233
234            it('should respond to collection "reset" events', function() {
235                this.collection.reset([{id: 'Adrian', age: 106}]);
236
237                expect(this.list.$('p')).toHaveLength(1);
238                expect(this.list.$('p')).toHaveId('item-Adrian');
239            });
240        });
241
242        describe('with default ItemView and no headerHtml and a maxSize parameter', function() {
243            beforeEach(function() {
244                this.list = new ListView({
245                    collection: this.collection,
246                    maxSize: 1,
247                    itemOptions: {
248                        template: itemTemplate,
249                        templateOptions: itemTemplateOptions
250                    }
251                });
252
253                this.list.render();
254            });
255
256            it('should populate itself with existing collection items on initialize and render', function() {
257                var $ps = this.list.$('p');
258                expect($ps).toHaveLength(1);
259                expect($ps).toHaveClass('my-class');
260
261                expect($ps.eq(0)).toHaveText('32');
262                expect($ps.eq(0)).toHaveId('item-Fred');
263            });
264
265            it('should set a data-id attribute on each item', function() {
266                expect(this.list.$el.children().eq(0)).toHaveAttr('data-id', 'Fred');
267            });
268
269            it('should respond to collection "add" events', function() {
270                this.collection.add({id: 'Penny', age: 26});
271
272                var $ps = this.list.$('p');
273                expect($ps).toHaveLength(1);
274                expect($ps).toHaveClass('my-class');
275
276                expect($ps.eq(0)).toHaveText('26');
277                expect($ps.eq(0)).toHaveId('item-Penny');
278
279                // this one goes at the end, so no DOM change
280                this.collection.add({id: 'Polly', age: 65});
281
282                var $ps2 = this.list.$('p');
283                expect($ps2).toHaveLength(1);
284                expect($ps2).toHaveClass('my-class');
285
286                expect($ps2.eq(0)).toHaveText('26');
287                expect($ps2.eq(0)).toHaveId('item-Penny');
288            });
289
290            it('should respond to collection "remove" events', function() {
291                this.collection.remove(this.collection.get('Fred'));
292
293                var $ps = this.list.$('p');
294                expect($ps).toHaveLength(1);
295                expect($ps).toHaveText('46');
296                expect($ps).toHaveId('item-George');
297            });
298
299            it('should respond to collection "change" events', function() {
300                this.collection.get('Fred').set('age', 33);
301
302                var $ps = this.list.$('p');
303                expect($ps).toHaveLength(1);
304
305                var $p = $ps.filter('#item-Fred');
306                expect($p).toHaveText('33');
307            });
308
309            it('should respond to collection "sort" events', function() {
310                this.collection.get('Fred').set('age', 105);
311                this.collection.sort();
312
313                var $ps = this.list.$('p');
314                expect($ps.eq(0)).toHaveId('item-George');
315            });
316
317            it('should respond to collection "reset" events', function() {
318                this.collection.reset([{id: 'Adrian', age: 106}]);
319
320                expect(this.list.$('p')).toHaveLength(1);
321                expect(this.list.$('p')).toHaveId('item-Adrian');
322            });
323        });
324
325        describe('with event proxying', function() {
326            beforeEach(function() {
327                this.ItemView = mockFactory.getView();
328
329                this.listView = new ListView({
330                    collection: this.collection,
331                    ItemView: this.ItemView,
332                    proxyEvents: ['my-event']
333                });
334
335                this.listView.render();
336
337                var eventArguments = this.eventArguments = [];
338
339                this.listView.on('item:my-event', function() {
340                    eventArguments.push(_.toArray(arguments));
341                });
342            });
343
344            it('should proxy ItemView events specified in the proxyEvents option', function() {
345                this.ItemView.instances[1].trigger('my-event', 123, 'abc');
346
347                expect(this.eventArguments.length).toBe(1);
348                expect(this.eventArguments[0]).toEqual([123, 'abc']);
349            });
350
351            it('should stop proxying events when the ItemView is removed', function() {
352                this.collection.remove(this.collection.at(0));
353                this.ItemView.instances[0].trigger('my-event', 123);
354
355                expect(this.eventArguments.length).toBe(0);
356
357                this.ItemView.instances[1].trigger('my-event', 123);
358
359                expect(this.eventArguments.length).toBe(1);
360            });
361
362            it('should stop proxying events when the ListView is removed', function() {
363                this.listView.remove();
364
365                this.ItemView.instances[0].trigger('my-event');
366                this.ItemView.instances[1].trigger('my-event');
367
368                expect(this.eventArguments.length).toBe(0);
369            });
370        });
371    });
372});
373
Full Screen

inventory.test.js

Source: inventory.test.js Github

copy
1const InventoryPage = require('../pageobjects/inventory.page');
2
3const LoginPage = require('../pageobjects/login.page');
4
5describe('Sauce Demo Test - 1 (standard_user)', () => {
6    beforeEach('browser pause', ()=> {
7        browser.pause(1000)
8    });
9    it('allow access', () => {
10        LoginPage.open()
11        LoginPage.username.setValue('standard_user')
12        LoginPage.password.setValue('secret_sauce')
13        LoginPage.login()
14
15        browser.pause(1000)
16        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory.html')
17    });
18    it('test \'sorting\' filters - A to Z', ()=> {
19        InventoryPage.sortMenu.click()
20        InventoryPage.sortByNameAZ.click()
21        browser.pause(1000)
22
23        expect(InventoryPage.firstItem).toHaveId('item_4_title_link')
24        expect(InventoryPage.secondItem).toHaveId('item_0_title_link')
25        expect(InventoryPage.thirdItem).toHaveId('item_1_title_link')
26        expect(InventoryPage.fourthItem).toHaveId('item_5_title_link')
27        expect(InventoryPage.fifthItem).toHaveId('item_2_title_link')
28        expect(InventoryPage.sixthItem).toHaveId('item_3_title_link')
29    });
30    it('test \'sorting\' filters - Z to A', ()=> {
31        InventoryPage.sortMenu.click()
32        InventoryPage.sortByNameZA.click()
33        browser.pause(1000)
34
35        expect(InventoryPage.firstItem).toHaveId('item_3_title_link') 
36        expect(InventoryPage.secondItem).toHaveId('item_2_title_link')
37        expect(InventoryPage.thirdItem).toHaveId('item_5_title_link')
38        expect(InventoryPage.fourthItem).toHaveId('item_1_title_link')
39        expect(InventoryPage.fifthItem).toHaveId('item_0_title_link')
40        expect(InventoryPage.sixthItem).toHaveId('item_4_title_link')
41    });
42    it('test \'sorting\' filters - Low to High', ()=> {
43        InventoryPage.sortMenu.click()
44        InventoryPage.sortByLowToHigh.click()
45        browser.pause(1000)
46
47        expect(InventoryPage.firstItem).toHaveId('item_2_title_link')
48        expect(InventoryPage.secondItem).toHaveId('item_0_title_link')
49        expect(InventoryPage.thirdItem).toHaveId('item_1_title_link')
50        expect(InventoryPage.fourthItem).toHaveId('item_3_title_link')
51        expect(InventoryPage.fifthItem).toHaveId('item_4_title_link')
52        expect(InventoryPage.sixthItem).toHaveId('item_5_title_link')
53    });
54    it('test \'sorting\' filters - High to Low', ()=> {
55        InventoryPage.sortMenu.click()
56        InventoryPage.sortByHighToLow.click()
57        browser.pause(1000)
58
59        expect(InventoryPage.firstItem).toHaveId('item_5_title_link')
60        expect(InventoryPage.secondItem).toHaveId('item_4_title_link')
61        expect(InventoryPage.thirdItem).toHaveId('item_1_title_link')
62        expect(InventoryPage.fourthItem).toHaveId('item_3_title_link')
63        expect(InventoryPage.fifthItem).toHaveId('item_0_title_link')
64        expect(InventoryPage.sixthItem).toHaveId('item_2_title_link')
65    });
66    it('testing access to item\'s description page by title-click', ()=> {
67        InventoryPage.bpackDescrBtn.click()
68
69        browser.pause(1000)
70        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=4')
71
72        InventoryPage.backToProducts()
73        browser.pause(1000)
74    
75        InventoryPage.backlightDescrBtn.click()
76        browser.pause(1000)
77        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=0')
78
79        InventoryPage.backToProducts()
80        browser.pause(1000)
81
82        InventoryPage.boltTshirtDescrBtn.click()
83        browser.pause(1000)
84        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=1')
85
86        InventoryPage.backToProducts()
87        browser.pause(1000)
88
89        InventoryPage.jacketDescrBtn.click()
90        browser.pause(1000)
91        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=5')
92
93        InventoryPage.backToProducts()
94        browser.pause(1000)
95
96        InventoryPage.onesieDescrBtn.click()
97        browser.pause(1000)
98        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=2')
99
100        InventoryPage.backToProducts()
101        browser.pause(1000)
102
103        InventoryPage.redTshirtDescrBtn.click()
104        browser.pause(1000)
105        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=3')
106    });
107    it('testing access to item\'s description page by img-click', ()=> {
108        InventoryPage.backToProducts()
109        InventoryPage.bpackImgBtn.click()
110
111        browser.pause(1000)
112        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=4')
113
114        InventoryPage.backToProducts()
115        browser.pause(1000)
116    
117        InventoryPage.backlightImgBtn.click()
118        browser.pause(1000)
119        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=0')
120
121        InventoryPage.backToProducts()
122        browser.pause(1000)
123
124        InventoryPage.boltTshirtImgBtn.click()
125        browser.pause(1000)
126        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=1')
127
128        InventoryPage.backToProducts()
129        browser.pause(1000)
130
131        InventoryPage.jacketImgBtn.click()
132        browser.pause(1000)
133        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=5')
134
135        InventoryPage.backToProducts()
136        browser.pause(1000)
137
138        InventoryPage.onesieImgBtn.click()
139        browser.pause(1000)
140        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=2')
141
142        InventoryPage.backToProducts()
143        browser.pause(1000)
144
145        InventoryPage.redTshirtImgBtn.click()
146        browser.pause(1000)
147        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=3')
148    });
149    it('testing access to shopping cart', ()=> {
150        InventoryPage.cartBtn.click()
151        browser.pause(1500)
152        InventoryPage.contShoppBtn.click()
153        browser.pause(1000)
154    });
155    it('testing adding/removing products to cart from item\'s description page', ()=> {
156        InventoryPage.bpackImgBtn.click()
157        InventoryPage.addBackpack.click()
158        browser.pause(1000)
159        InventoryPage.backToProducts()
160
161        InventoryPage.backlightImgBtn.click()
162        InventoryPage.addBikelight.click()
163        browser.pause(1000)
164        InventoryPage.backToProducts()
165
166        InventoryPage.cartBtn.click()
167        browser.pause(2000)
168
169        expect(InventoryPage.bpackDescrBtn).toExist
170        expect(InventoryPage.backlightDescrBtn).toExist
171
172        InventoryPage.removeBackpack.click()
173        browser.pause(1000)
174        InventoryPage.removeBikelight.click()
175        browser.pause(1000)
176
177        expect(InventoryPage.bpackDescrBtn).not.toExist
178        expect(InventoryPage.backlightDescrBtn).not.toExist
179        browser.pause(1000)
180
181        InventoryPage.contShoppBtn.click()
182        browser.pause(1000)
183    });
184    it('testing adding/removing products to cart from Inventory page', ()=> {
185        InventoryPage.addBackpack.click()
186        browser.pause(1000)
187        InventoryPage.addBikelight.click()
188        browser.pause(1000)
189
190        InventoryPage.cartBtn.click()
191        browser.pause(2000)
192
193        expect(InventoryPage.bpackDescrBtn).toExist
194        expect(InventoryPage.backlightDescrBtn).toExist
195
196        InventoryPage.removeBackpack.click()
197        browser.pause(1000)
198        InventoryPage.removeBikelight.click()
199        browser.pause(1000)
200
201        expect(InventoryPage.bpackDescrBtn).not.toExist
202        expect(InventoryPage.backlightDescrBtn).not.toExist
203        browser.pause(1000)
204
205        InventoryPage.contShoppBtn.click()
206        browser.pause(1000)
207    });
208})
209
210describe('Sauce Demo Test - 2 (problem_user)', () => {
211    it('allow access', () => {
212        LoginPage.open()
213        LoginPage.username.setValue('problem_user')
214        LoginPage.password.setValue('secret_sauce')
215        LoginPage.login()
216
217        browser.pause(1000)
218        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory.html')
219    });
220})
221
222describe('Sauce Demo Test - 3 (performance_glitch_user)', () => {
223    it('allow access', () => {
224        LoginPage.open()
225        LoginPage.username.setValue('performance_glitch_user')
226        LoginPage.password.setValue('secret_sauce')
227        LoginPage.login()
228
229        browser.pause(1000)
230        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory.html')
231    });
232    it('testing item\'s description page working correctly', ()=> {
233        InventoryPage.bpackDescrBtn.click()
234
235        browser.pause(2000)
236        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=4')
237
238        InventoryPage.backToProducts()
239        browser.pause(2000)
240
241        InventoryPage.backlightDescrBtn.click()
242        browser.pause(2000)
243        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=0')
244
245        InventoryPage.backToProducts()
246        browser.pause(2000)
247
248        InventoryPage.boltTshirtDescrBtn.click()
249        browser.pause(2000)
250        expect(browser).toHaveUrl('https://www.saucedemo.com/inventory-item.html?id=1')
251
252        InventoryPage.backToProducts()
253        browser.pause(2000)
254    });
255})
Full Screen

inventory_test.js

Source: inventory_test.js Github

copy
1describe("inventory", function() {
2
3  require(['inventory/Beans',
4           'inventory/Medkit',
5           'inventory/Shotgun'], function () {});
6
7  // because we fake double clicks
8  function doubleClickThen(node, callback) {
9    node.click();
10    node.click();
11
12    waits(300);
13
14    runs(callback);
15  }
16
17  beforeEach(function () {
18    $('.back').click();
19    $('#resume').click();
20
21    clearSprites();
22
23    $dudeInventory = $('#dude-inventory');
24    $dudeInventory.css('visibility', 'visible');
25
26    Game.dude.inventory.clear();
27    Game.dude.hands.clear();
28  });
29
30  it("opens and closes when i is pressed", function () {
31    $dudeInventory.css('visibility', 'hidden');
32    pressKey('i');
33
34    waits(100);
35    runs(function () {
36      expect($dudeInventory.css('visibility')).toEqual('visible');
37
38      pressKey('i');
39
40      waits(100);
41      runs(function () {
42        expect($dudeInventory.css('visibility')).toEqual('hidden');
43      });
44    });
45  });
46
47  it("moves an item to an open hand when double-clicked", function () {
48    Cheat.give('Beans');
49    var beanz = $('.inventory-item:first');
50    expect(beanz.parents('table.inventory')).not.toHaveId('dude-hands');
51
52    doubleClickThen(beanz, function () {
53      expect(beanz).toBeVisible();
54      expect(beanz.parents('table.inventory')).toHaveId('dude-hands');
55    });
56  });
57
58  it("moves an item back to the inventory when double clicks in the hands", function () {
59    var canOBeans = createItem('Beans');
60    Game.dude.hands.stuffItemIn(canOBeans);
61
62    var beanz = $('.inventory-item:first');
63
64    expect(beanz.parents('table.inventory')).toHaveId('dude-hands');
65
66    doubleClickThen(beanz, function () {
67      expect(beanz).toBeVisible();
68      expect(beanz.parents('table.inventory')).not.toHaveId('dude-hands');
69    });
70  });
71
72  it("doesn't move an item on double click if it can't fit in the hands", function () {
73    var medkit = createItem('Medkit');
74    Game.dude.hands.stuffItemIn(medkit);
75
76    Cheat.give('Beans');
77    var beanz = $('.inventory-item:first');
78    expect(beanz.parents('table.inventory')).not.toHaveId('dude-hands');
79
80    doubleClickThen(beanz, function () {
81      expect(beanz).toBeVisible();
82      expect(beanz.parents('table.inventory')).not.toHaveId('dude-hands');
83    });
84  });
85
86  it("doesn't move an item back from the hands on double click if the inventory has no room", function () {
87    // fill that inventory
88    var i;
89    for (i = 0; i < 3; i++) {
90      Cheat.give('Shotgun');
91    }
92
93    var medkit = createItem('Medkit');
94    Game.dude.hands.stuffItemIn(medkit);
95
96    var medkitNode = $('#dude-hands .inventory-item:first');
97
98    doubleClickThen(medkitNode, function () {
99      expect(medkitNode).toBeVisible();
100      expect(medkitNode.parents('table.inventory')).toHaveId('dude-hands');
101    });
102  });
103
104  it("removes the item from the inventory when it is clicked on", function () {
105    Cheat.give('Beans');
106
107    var beanz = $('.inventory-item:first');
108
109    waitsFor(function () {
110      return beanz.is(":visible");
111    }, 100);
112
113    runs(function () {
114      var offset = beanz.offset();
115
116      simulateClick(offset.left + 20, offset.top + 20);
117
118      waits(300);
119
120      runs(function () {
121        var Beans = require('inventory/Beans');
122        expect(Game.dude.inventory.findItem(Beans)).toBeUndefined();
123        expect($("img.click-dragging[src*='beans']")).toExist();
124      });
125    });
126  });
127
128  it("is hidden when a new game is created", function () {
129    $dudeInventory.css('visibility', 'hidden');
130    pressKey('i');
131
132    waits(100);
133    runs(function () {
134      expect($dudeInventory.css('visibility')).toEqual('visible');
135
136      startNewGame();
137
138      waits(300);
139
140      runs(function () {
141        $('#intro-screen').click();
142        expect($dudeInventory.css('visibility')).toEqual('hidden');
143      });
144    });
145  });
146
147});
148
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)