How to use insertBefore 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.

game.js

Source: game.js Github

copy
1// JavaScript Document
2
3//
4//SETS ALL VARIABLES FOR THE GAME
5//
6cellunlocked = false;
7beentohallway = false;
8beentorture = false;
9beenmorgue = false;
10beentowesthall = false;
11beentobonus = false;
12exitunlocked = false;
13beentoexit = false;
14//inventory
15paperclip = false;
16deadbugs = false;
17lunchtray = false;
18torch = false;
19note = false;
20knife = false;
21hat = false;
22whip = false;
23key = false;
24powder = false;
25//
26currentroom = "jail";
27searchtable = false;
28crate = false;
29zombiedead = false;
30//
31//
32//
33$(document).ready(function() {
34	$("#compass").fadeIn(3000);
35	$("#message_begin").fadeIn(3000);
36	$("#area_main").fadeIn(3000);
37	$("#command_line").fadeIn(3000);
38	$("form").submit(function() {
39		var input = $("#command_line").val();
40		
41		
42		
43		
44		
45		
46		//
47		//help
48		//
49		if (input.indexOf("help") > -1) {
50			if (input == "help") {
51				$("#message_help").clone().insertBefore("#placeholder").fadeIn(1000);
52			}
53		}
54		//
55		//end help
56		//
57		
58		
59		
60		
61		
62		
63		//
64		//take
65		//
66		else if (input.indexOf("take") > -1 || input.indexOf("read") > -1) {
67			
68			if (input == "take") {
69				$('<p>Take what? Be specific. Type "help" for a list of all commands.</p>').insertBefore("#placeholder").fadeIn(1000);
70			}
71			
72			//paperclip
73			else if (input == "take paperclip" || input == "take paper clip") {
74				if (currentroom == "jail" && paperclip == false) {
75					paperclip = true;
76					$('<p>You picked up a paper clip.</p>').insertBefore("#placeholder").fadeIn(1000);
77				}
78				else $('<p>That item is not here!</p>').insertBefore("#placeholder").fadeIn(1000);
79			}
80			//
81			
82			//dead bugs
83			else if (input == "take dead bugs" || input == "take deadbugs") {
84				if (currentroom == "jail" && deadbugs == false) {
85					deadbugs = true;
86					$('<p>You picked up some dead bugs. Gross.</p>').insertBefore("#placeholder").fadeIn(1000);
87				}
88				else $('<p>That item is not here!</p>').insertBefore("#placeholder").fadeIn(1000);
89			}
90			//
91			
92			//lunch tray
93			else if (input == "take lunchtray" || input == "take lunch tray" || input == "take tray") {
94				if (currentroom == "jail" && lunchtray == false) {
95					lunchtray = true;
96					$('<p>You picked up a lunch tray.</p>').insertBefore("#placeholder").fadeIn(1000);
97				}
98				else $('<p>That item is not here!</p>').insertBefore("#placeholder").fadeIn(1000);
99			}
100			//
101			
102			//torch
103			else if (input == "take torch") {
104				if (currentroom == "hallway" && torch == false) {
105					torch = true;
106					$('<p>You picked up a torch. You can now venture off into the dark hallway.</p>').insertBefore("#placeholder").fadeIn(1000);
107				}
108				else $('<p>That item is not here!</p>').insertBefore("#placeholder").fadeIn(1000);
109			}
110			//
111			
112			//note
113			else if (input == "take note" || input == "read note") {
114				if (currentroom == "hallway" && note == false) {
115					note = true;
116					$('<p>You picked up a note. It reads: <br />Well now. It seems you have managed to pass your first test. Don\'t worry. Things will get plenty more difficult and it will be almost impossible for you to escape with your life.<br /><br />Sincerely,<br/>Your Captors<br /><br />P.S. Watch out for my zombie.</p>').insertBefore("#placeholder").fadeIn(1000);
117				}
118				else $('<p>That item is not here!</p>').insertBefore("#placeholder").fadeIn(1000);
119			}
120			//
121			
122			//whip
123			else if (input == "take whip") {
124				if (currentroom == "torture" && whip == false) {
125					whip = true;
126					$('<p>You picked up a whip.</p>').insertBefore("#placeholder").fadeIn(1000);
127					if (whip == true && hat == true) {
128						$('<p>A whip and a hat? This is no time to play Indiana Jones!</p>').insertBefore("#placeholder").fadeIn(1000);
129					}
130				}
131				else $('<p>That item is not here!</p>').insertBefore("#placeholder").fadeIn(1000);
132			}
133			//
134
135			else $('<p>You can\'t do that.</p>').insertBefore("#placeholder").fadeIn(1000);
136		
137		}
138		//
139		//end take
140		//
141		
142		
143		
144		
145		
146		//
147		//search
148		//
149		else if (input.indexOf("search") > -1) {
150			
151			if (input == "search") {
152				$('<p>Search what? Be specific. Type "help" for a list of all commands.</p>').insertBefore("#placeholder").fadeIn(1000);
153			}
154			
155			//table
156			else if (input == "search table") {
157				if (currentroom == "torture" && hat == false && knife == false) {
158					hat = true;
159					knife = true;
160					searchtable = true;
161					$('<p>You found a knife stuck in the table and picked it up. You also take a hat from the table and place it on your head.</p>').insertBefore("#placeholder").fadeIn(1000);
162					if (whip == true && hat == true) {
163						$('<p>A whip and a hat? This is no time to play Indiana Jones!</p>').insertBefore("#placeholder").fadeIn(1000);
164					}
165						
166				}
167				else $('<p>There is nothing to search for.</p>').insertBefore("#placeholder").fadeIn(1000);
168			}
169			//
170			
171			//zombie
172			else if (input == "search zombie") {
173				if (currentroom == "morgue" && zombiedead == true) {
174					key = true;
175					$('<p>You found a key buried in the zombie\'s flesh.</p>').insertBefore("#placeholder").fadeIn(1000);
176				}
177				else $('<p>There is nothing to search for.</p>').insertBefore("#placeholder").fadeIn(1000);
178			}
179			//
180			
181			//crate
182			else if (input == "search crate") {
183				if (currentroom == "bonus") {
184					powder = true;
185					$('<p>You found a strange powder. What use could that possibly have?</p>').insertBefore("#placeholder").fadeIn(1000);
186				}
187				else $('<p>There is nothing to search for.</p>').insertBefore("#placeholder").fadeIn(1000);
188			}
189			//
190
191			else $('<p>There is nothing to search for.</p>').insertBefore("#placeholder").fadeIn(1000);
192		
193		}
194		//
195		//end search
196		//
197		
198		
199		
200		
201		//
202		//eat
203		//
204		else if (input.indexOf("eat") > -1) {
205			
206			if (input == "eat") {
207				$('<p>Eat what? Be specific. Type "help" for a list of all commands.</p>').insertBefore("#placeholder").fadeIn(1000);
208			}
209			
210			//powder
211			else if (input == "eat powder" || input == "eat strange powder") {
212				if (powder == true) {
213					$("#container").fadeOut(3000, function() {
214						$("#foodpoisoning").fadeIn(3000);
215					});
216				}
217				else $('<p>You can\'t do that.</p>').insertBefore("#placeholder").fadeIn(1000);
218			}
219			//
220			
221			
222			//bugs
223			else if (input == "eat bugs" || input == "eat dead bugs") {
224				if (deadbugs == true) {
225					$('<p>You did not just do that.</p>').insertBefore("#placeholder").fadeIn(1000);
226					deadbugs = "ate";
227				}
228				else $('<p>You can\'t do that.</p>').insertBefore("#placeholder").fadeIn(1000);
229			}
230			//
231			
232			else $('<p>I don\'t understand "' + input + '</p>').insertBefore("#placeholder").fadeIn(1000);
233		
234		}
235		//
236		//end eat
237		//
238		
239		
240		
241		
242		
243		//
244		//kill
245		//
246		else if (input.indexOf("kill") > -1) {
247			
248			if (input == "kill") {
249				$('<p>Kill what with what? Be specific. Type "help" for a list of all commands.</p>').insertBefore("#placeholder").fadeIn(1000);
250			}
251			else if (input == "kill zombie" && currentroom == "morgue") {
252				$('<p>Kill zombie with what?</p>').insertBefore("#placeholder").fadeIn(1000);
253			}
254			
255			//zombie
256			else if (input == "kill zombie with knife") {
257				if (currentroom == "morgue" && knife == true) {
258					$('<p>You attack the zombie with a knife and kill it!</p>').insertBefore("#placeholder").fadeIn(1000);
259					zombiedead = true;
260				}
261				else {
262					$('<p>You can\'t do that.</p>').insertBefore("#placeholder").fadeIn(1000);
263				}
264			}
265					
266			else if (input == "kill zombie with lunch tray" || input == "kill zombie with lunchtray" || input == "kill zombie with tray") {
267				if (currentroom == "morgue" && lunchtray == true) {
268					$('<p>You attack the zombie with a lunch tray and kill it!</p>').insertBefore("#placeholder").fadeIn(1000);
269					zombiedead = true;
270				}
271				else {
272					$('<p>You can\'t do that.</p>').insertBefore("#placeholder").fadeIn(1000);
273				}
274			}
275			//
276			
277			//kill self
278			else if (input == "kill self with lunch tray" || input == "kill self with lunchtray" || input == "kill self with tray") {
279				if (lunchtray == true) {
280					$("#container").fadeOut(3000, function() {
281						$("#killself").fadeIn(3000);
282					});
283				}
284				else {
285					$('<p>You can\'t do that.</p>').insertBefore("#placeholder").fadeIn(1000);
286				}
287			}
288			
289			else if (input == "kill self with knife") {
290				if (knife == true) {
291					$("#container").fadeOut(3000, function() {
292						$("#killself").fadeIn(3000);
293					});
294				}
295				else {
296					$('<p>You can\'t do that.</p>').insertBefore("#placeholder").fadeIn(1000);
297				}
298			}
299			
300			else if (input == "kill self with whip") {
301				if (whip == true) {
302					$("#container").fadeOut(3000, function() {
303						$("#killself").fadeIn(3000);
304					});
305				}
306				else {
307					$('<p>You can\'t do that.</p>').insertBefore("#placeholder").fadeIn(1000);
308				}
309			}
310			//
311			
312			else $('<p>You can\'t do that!</p>').insertBefore("#placeholder").fadeIn(1000);
313			
314		
315		}
316		//
317		//end kill
318		//
319		
320		
321		
322		
323		//
324		//inventory
325		//
326		else if (input.indexOf("inventory") > -1) {
327			if (input == "inventory") {
328				//paperclips
329				if (paperclip == true) {
330					pclip = "Paper Clip<br />";
331				}
332				else {
333					pclip = "";
334				}
335				//
336				
337				//dead bugs
338				if (deadbugs == true) {
339					dbugs = "Dead Bugs<br />";
340				}
341				else {
342					dbugs = "";
343				}
344				//
345				
346				//lunch tray
347				if (lunchtray == true) {
348					ltray = "Lunch Tray<br />";
349				}
350				else {
351					ltray = "";
352				}
353				//
354				
355				//lunch tray
356				if (torch == true) {
357					tch = "Torch<br />";
358				}
359				else {
360					tch = "";
361				}
362				//
363				
364				//lunch tray
365				if (note == true) {
366					nt = "Note from Captors<br />";
367				}
368				else {
369					nt = "";
370				}
371				//
372				
373				//hat
374				if (hat == true) {
375					ht = "Hat<br />";
376				}
377				else {
378					ht = "";
379				}
380				//
381								
382				//knife
383				if (knife == true) {
384					knf = "Knife<br />";
385				}
386				else {
387					knf = "";
388				}
389				//
390				
391				//whip
392				if (whip == true) {
393					whp = "Whip<br />";
394				}
395				else {
396					whp = "";
397				}
398				//
399				
400				//key
401				if (key == true) {
402					ky = "Key<br />";
403				}
404				else {
405					ky = "";
406				}
407				//
408				
409				//goo
410				if (powder == true) {
411					powd = "Strange Powder<br />";
412				}
413				else {
414					powd = "";
415				}
416				//
417				
418				if (pclip == "" && dbugs == "" && ltray == "") {
419					$('<p>Inventory:<br /><i>There is nothing in your inventory</i></p>').insertBefore("#placeholder").fadeIn(1000);
420				}
421				else {
422					 $('<p>Inventory:<br />' + pclip + dbugs + ltray + tch + nt + ht + whp + knf + ky + powd + '</p>').insertBefore("#placeholder").fadeIn(1000);
423				}
424			}
425			else $('<p>I don\'t understand "' + input + '"</p>').insertBefore("#placeholder").fadeIn(1000);
426		}
427		//
428		//end inventory
429		//
430		
431		
432		
433		
434		
435		
436		//
437		//unlock
438		//
439		
440		else if (input.indexOf("unlock") > -1) {
441			if (input == "unlock" || input == "unlock door" || input == "unlock jail door" || input == "unlock jaildoor") {
442				$('<p>Unlock door with what? Be specific. Type "help" for a list of all commands.</p>').insertBefore("#placeholder").fadeIn(1000);
443			}
444			
445			//jail door
446			else if (input == "unlock jail door with paperclip" || input == "unlock jaildoor with paperclip" || input == "unlock jail door with paper clip" || input == "unlock jaildoor with paper clip" || input == "unlock door with paper clip" || input == "unlock door with paperclip") {
447				if (currentroom != "jail") {
448					$('<p>You can\'t do that.</p>').insertBefore("#placeholder").fadeIn(1000);
449				}
450				else if (cellunlocked == true) {
451					$('<p>The door is already unlocked.</p>').insertBefore("#placeholder").fadeIn(1000);
452				}
453				else if (currentroom == "jail" && paperclip == true) {
454					cellunlocked = true;
455					$('<p>You unlocked the jail door successfully. You can now proceed northward.</p>').insertBefore("#placeholder").fadeIn(1000);
456				}
457				else $('<p>The door cannot be unlocked.</p>').insertBefore("#placeholder").fadeIn(1000);
458			}
459			//
460			
461			//exit door
462			else if (input == "unlock door with key") {
463				if (currentroom != "exit") {
464					$('<p>You can\'t do that.</p>').insertBefore("#placeholder").fadeIn(1000);
465				}
466				else if (exitunlocked == true) {
467					$('<p>The door is already unlocked.</p>').insertBefore("#placeholder").fadeIn(1000);
468				}
469				else if (currentroom == "exit" && key == true) {
470					exitunlocked = true;
471					$('<p>You unlocked the door successfully. You can now proceed northward.</p>').insertBefore("#placeholder").fadeIn(1000);
472				}
473				else $('<p>The door cannot be unlocked.</p>').insertBefore("#placeholder").fadeIn(1000);
474			}
475			//
476			
477			else $('<p>I don\'t understand "' + input + '"</p>').insertBefore("#placeholder").fadeIn(1000);
478			
479		}
480		//
481		//end unlock
482		//
483		
484		
485		
486		
487		
488		
489		
490		//
491		//go
492		//
493		else if (input.indexOf("go") > -1) {
494			if (input == "go") {
495				$('<p>Go in which direction?</p>').insertBefore("#placeholder").fadeIn(1000);
496			}
497			
498			//go from jail cell
499			else if (input == "go north" && currentroom == "jail") {
500				if (cellunlocked == true) {
501					if (beentohallway == true) {
502						if (note == false) {
503							hallnote = " The note is still here. ";
504						}
505						else {
506							hallnote = "";
507						}
508						if (torch == false) {
509							halltorch = " The torch continues to light the dim hallway. ";
510						}
511						else {
512							halltorch = "";
513						}
514						$('<p>You are back in the hallway. The hallway continues to the east and west. The jail room is to the south. ' + hallnote + halltorch + '</p>').insertBefore("#placeholder").fadeIn(1000);
515						currentroom = "hallway";
516					}
517					else {
518						$("#area_hallway").clone().insertBefore("#placeholder").fadeIn(1000);
519						currentroom = "hallway";
520						beentohallway = true;
521					}
522				}
523				else {
524					$('<p>The door is locked.</p>').insertBefore("#placeholder").fadeIn(1000);
525				}
526			}		
527			//
528			
529			//go back to jail cell
530			else if (input == "go south" && currentroom == "hallway") {
531				if (deadbugs == false) {
532					jailbugs = "The dead bugs are still here";
533					jailperiod = ".";
534				}
535				else {
536					jailbugs = "";
537				}
538				if (lunchtray == false) {
539					jailtray = "The lunch tray is still here";
540					jailperiod = ".";
541				}
542				else {
543					jailtray = "";
544				}
545				if (deadbugs == false && lunchtray == false) {
546					jailword = " and ";
547					jailtray = "the lunch tray is still here";
548					jailperiod = ".";
549				}
550				else {
551					jailword = "";
552				}
553				if (deadbugs == true && lunchtray == true) {
554					jailperiod = "";
555				}
556				$('<p>You are back in the jail cell. To the north is the door. ' + jailbugs + jailword + jailtray + jailperiod + '</p>').insertBefore("#placeholder").fadeIn(1000);
557				currentroom = "jail";
558			}
559			//
560			
561			//go to torture room from hallway
562			else if (input == "go east" && currentroom == "hallway") {
563				if (torch == true) {
564					if (beentorture == true) {
565						if (searchtable == false) {
566							torturetable = "The table seems to emit a strange energy. ";
567						}
568						else {
569							torturetable = "";
570						}
571						if (whip == false) {
572							torturewhip = "The whip remains stationed on the wall. ";
573						}
574						else {
575							torturewhip = "";
576						}
577						$('<p>You are back in the room of strange devices. To the south is a doorway, and to the west is the hallway you came from. ' + torturetable + torturewhip + '</p>').insertBefore("#placeholder").fadeIn(1000);
578						currentroom = "torture";
579					}
580					else {
581						$("#area_torture").clone().insertBefore("#placeholder").fadeIn(1000);
582						beentorture = true;
583						currentroom = "torture";
584					}
585				}
586				else {
587					$('<p>It seems awful dark that way...</p>').insertBefore("#placeholder").fadeIn(1000);
588				}
589			}
590			//
591			
592			//go to westhall from hallway
593			else if (input == "go west" && currentroom == "hallway") {
594				if (torch == true) {
595					if (beentowesthall == true) {
596						$('<p>You are back at the west hallway. To the east is where you came from. To the north and south are dark rooms.</p>').insertBefore("#placeholder").fadeIn(1000);
597						currentroom = "westhall";
598					}
599					else {
600						$("#area_westhall").clone().insertBefore("#placeholder").fadeIn(1000);
601						beentowesthall = true;
602						currentroom = "westhall";
603					}
604				}
605				else {
606					$('<p>It seems awful dark that way...</p>').insertBefore("#placeholder").fadeIn(1000);
607				}
608			}
609			//
610			
611			//go to exit from westhallway
612			else if (input == "go north" && currentroom == "westhall") {
613				if (beentoexit == true) {
614					$('<p>You are back at the room with the strange door. To the south is the hallway you came from.</p>').insertBefore("#placeholder").fadeIn(1000);
615					currentroom = "exit";
616				}
617				else {
618					$("#area_exit").clone().insertBefore("#placeholder").fadeIn(1000);
619					beentoexit = true;
620					currentroom = "exit";
621				}
622			}
623			//
624			
625			//go to westhallway from exit
626			else if (input == "go south" && currentroom == "exit") {
627				if (beentowesthall == true) {
628					$('<p>You are back at the west hallway. To the north and south are dark rooms. The hallway continues east.</p>').insertBefore("#placeholder").fadeIn(1000);
629					currentroom = "westhall";
630				}
631				else {
632					$("#area_westhall").clone().insertBefore("#placeholder").fadeIn(1000);
633					beentowesthall = true;
634					currentroom = "westhall";
635				}
636			}
637			//
638			
639			//go through exit
640			else if (input == "go north" && currentroom == "exit") {
641				if (exitunlocked == true) {
642					$("#container").fadeOut(3000, function() {
643						$("#wingame").fadeIn(3000);
644					});
645				}
646				else {
647					$('<p>The door is locked.</p>').insertBefore("#placeholder").fadeIn(1000);
648				}
649			}
650			//
651			
652			
653			//go back to hallway from west hall
654			else if (input == "go east" && currentroom == "westhall") {
655				if (note == false) {
656					hallnote = " The note is still here. ";
657				}
658				else {
659					hallnote = "";
660				}
661				if (torch == false) {
662					halltorch = " The torch continues to light the dim hallway. ";
663				}
664				else {
665					halltorch = "";
666				}
667				$('<p>You are back in the main hallway. The hallway continues to the east and west. The jail room is to the south.' + hallnote + halltorch + '</p>').insertBefore("#placeholder").fadeIn(1000);
668				currentroom = "hallway";
669			}
670			//
671			
672			//go to bonus room from westhall
673			else if (input == "go south" && currentroom == "westhall") {
674				if (beentobonus == true) {
675					if (powder == false) {
676						bonuscrate = "The lone crate in the corner looks untouched.";
677					}
678					else {
679						bonuscrate = "";
680					}
681					$('<p>You are back in the small storage room. You came from the north. ' + bonuscrate + '</p>').insertBefore("#placeholder").fadeIn(1000);
682					currentroom = "bonus";
683				}
684				else {
685					$("#area_bonus").clone().insertBefore("#placeholder").fadeIn(1000);
686					beentobonus = true;
687					currentroom = "bonus";
688				}
689			}
690			//
691			
692			//go to westhall from bonus room
693			else if (input == "go north" && currentroom == "bonus") {
694					$('<p>You are back in the hallway. To the north and south are dark rooms. The hallway continues east.</p>').insertBefore("#placeholder").fadeIn(1000);
695					currentroom = "westhall";
696			}
697			//
698			
699			//go back to hallway from torture room
700			else if (input == "go west" && currentroom == "torture") {
701				if (note == false) {
702					hallnote = " The note is still here. ";
703				}
704				else {
705					hallnote = "";
706				}
707				if (torch == false) {
708					halltorch = " The torch continues to light the dim hallway. ";
709				}
710				else {
711					halltorch = "";
712				}
713				$('<p>You are back in the main hallway. The hallway continues to the east and west. The jail room is to the south.' + hallnote + halltorch + '</p>').insertBefore("#placeholder").fadeIn(1000);
714				currentroom = "hallway";
715			}
716			//
717			
718			
719			//go to morgue from torture room
720			else if (input == "go south" && currentroom == "torture") {
721				if (beenmorgue == true) {
722					if (zombiedead == false) {
723						morguezombie = "The zombie is still here!";
724					}
725					else {
726						morguezombie = "The zombie remains on the floor rotting in a cesspool of it's juices.";
727					}
728					$('<p>You are back in the morgue. To the north is the doorway to the room of strange devices. ' + morguezombie + '</p>').insertBefore("#placeholder").fadeIn(1000);
729					currentroom = "morgue";
730				}
731				else {
732					$("#area_morgue").clone().insertBefore("#placeholder").fadeIn(1000);
733					beenmorgue = true;
734					currentroom = "morgue";
735				}
736			}
737			//
738			
739			//go to torture room from morgue
740			else if (input == "go north" && currentroom == "morgue") {
741				if (searchtable == false) {
742					torturetable = "The table seems to emit a strange energy. ";
743				}
744				else {
745					torturetable = "";
746				}
747				if (whip == false) {
748					torturewhip = "The whip remains stationed on the wall. ";
749				}
750				else {
751					torturewhip = "";
752				}
753				$('<p>You are back in the room of strange devices. To the south is a doorway, and to the west is the hallway. ' + torturetable + torturewhip + '</p>').insertBefore("#placeholder").fadeIn(1000);
754				currentroom = "torture";
755			}
756			//
757			
758			
759			
760			else $('<p>You can\'t go that way.</p>').insertBefore("#placeholder").fadeIn(1000);
761		}
762		//
763		//end go
764		//
765				
766				
767				
768				
769				
770				
771		
772		else if (input != "") {
773			$('<p>I don\'t understand "' + input + '"</p>').insertBefore("#placeholder").fadeIn(1000);
774		}
775		
776		$("#console").scrollTop($("#console")[0].scrollHeight);
777		$("#command_line").val("");
778	});
779});
Full Screen

dom.js

Source: dom.js Github

copy
1(function() {
2
3var paper,
4    url = 'http://raphaeljs.com';
5
6module('DOM', {
7  setup: function() {
8    paper = new Raphael(document.getElementById('qunit-fixture'), 1000, 1000);
9  },
10  teardown: function() {
11    paper.remove();
12  }
13});
14
15var equalNodePosition = function(node, expectedParent, expectedPreviousSibling, expectedNextSibling) {
16  equal(node.parentNode, expectedParent);
17  equal(node.previousSibling, expectedPreviousSibling);
18  equal(node.nextSibling, expectedNextSibling);
19};
20
21var equalNodePositionWrapped = function(node, anchor, expectedParent, expectedPreviousSibling, expectedNextSibling) {
22  equal(node.parentNode, anchor);
23  equalNodePosition(anchor, expectedParent, expectedPreviousSibling, expectedNextSibling);
24};
25
26// Element#insertBefore
27// --------------------
28
29test('insertBefore: no element', function() {
30  var el = paper.rect();
31
32  el.insertBefore(null);
33
34  equalNodePosition(el.node, paper.canvas, paper.defs, null);
35});
36
37test('insertBefore: first element', function() {
38  var x = paper.rect();
39  var el = paper.rect();
40
41  el.insertBefore(x);
42
43  equalNodePosition(el.node, paper.canvas, paper.defs, x.node);
44});
45
46test('insertBefore: middle element', function() {
47  var x = paper.rect();
48  var y = paper.rect();
49  var el = paper.rect();
50
51  el.insertBefore(y);
52
53  equalNodePosition(el.node, paper.canvas, x.node, y.node);
54});
55
56test('insertBefore: no element when wrapped in <a>', function() {
57  var el = paper.rect().attr('href', url),
58      anchor = el.node.parentNode;
59
60  el.insertBefore(null);
61
62  equalNodePositionWrapped(el.node, anchor, paper.canvas, paper.defs, null);
63});
64
65test('insertBefore: first element when wrapped in <a>', function() {
66  var x = paper.rect();
67  var el = paper.rect().attr('href', url),
68      anchor = el.node.parentNode;
69
70  el.insertBefore(x);
71
72  equalNodePositionWrapped(el.node, anchor, paper.canvas, paper.defs, x.node);
73});
74
75test('insertBefore: first element wrapped in <a> and wrapped in <a>', function() {
76  var x = paper.rect().attr('href', url),
77      xAnchor = x.node.parentNode;
78  var el = paper.rect().attr('href', url),
79      anchor = el.node.parentNode;
80
81  el.insertBefore(x);
82
83  equalNodePositionWrapped(el.node, anchor, paper.canvas, paper.defs, xAnchor);
84});
85
86test('insertBefore: middle element when wrapped in <a>', function() {
87  var x = paper.rect();
88  var y = paper.rect();
89  var el = paper.rect().attr('href', url),
90      anchor = el.node.parentNode;
91
92  el.insertBefore(y);
93
94  equalNodePositionWrapped(el.node, anchor, paper.canvas, x.node, y.node);
95});
96
97test('insertBefore: middle element wrapped in <a> and wrapped in <a>', function() {
98  var x = paper.rect().attr('href', url),
99      xAnchor = x.node.parentNode;
100  var y = paper.rect().attr('href', url),
101      yAnchor = y.node.parentNode;
102  var el = paper.rect().attr('href', url),
103      anchor = el.node.parentNode;
104
105  el.insertBefore(y);
106
107  equalNodePositionWrapped(el.node, anchor, paper.canvas, xAnchor, yAnchor);
108});
109
110// TODO...
111// insertBefore: with set
112// insertBefore: with nested set.
113
114// Element#insertAfter
115// -------------------
116
117test('insertAfter: no element', function() {
118  var el = paper.rect();
119
120  el.insertAfter(null);
121
122  equalNodePosition(el.node, paper.canvas, paper.defs, null);
123});
124
125test('insertAfter: last element', function() {
126  var x = paper.rect();
127  var el = paper.rect();
128
129  el.insertAfter(x);
130
131  equalNodePosition(el.node, paper.canvas, x.node, null);
132});
133
134test('insertAfter: middle element', function() {
135  var x = paper.rect();
136  var y = paper.rect();
137  var el = paper.rect();
138
139  el.insertAfter(x);
140
141  equalNodePosition(el.node, paper.canvas, x.node, y.node);
142});
143
144test('insertAfter: no element when wrapped in <a>', function() {
145  var el = paper.rect().attr('href', url),
146      anchor = el.node.parentNode;
147
148  el.insertAfter(null);
149
150  equalNodePositionWrapped(el.node, anchor, paper.canvas, paper.defs, null);
151});
152
153test('insertAfter: last element when wrapped in <a>', function() {
154  var x = paper.rect();
155  var el = paper.rect().attr('href', url),
156      anchor = el.node.parentNode;
157
158  el.insertAfter(x);
159
160  equalNodePositionWrapped(el.node, anchor, paper.canvas, x.node, null);
161});
162
163test('insertAfter: last element wrapped in <a> and wrapped in <a>', function() {
164  var x = paper.rect().attr('href', url),
165      xAnchor = x.node.parentNode;
166  var el = paper.rect().attr('href', url),
167      anchor = el.node.parentNode;
168
169  el.insertAfter(x);
170
171  equalNodePositionWrapped(el.node, anchor, paper.canvas, xAnchor, null);
172});
173
174test('insertAfter: middle element when wrapped in <a>', function() {
175  var x = paper.rect();
176  var y = paper.rect();
177  var el = paper.rect().attr('href', url),
178      anchor = el.node.parentNode;
179
180  el.insertAfter(x);
181
182  equalNodePositionWrapped(el.node, anchor, paper.canvas, x.node, y.node);
183});
184
185test('insertAfter: middle element wrapped in <a> and wrapped in <a>', function() {
186  var x = paper.rect().attr('href', url),
187      xAnchor = x.node.parentNode;
188  var y = paper.rect().attr('href', url),
189      yAnchor = y.node.parentNode;
190  var el = paper.rect().attr('href', url),
191      anchor = el.node.parentNode;
192
193  el.insertAfter(x);
194
195  equalNodePositionWrapped(el.node, anchor, paper.canvas, xAnchor, yAnchor);
196});
197
198// TODO...
199// insertAfter: with set
200// insertAfter: with nested set.
201
202// Element#remove
203// --------------
204
205test('remove: after added', function() {
206  var el = paper.rect(),
207      node = el.node;
208
209  el.remove();
210
211  equal(el.node, null);
212  equal(node.parentNode, null);
213});
214
215test('remove: when wrapped in <a>', function() {
216  var el = paper.rect().attr('href', url),
217      node = el.node,
218      anchor = node.parentNode;
219
220  el.remove();
221
222  equal(el.node, null);
223  equal(node.parentNode, anchor);
224  equal(anchor.parentNode, null);
225});
226
227test('remove: when already removed', function() {
228  var el = paper.rect(),
229      node = el.node;
230
231  el.remove();
232  el.remove();
233
234  equal(el.node, null);
235  equal(node.parentNode, null);
236});
237
238test('remove: when the canvas is removed', function() {
239  var el = paper.rect(),
240      node = el.node;
241
242  paper.remove();
243  el.remove();
244
245  equal(el.node, null);
246  equal(node.parentNode, null);
247});
248
249// Element#toFront
250// --------------
251
252test('toFront: normal', function() {
253  var el = paper.rect();
254  var x = paper.rect();
255
256  el.toFront();
257
258  equalNodePosition(el.node, paper.canvas, x.node, null);
259});
260
261test('toFront: when wrapped in <a>', function() {
262  var el = paper.rect().attr('href', url),
263      anchor = el.node.parentNode;
264  var x = paper.rect();
265
266  el.toFront();
267
268  equalNodePositionWrapped(el.node, anchor, paper.canvas, x.node, null);
269});
270
271// Element#toBack
272// --------------
273
274test('toBack: normal', function() {
275  var x = paper.rect();
276  var el = paper.rect();
277
278  el.toBack();
279
280  equalNodePosition(el.node, paper.canvas, null, paper.desc);
281  equalNodePosition(x.node, paper.canvas, paper.defs, null);
282});
283
284test('toBack: when wrapped in <a>', function() {
285  var x = paper.rect();
286  var el = paper.rect().attr('href', url),
287      anchor = el.node.parentNode;
288
289  el.toBack();
290
291  equalNodePositionWrapped(el.node, anchor, paper.canvas, null, paper.desc);
292  equalNodePosition(x.node, paper.canvas, paper.defs, null);
293});
294
295})();
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)