Best JavaScript code snippet using playwright-internal
ast.js
Source:ast.js  
...44      expect(argNode2).to.have.property('text', 'bar');45      expect(argNode2.location).to.eql({ min: 5, max: 8 });46    });47    it('should return a match all "is" function for whitespace', function () {48      const expected = nodeTypes.function.buildNode('is', '*', '*');49      const actual = fromLegacyKueryExpressionNoMeta('  ');50      expect(actual).to.eql(expected);51    });52    it('should return an "and" function for single literals', function () {53      const expected = nodeTypes.function.buildNode('and', [nodeTypes.literal.buildNode('foo')]);54      const actual = fromLegacyKueryExpressionNoMeta('foo');55      expect(actual).to.eql(expected);56    });57    it('should ignore extraneous whitespace at the beginning and end of the query', function () {58      const expected = nodeTypes.function.buildNode('and', [nodeTypes.literal.buildNode('foo')]);59      const actual = fromLegacyKueryExpressionNoMeta('  foo ');60      expect(actual).to.eql(expected);61    });62    it('literals and queries separated by whitespace should be joined by an implicit "and"', function () {63      const expected = nodeTypes.function.buildNode('and', [64        nodeTypes.literal.buildNode('foo'),65        nodeTypes.literal.buildNode('bar'),66      ]);67      const actual = fromLegacyKueryExpressionNoMeta('foo bar');68      expect(actual).to.eql(expected);69    });70    it('should also support explicit "and"s as a binary operator', function () {71      const expected = nodeTypes.function.buildNode('and', [72        nodeTypes.literal.buildNode('foo'),73        nodeTypes.literal.buildNode('bar'),74      ]);75      const actual = fromLegacyKueryExpressionNoMeta('foo and bar');76      expect(actual).to.eql(expected);77    });78    it('should also support "and" as a function', function () {79      const expected = nodeTypes.function.buildNode('and', [80        nodeTypes.literal.buildNode('foo'),81        nodeTypes.literal.buildNode('bar'),82      ], 'function');83      const actual = fromLegacyKueryExpressionNoMeta('and(foo, bar)');84      expect(actual).to.eql(expected);85    });86    it('should support "or" as a binary operator', function () {87      const expected = nodeTypes.function.buildNode('or', [88        nodeTypes.literal.buildNode('foo'),89        nodeTypes.literal.buildNode('bar'),90      ]);91      const actual = fromLegacyKueryExpressionNoMeta('foo or bar');92      expect(actual).to.eql(expected);93    });94    it('should support "or" as a function', function () {95      const expected = nodeTypes.function.buildNode('or', [96        nodeTypes.literal.buildNode('foo'),97        nodeTypes.literal.buildNode('bar'),98      ]);99      const actual = fromLegacyKueryExpressionNoMeta('or(foo, bar)');100      expect(actual).to.eql(expected);101    });102    it('should support negation of queries with a "!" prefix', function () {103      const expected = nodeTypes.function.buildNode('not',104        nodeTypes.function.buildNode('or', [105          nodeTypes.literal.buildNode('foo'),106          nodeTypes.literal.buildNode('bar'),107        ]));108      const actual = fromLegacyKueryExpressionNoMeta('!or(foo, bar)');109      expect(actual).to.eql(expected);110    });111    it('"and" should have a higher precedence than "or"', function () {112      const expected = nodeTypes.function.buildNode('or', [113        nodeTypes.literal.buildNode('foo'),114        nodeTypes.function.buildNode('or', [115          nodeTypes.function.buildNode('and', [116            nodeTypes.literal.buildNode('bar'),117            nodeTypes.literal.buildNode('baz'),118          ]),119          nodeTypes.literal.buildNode('qux'),120        ])121      ]);122      const actual = fromLegacyKueryExpressionNoMeta('foo or bar and baz or qux');123      expect(actual).to.eql(expected);124    });125    it('should support grouping to override default precedence', function () {126      const expected = nodeTypes.function.buildNode('and', [127        nodeTypes.function.buildNode('or', [128          nodeTypes.literal.buildNode('foo'),129          nodeTypes.literal.buildNode('bar'),130        ]),131        nodeTypes.literal.buildNode('baz'),132      ]);133      const actual = fromLegacyKueryExpressionNoMeta('(foo or bar) and baz');134      expect(actual).to.eql(expected);135    });136    it('should support a shorthand operator syntax for "is" functions', function () {137      const expected = nodeTypes.function.buildNode('is', 'foo', 'bar', true);138      const actual = fromLegacyKueryExpressionNoMeta('foo:bar');139      expect(actual).to.eql(expected);140    });141    it('should support a shorthand operator syntax for inclusive "range" functions', function () {142      const argumentNodes = [143        nodeTypes.literal.buildNode('bytes'),144        nodeTypes.literal.buildNode(1000),145        nodeTypes.literal.buildNode(8000),146      ];147      const expected = nodeTypes.function.buildNodeWithArgumentNodes('range', argumentNodes);148      const actual = fromLegacyKueryExpressionNoMeta('bytes:[1000 to 8000]');149      expect(actual).to.eql(expected);150    });151    it('should support functions with named arguments', function () {152      const expected = nodeTypes.function.buildNode('range', 'bytes', { gt: 1000, lt: 8000 });153      const actual = fromLegacyKueryExpressionNoMeta('range(bytes, gt=1000, lt=8000)');154      expect(actual).to.eql(expected);155    });156    it('should throw an error for unknown functions', function () {157      expect(ast.fromLegacyKueryExpression).withArgs('foo(bar)').to.throwException(/Unknown function "foo"/);158    });159  });160  describe('fromKueryExpression', function () {161    it('should return a match all "is" function for whitespace', function () {162      const expected = nodeTypes.function.buildNode('is', '*', '*');163      const actual = ast.fromKueryExpression('  ');164      expect(actual).to.eql(expected);165    });166    it('should return an "is" function with a null field for single literals', function () {167      const expected = nodeTypes.function.buildNode('is', null, 'foo');168      const actual = ast.fromKueryExpression('foo');169      expect(actual).to.eql(expected);170    });171    it('should ignore extraneous whitespace at the beginning and end of the query', function () {172      const expected = nodeTypes.function.buildNode('is', null, 'foo');173      const actual = ast.fromKueryExpression('  foo ');174      expect(actual).to.eql(expected);175    });176    it('should not split on whitespace', function () {177      const expected = nodeTypes.function.buildNode('is', null, 'foo bar');178      const actual = ast.fromKueryExpression('foo bar');179      expect(actual).to.eql(expected);180    });181    it('should support "and" as a binary operator', function () {182      const expected = nodeTypes.function.buildNode('and', [183        nodeTypes.function.buildNode('is', null, 'foo'),184        nodeTypes.function.buildNode('is', null, 'bar'),185      ]);186      const actual = ast.fromKueryExpression('foo and bar');187      expect(actual).to.eql(expected);188    });189    it('should support "or" as a binary operator', function () {190      const expected = nodeTypes.function.buildNode('or', [191        nodeTypes.function.buildNode('is', null, 'foo'),192        nodeTypes.function.buildNode('is', null, 'bar'),193      ]);194      const actual = ast.fromKueryExpression('foo or bar');195      expect(actual).to.eql(expected);196    });197    it('should support negation of queries with a "not" prefix', function () {198      const expected = nodeTypes.function.buildNode('not',199        nodeTypes.function.buildNode('or', [200          nodeTypes.function.buildNode('is', null, 'foo'),201          nodeTypes.function.buildNode('is', null, 'bar'),202        ])203      );204      const actual = ast.fromKueryExpression('not (foo or bar)');205      expect(actual).to.eql(expected);206    });207    it('"and" should have a higher precedence than "or"', function () {208      const expected = nodeTypes.function.buildNode('or', [209        nodeTypes.function.buildNode('is', null, 'foo'),210        nodeTypes.function.buildNode('or', [211          nodeTypes.function.buildNode('and', [212            nodeTypes.function.buildNode('is', null, 'bar'),213            nodeTypes.function.buildNode('is', null, 'baz'),214          ]),215          nodeTypes.function.buildNode('is', null, 'qux'),216        ])217      ]);218      const actual = ast.fromKueryExpression('foo or bar and baz or qux');219      expect(actual).to.eql(expected);220    });221    it('should support grouping to override default precedence', function () {222      const expected = nodeTypes.function.buildNode('and', [223        nodeTypes.function.buildNode('or', [224          nodeTypes.function.buildNode('is', null, 'foo'),225          nodeTypes.function.buildNode('is', null, 'bar'),226        ]),227        nodeTypes.function.buildNode('is', null, 'baz'),228      ]);229      const actual = ast.fromKueryExpression('(foo or bar) and baz');230      expect(actual).to.eql(expected);231    });232    it('should support matching against specific fields', function () {233      const expected = nodeTypes.function.buildNode('is', 'foo', 'bar');234      const actual = ast.fromKueryExpression('foo:bar');235      expect(actual).to.eql(expected);236    });237    it('should also not split on whitespace when matching specific fields', function () {238      const expected = nodeTypes.function.buildNode('is', 'foo', 'bar baz');239      const actual = ast.fromKueryExpression('foo:bar baz');240      expect(actual).to.eql(expected);241    });242    it('should treat quoted values as phrases', function () {243      const expected = nodeTypes.function.buildNode('is', 'foo', 'bar baz', true);244      const actual = ast.fromKueryExpression('foo:"bar baz"');245      expect(actual).to.eql(expected);246    });247    it('should support a shorthand for matching multiple values against a single field', function () {248      const expected = nodeTypes.function.buildNode('or', [249        nodeTypes.function.buildNode('is', 'foo', 'bar'),250        nodeTypes.function.buildNode('is', 'foo', 'baz'),251      ]);252      const actual = ast.fromKueryExpression('foo:(bar or baz)');253      expect(actual).to.eql(expected);254    });255    it('should support "and" and "not" operators and grouping in the shorthand as well', function () {256      const expected = nodeTypes.function.buildNode('and', [257        nodeTypes.function.buildNode('or', [258          nodeTypes.function.buildNode('is', 'foo', 'bar'),259          nodeTypes.function.buildNode('is', 'foo', 'baz'),260        ]),261        nodeTypes.function.buildNode('not',262          nodeTypes.function.buildNode('is', 'foo', 'qux')263        ),264      ]);265      const actual = ast.fromKueryExpression('foo:((bar or baz) and not qux)');266      expect(actual).to.eql(expected);267    });268    it('should support exclusive range operators', function () {269      const expected = nodeTypes.function.buildNode('and', [270        nodeTypes.function.buildNode('range', 'bytes', {271          gt: 1000,272        }),273        nodeTypes.function.buildNode('range', 'bytes', {274          lt: 8000,275        }),276      ]);277      const actual = ast.fromKueryExpression('bytes > 1000 and bytes < 8000');278      expect(actual).to.eql(expected);279    });280    it('should support inclusive range operators', function () {281      const expected = nodeTypes.function.buildNode('and', [282        nodeTypes.function.buildNode('range', 'bytes', {283          gte: 1000,284        }),285        nodeTypes.function.buildNode('range', 'bytes', {286          lte: 8000,287        }),288      ]);289      const actual = ast.fromKueryExpression('bytes >= 1000 and bytes <= 8000');290      expect(actual).to.eql(expected);291    });292    it('should support wildcards in field names', function () {293      const expected = nodeTypes.function.buildNode('is', 'machine*', 'osx');294      const actual = ast.fromKueryExpression('machine*:osx');295      expect(actual).to.eql(expected);296    });297    it('should support wildcards in values', function () {298      const expected = nodeTypes.function.buildNode('is', 'foo', 'ba*');299      const actual = ast.fromKueryExpression('foo:ba*');300      expect(actual).to.eql(expected);301    });302    it('should create an exists "is" query when a field is given and "*" is the value', function () {303      const expected = nodeTypes.function.buildNode('is', 'foo', '*');304      const actual = ast.fromKueryExpression('foo:*');305      expect(actual).to.eql(expected);306    });307  });308  describe('fromLiteralExpression', function () {309    it('should create literal nodes for unquoted values with correct primitive types', function () {310      const stringLiteral = nodeTypes.literal.buildNode('foo');311      const booleanFalseLiteral = nodeTypes.literal.buildNode(false);312      const booleanTrueLiteral = nodeTypes.literal.buildNode(true);313      const numberLiteral = nodeTypes.literal.buildNode(42);314      expect(ast.fromLiteralExpression('foo')).to.eql(stringLiteral);315      expect(ast.fromLiteralExpression('true')).to.eql(booleanTrueLiteral);316      expect(ast.fromLiteralExpression('false')).to.eql(booleanFalseLiteral);317      expect(ast.fromLiteralExpression('42')).to.eql(numberLiteral);318    });319    it('should allow escaping of special characters with a backslash', function () {320      const expected = nodeTypes.literal.buildNode('\\():<>"*');321      // yo dawg322      const actual = ast.fromLiteralExpression('\\\\\\(\\)\\:\\<\\>\\"\\*');323      expect(actual).to.eql(expected);324    });325    it('should support double quoted strings that do not need escapes except for quotes', function () {326      const expected = nodeTypes.literal.buildNode('\\():<>"*');327      const actual = ast.fromLiteralExpression('"\\():<>\\"*"');328      expect(actual).to.eql(expected);329    });330    it('should support escaped backslashes inside quoted strings', function () {331      const expected = nodeTypes.literal.buildNode('\\');332      const actual = ast.fromLiteralExpression('"\\\\"');333      expect(actual).to.eql(expected);334    });335    it('should detect wildcards and build wildcard AST nodes', function () {336      const expected = nodeTypes.wildcard.buildNode('foo*bar');337      const actual = ast.fromLiteralExpression('foo*bar');338      expect(actual).to.eql(expected);339    });340  });341  describe('toElasticsearchQuery', function () {342    it('should return the given node type\'s ES query representation', function () {343      const node = nodeTypes.function.buildNode('exists', 'response');344      const expected = nodeTypes.function.toElasticsearchQuery(node, indexPattern);345      const result = ast.toElasticsearchQuery(node, indexPattern);346      expect(result).to.eql(expected);347    });348    it('should return an empty "and" function for undefined nodes and unknown node types', function () {349      const expected = nodeTypes.function.toElasticsearchQuery(nodeTypes.function.buildNode('and', []));350      expect(ast.toElasticsearchQuery()).to.eql(expected);351      const noTypeNode = nodeTypes.function.buildNode('exists', 'foo');352      delete noTypeNode.type;353      expect(ast.toElasticsearchQuery(noTypeNode)).to.eql(expected);354      const unknownTypeNode = nodeTypes.function.buildNode('exists', 'foo');355      unknownTypeNode.type = 'notValid';356      expect(ast.toElasticsearchQuery(unknownTypeNode)).to.eql(expected);357    });358  });359  describe('doesKueryExpressionHaveLuceneSyntaxError', function () {360    it('should return true for Lucene ranges', function () {361      const result = ast.doesKueryExpressionHaveLuceneSyntaxError('bar: [1 TO 10]');362      expect(result).to.eql(true);363    });364    it('should return false for KQL ranges', function () {365      const result = ast.doesKueryExpressionHaveLuceneSyntaxError('bar < 1');366      expect(result).to.eql(false);367    });368    it('should return true for Lucene exists', function () {...datepickr.js
Source:datepickr.js  
...185			element.detachEvent('on' + eventType, callback);186		}187	}188	189	function buildNode(nodeName, attributes, content) {190		var element;191		192		if(!(nodeName in buildCache)) {193			buildCache[nodeName] = document.createElement(nodeName);194		}195		196		element = buildCache[nodeName].cloneNode(false);197		198		if(attributes != null) {199			for(var attribute in attributes) {200				element[attribute] = attributes[attribute];201			}202		}203		204		if(content != null) {205			if(typeof(content) == 'object') {206				element.appendChild(content);207			} else {208				element.innerHTML = content;209			}210		}211		212		return element;213	}214	215	function monthToStr(date, full, months) {216		return ((full == true) ? months[date] : ((months[date].length > 3) ? months[date].substring(0, 3) : months[date]));217	}218	219	function isToday(day, currentMonthView, currentYearView) {220		return day == date.current.day() && currentMonthView == date.current.month.integer() && currentYearView == date.current.year();221	}222	223	function buildWeekdays(weekdays) {224		var weekdayHtml = document.createDocumentFragment();225		foreach(weekdays, function(weekday) {226			weekdayHtml.appendChild(buildNode('th', {}, weekday.substring(0, 2)));227		});228		return weekdayHtml;229	}230	231	function rebuildCalendar() {232		while(this.calendarBody.hasChildNodes()){233			this.calendarBody.removeChild(this.calendarBody.lastChild);234		}235		236		var firstOfMonth = new Date(this.currentYearView, this.currentMonthView, 1).getDay(),237		numDays = date.month.numDays(this.currentMonthView, this.currentYearView);238		239		this.currentMonth.innerHTML = date.month.string(this.config.fullCurrentMonth, this.currentMonthView, this.config.months) + ' ' + this.currentYearView;240		this.calendarBody.appendChild(buildDays(firstOfMonth, numDays, this.currentMonthView, this.currentYearView));241	}242	243	function buildCurrentMonth(config, currentMonthView, currentYearView, months) {244		return buildNode('span', { className: 'current-month' }, date.month.string(config.fullCurrentMonth, currentMonthView, months) + ' ' + currentYearView);245	}246	247	function buildMonths(config, currentMonthView, currentYearView) {248		var months = buildNode('div', { className: 'months' }),249		prevMonth = buildNode('span', { className: 'prev-month' }, buildNode('span', { className: 'prevMonth' }, '<')),250		nextMonth = buildNode('span', { className: 'next-month' }, buildNode('span', { className: 'nextMonth' }, '>'));251		252		months.appendChild(prevMonth);253		months.appendChild(nextMonth);254		255		return months;256	}257	258	function buildDays(firstOfMonth, numDays, currentMonthView, currentYearView) {259		var calendarBody = document.createDocumentFragment(),260		row = buildNode('tr'),261		dayCount = 0, i;262		263		/* print out previous month's "days" */264		for(i = 1; i <= firstOfMonth; i++) {265			row.appendChild(buildNode('td', null, ' '));266			dayCount++;267		}268		269		for(i = 1; i <= numDays; i++) {270			/* if we have reached the end of a week, wrap to the next line */271			if(dayCount == 7) {272				calendarBody.appendChild(row);273				row = buildNode('tr');274				dayCount = 0;275			}276			277			var todayClassName = isToday(i, currentMonthView, currentYearView) ? { className: 'today' } : null;278			row.appendChild(buildNode('td', todayClassName, buildNode('span', { className: 'day' }, i)));279			280			dayCount++;281		}282		283		/* if we haven't finished at the end of the week, start writing out the "days" for the next month */284		for(i = 1; i <= (7 - dayCount); i++) {285			row.appendChild(buildNode('td', null, ' '));286		}287		288		calendarBody.appendChild(row);289		290		return calendarBody;291	}292	293	function buildCalendar() {294		var firstOfMonth = new Date(this.currentYearView, this.currentMonthView, 1).getDay(),295		numDays = date.month.numDays(this.currentMonthView, this.currentYearView),296		self = this;297		298		var inputLeft = inputTop = 0,299		obj = this.element;300		301		if(obj.offsetParent) {302			do {303				inputLeft += obj.offsetLeft;304				inputTop += obj.offsetTop;305			} while (obj = obj.offsetParent);306		}307		308		var calendarContainer = buildNode('div', { className: 'calendar' });309		calendarContainer.style.cssText = 'display: none; position: absolute; top: ' + (inputTop + this.element.offsetHeight) + 'px; left: ' + inputLeft + 'px; z-index: 100;';310		311		this.currentMonth = buildCurrentMonth(this.config, this.currentMonthView, this.currentYearView, this.config.months)312		var months = buildMonths(this.config, this.currentMonthView, this.currentYearView);313		months.appendChild(this.currentMonth);314		315		var calendar = buildNode('table', null, buildNode('thead', null, buildNode('tr', { className: 'weekdays' }, buildWeekdays(this.config.weekdays))));316		this.calendarBody = buildNode('tbody');317		this.calendarBody.appendChild(buildDays(firstOfMonth, numDays, this.currentMonthView, this.currentYearView));318		calendar.appendChild(this.calendarBody);319		320		calendarContainer.appendChild(months);321		calendarContainer.appendChild(calendar);322		323		document.body.appendChild(calendarContainer);324		325		addEvent(calendarContainer, 'click', function(e) { handlers.calendarClick.call(self, e); });326		327		return calendarContainer;328	}329	330	return function(elementId, userConfig) {...im_send_message.js
Source:im_send_message.js  
...29    }else if(option.chatType == 'groupchat'){30        aMessage.setTo(option.toId + "@group.localhost");31        aMessage.setType("groupchat");32        if(option.atList){33            var atList = aMessage.buildNode("atList");34            for(var i = 0;i<option.atList.length;i++){35                atList.appendChild(aMessage.buildNode('at', option.atList[i]));36            }37        }3839    }40    aMessage.setBody(option.content);41    aMessage.setName(cmp.member.name);42    aMessage.appendNode(aMessage.buildNode('toname', option.toName));43    if(option.atList.length > 0){44        aMessage.appendNode(atList);45    }46    sendMsg(option.id,aMessage.xml(),null,option.errorFunc);47}4849/**50 *  ç³»ç»æ¶æ¯51 *  @param option  åæ°é52 *  id  æ¶æ¯id53 *  toId æåid54 *  toName æåidçå§å55 *  chatType è天类å å人 群56 *  content å
容57 *  errorFunc 失败çåè°æ¹æ³58 *  single dog single dog single all thd day~59 *  <message from="2481121618130258326@localhost/mobile" to="2753297105921130843@localhost" type="chat">60 *       <name>hd1</name>61 *       <body>Ddgf</body>62 *       <toname>hd2</toname>63 *  </message>64 */65function chatForSysMessage(option) {66    var aMessage = newJSJaCMessage();67    var jid = cmp.member.id;68    aMessage.setFrom(jid + "@localhost/mobile");69    aMessage.setID(option.id);70    if(option.chatType == 'chat'){71        aMessage.setTo(option.toId + "@localhost");72        aMessage.setType("system");73    }else if(option.chatType == 'groupchat'){74        aMessage.setTo(option.toId + "@group.localhost");75        aMessage.setType("system");76        if(option.atList){77            var atList = aMessage.buildNode("atList");78            for(var i = 0;i<option.atList.length;i++){79                atList.appendChild(aMessage.buildNode('at', option.atList[i]));80            }81        }8283    }84    aMessage.setBody(option.content);85    aMessage.setName(cmp.member.name);86    aMessage.appendNode(aMessage.buildNode('toname', option.toName));87    if(option.atList){88        aMessage.appendNode(atList);89    }90    sendMsg(option.id,aMessage.xml(),null,option.errorFunc);91}9293/**94 * åè¯é³æ¶æ¯95 * @param toId96 * @param toName97 * @param chatType98 * @param fileName99 * @param recordTime100 * @param errorFunc101 * <message from="2481121618130258326@localhost/mobile" to="2753297105921130843@localhost" type="microtalk" id="microtalk_1">102 *   <name>hd1</name>103 *   <toname>hd2</toname>104 *   <microtalk xmlns="microtalk">105 *     <id>2351776293</id>106 *     <size>3</size>107 *   </microtalk>108 * </message>109 */110function chatForVoice(toId,toName,chatType,fileName,recordTime,id,errorFunc){111    var aMessage = newJSJaCMessage();112    var jId = cmp.member.id;113114    aMessage.setFrom(jId + "@localhost/mobile");115    aMessage.setID(id);116    if(chatType == 'chat'){117        aMessage.setTo(toId + "@localhost");118    }else if(chatType == 'groupchat'){119        aMessage.setTo(toId + "@group.localhost");120    }121    aMessage.setType("microtalk");122    aMessage.setName(cmp.member.name);123    aMessage.appendNode(aMessage.buildNode('toname', toName));124125    var microTalk = aMessage.buildNode('microtalk');126    microTalk.setAttribute("xmlns","microtalk");127    microTalk.appendChild(aMessage.buildNode('id', fileName));128    microTalk.appendChild(aMessage.buildNode('size', recordTime));129    aMessage.appendNode(microTalk);130    sendMsg(jId,aMessage.xml(),null,errorFunc);131}132/**133 * åå¾çæ¶æ¯134 * @param toId135 * @param toName136 * @param chatType137 * @param fileId138 * @param fileName139 * @param errorFunc140 * <message from="2481121618130258326@localhost/mobile" to="2753297105921130843@localhost" type="image" id="image_1">141 *     <name>hd1</name>142 *     <toname>hd2</toname>143 *     <image xmlns="image">144 *         <id>3241353559</id>145 *         <id_thumbnail>3241353559_1</id_thumbnail>146 *         <name>2016112414241364.png</name>147 *         <size>60</size>148 *         <hash>4f71215587711e98f5ec9fbd5cb434db</hash>149 *         <date>2016-11-24T14:24:13.659000+08:00</date>150 *         <desc/>151 *     </image>152 * </message>153 */154function chatForImage(toId,toName,chatType,fileId,fileName,id,date,fileSize,errorFunc){155    var aMessage = newJSJaCMessage();156    var jId = cmp.member.id;157158    aMessage.setFrom(jId + "@localhost/mobile");159    aMessage.setID(id);160    if(chatType == 'chat'){161        aMessage.setTo(toId + "@localhost");162    }else if(chatType == 'groupchat'){163        aMessage.setTo(toId + "@group.localhost");164    }165    aMessage.setType("image");166    aMessage.setName(cmp.member.name);167    aMessage.appendNode(aMessage.buildNode('toname', toName));168169    var image = aMessage.buildNode('image');170    image.setAttribute("xmlns","image");171    image.appendChild(aMessage.buildNode('id', fileId));172    image.appendChild(aMessage.buildNode('id_thumbnail', fileId + "_1"));173    image.appendChild(aMessage.buildNode('name', fileName));174    image.appendChild(aMessage.buildNode('size',fileSize));175    image.appendChild(aMessage.buildNode('desc'));176    image.appendChild(aMessage.buildNode('date', date));177    aMessage.appendNode(image);178    sendMsg(jId,aMessage.xml(),null,errorFunc);179}180/**181 * åéä»¶æ¶æ¯182 * @param toId183 * @param toName184 * @param chatType185 * @param fileId186 * @param fileName187 * @param errorFunc188 * <message from="2481121618130258326@localhost/mobile" to="2753297105921130843@localhost" type="filetrans" id="filetrans_1">189 *    <name>hd1</name>190 *    <toname>hd2</toname>191 *    <filetrans xmlns="filetrans">192 *      <id>3823263968</id>193 *      <name>表å.txt</name>194 *      <size>1</size>195 *      <hash/>196 *      <date>2016-11-24T14:51:35.081000+08:00</date>197 *      <desc/>198 *    </filetrans>199 *  </message>200 */201function chatForFile(toId,toName,chatType,fileId,fileName,fileSize,id,errorFunc){202    var aMessage = newJSJaCMessage();203    var jId = cmp.member.id;204205    aMessage.setFrom(jId + "@localhost/mobile");206    aMessage.setID(id);207    if(chatType == 'chat'){208        aMessage.setTo(toId + "@localhost");209    }else if(chatType == 'groupchat'){210        aMessage.setTo(toId + "@group.localhost");211    }212    aMessage.setType("filetrans");213    aMessage.setName(cmp.member.name);214    aMessage.appendNode(aMessage.buildNode('toname', toName));215216    var file = aMessage.buildNode('filetrans');217    file.setAttribute("xmlns","filetrans");218    file.appendChild(aMessage.buildNode('id', fileId));219    file.appendChild(aMessage.buildNode('name', fileName));220    file.appendChild(aMessage.buildNode('size',fileSize));221    file.appendChild(aMessage.buildNode('desc'));222    aMessage.appendNode(file);223    sendMsg(jId,aMessage.xml(),null,errorFunc);224}225/**226 * æ¤æ¶æ¶æ¯227 * @param id228 * @param msgId229 * @param jId230 * @param name231 * @param toId232 * @param toName233 * @param successFunc234 * @param errorFunc235 * <message type='cancel_chat' id=â123456â from=â1234@localhostâ to=â1234@localhostâ>236 *     <to>111@localhost</to>  //ç宿¥æ¶è
237 * 	   <msgid></msgid> //被æ¤åçæ¶æ¯id238 * 	   <name></name>239 * 	   <toname></toname>240 * </message>241 */242function cancelChat(id,msgId,toId,toName,successFunc,errorFunc){243    var aMessage = newJSJaCMessage();244    var jId = cmp.member.id;245246    aMessage.setFrom(jId + "@localhost/mobile");247    aMessage.setID(id);248    aMessage.setTo(jId + "@localhost");249    aMessage.setType("cancel_chat");250    aMessage.setName(cmp.member.name);251    aMessage.appendNode(aMessage.buildNode('msgid', msgId));252    aMessage.appendNode(aMessage.buildNode('to', toId + "@localhost"));253    aMessage.appendNode(aMessage.buildNode('toname', toName));254255    sendMsg(id,aMessage.xml(),successFunc,errorFunc);256}257
...not.js
Source:not.js  
...5import StubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';6import ngMock from 'ng_mock';7import { expectDeepEqual } from '../../../../../test_utils/expect_deep_equal';8let indexPattern;9const childNode = nodeTypes.function.buildNode('is', 'response', 200);10describe('kuery functions', function () {11  describe('not', function () {12    beforeEach(ngMock.module('kibana'));13    beforeEach(ngMock.inject(function (Private) {14      indexPattern = Private(StubbedLogstashIndexPatternProvider);15    }));16    describe('buildNodeParams', function () {17      it('should return "arguments" and "serializeStyle" params', function () {18        const result = not.buildNodeParams(childNode);19        expect(result).to.only.have.keys('arguments', 'serializeStyle');20      });21      it('arguments should contain the unmodified child node', function () {22        const { arguments: [ actualChild ] } = not.buildNodeParams(childNode);23        expect(actualChild).to.be(childNode);24      });25      it('serializeStyle should default to "operator"', function () {26        const { serializeStyle } = not.buildNodeParams(childNode);27        expect(serializeStyle).to.be('operator');28      });29    });30    describe('toElasticsearchQuery', function () {31      it('should wrap a subquery in an ES bool query\'s must_not clause', function () {32        const node = nodeTypes.function.buildNode('not', childNode);33        const result = not.toElasticsearchQuery(node, indexPattern);34        expect(result).to.only.have.keys('bool');35        expect(result.bool).to.only.have.keys('must_not');36        expect(result.bool.must_not).to.eql(ast.toElasticsearchQuery(childNode, indexPattern));37      });38      it('should wrap a literal argument with an "is" function targeting the default_field', function () {39        const literalFoo = nodeTypes.literal.buildNode('foo');40        const expectedChild = ast.toElasticsearchQuery(nodeTypes.function.buildNode('is', null, 'foo'), indexPattern);41        const node = nodeTypes.function.buildNode('not', literalFoo);42        const result = not.toElasticsearchQuery(node, indexPattern);43        const resultChild = result.bool.must_not;44        expectDeepEqual(resultChild, expectedChild);45      });46    });47    describe('toKueryExpression', function () {48      it('should serialize "not" nodes with an operator syntax', function () {49        const node = nodeTypes.function.buildNode('not', childNode, 'operator');50        const result = not.toKueryExpression(node);51        expect(result).to.be('!"response":200');52      });53      it('should wrap "and" and "or" sub-queries in parenthesis', function () {54        const andNode = nodeTypes.function.buildNode('and', [childNode, childNode], 'operator');55        const notAndNode = nodeTypes.function.buildNode('not', andNode, 'operator');56        expect(not.toKueryExpression(notAndNode)).to.be('!("response":200 and "response":200)');57        const orNode = nodeTypes.function.buildNode('or', [childNode, childNode], 'operator');58        const notOrNode = nodeTypes.function.buildNode('not', orNode, 'operator');59        expect(not.toKueryExpression(notOrNode)).to.be('!("response":200 or "response":200)');60      });61      it('should not wrap "and" and "or" sub-queries that use the function syntax', function () {62        const andNode = nodeTypes.function.buildNode('and', [childNode, childNode], 'function');63        const notAndNode = nodeTypes.function.buildNode('not', andNode, 'operator');64        expect(not.toKueryExpression(notAndNode)).to.be('!and("response":200, "response":200)');65        const orNode = nodeTypes.function.buildNode('or', [childNode, childNode], 'function');66        const notOrNode = nodeTypes.function.buildNode('not', orNode, 'operator');67        expect(not.toKueryExpression(notOrNode)).to.be('!or("response":200, "response":200)');68      });69      it('should throw an error for nodes with unknown or undefined serialize styles', function () {70        const node = nodeTypes.function.buildNode('not', childNode, 'notValid');71        expect(not.toKueryExpression)72          .withArgs(node).to.throwException(/Cannot serialize "not" function as "notValid"/);73      });74    });75  });...mainToolsViewDemo.js
Source:mainToolsViewDemo.js  
...21function switchToVizMode() {22	config.userMode = "viz";23}24	function renderMainTools(){25		const left = buildNode(".left");26		left.appendChild(buildNode("h1","Filières du recyclage"));//"legend_title"));27		left.appendChild(buildNode("#loginButton.pictoButton.ghost"));28		left.appendChild(buildNode("#emailButton.pictoButton.ghost"));29		left.appendChild(buildNode("#faqButton.pictoButton.ghost"));30		left.appendChild(buildNode("#alertsButton.pictoButton.ghost"));31		const right = buildNode(".right");32		right.appendChild(buildNode("#visuButton.pictoButton.ghost"));33		right.appendChild(buildNode("#vizModeButton.pictoButton"));34		right.appendChild(buildNode("#editModeButton.pictoButton"));35		right.appendChild(buildNode("#diagramGenButton.pictoButton.ghost"));36		right.appendChild(buildNode("#printButton.pictoButton.ghost"));37		right.appendChild(buildNode("#exportData.pictoButton"));38		const search = buildNode("label#search.ghost");39		search.appendChild(buildNode(".decoSearch"));40		const searchField = buildNode("input","");41		searchField.type = "search";42		searchField.placeholder = "Rerchercher...";43		search.appendChild(searchField);44		right.appendChild(search);45		//right.appendChild(buildNode("#fakeLang.pictoButton.ghost"));46		anchorMainTools.innerHTML="";47		anchorMainTools.appendChild(left);48		anchorMainTools.appendChild(right);49	}50	return {51		init52	}...createElement.test.js
Source:createElement.test.js  
...13  test('createElement will return {}', ()=> {14    expect(createElement('span')).toMatchObject({})15  })16  test('createElement(x) will return vnode ', ()=> {17    expect(createElement('span')).toMatchObject(buildNode('span', null, []))18  })19  test('with attribute', () => {20    expect(createElement('span', {key:12, className:'ss'})).toMatchObject(buildNode('span',{key:12, className:'ss'} ))21  })22  test('createElement with children ', ()=> {23    expect(createElement('span', null, 'a', 1,2, h('w'))).toMatchObject(buildNode('span', null, ['a'+'1'+'2', h('w')]))24  })25  test('createElement with seque string', () => {26    expect(createElement('span', null,'a', 'b')).toMatchObject(buildNode('span', null, ['ab']))27  })28  test('createElement should support element', () =>{29    expect(h('span', null, h('x'))).toMatchObject(buildNode('span',null, [buildNode('x')]))30  })31  test('createElemnt child could be number', () => {32    expect(h('x', null, 1)).toMatchObject(buildNode('x', null, ['1']))33  })34  test('createElement only attributes cotaine children but ', () => {35    expect(h('x', { children: [h('x')] })).toMatchObject(buildNode('x',{}, [h('x')]))36  })37  test('children was bool, chang it to null', () =>{38    expect(h('x',null, true, false )).toMatchObject(buildNode('x', null, ['']))39  })40  test('children was null chang it to ""', () =>{41    expect(h('x',null, null, undefined )).toMatchObject(buildNode('x', null, ['']))42  })43  test('node was function', () => {44    expect(h(()=>'a'))45  })...solution.test.js
Source:solution.test.js  
...14        ]],15      ]],16    ]];17    const ast = parse(data);18    const expected = buildNode('html', {}, '', [19      buildNode('head', {}, '', [20        buildNode('title', {}, 'hello, hexlet!'),21      ]),22      buildNode('body', {}, '', [23        buildNode('h1', { class: 'header' }, 'html builder example'),24        buildNode('div', {}, '', [25          buildNode('span', {}, 'span text'),26          buildNode('hr'),27        ]),28      ]),29    ]);30    expect(ast).toEqual(expected);31  });32  it('#toString', () => {33    const data = ['html', [34      ['head', [35        ['title', 'hello, hexlet!'],36      ]],37      ['body', [38        ['div', { class: 'separator' }],39        ['h1', { class: 'header' }, 'html builder example'],40        ['div', [...Using AI Code Generation
1const { chromium } = require('playwright');2const fs = require('fs');3(async () => {4  const browser = await chromium.launch();5  const page = await browser.newPage();6  const html = await page.content();7  const dom = await page.evaluateHandle(() => document);8  const node = await dom.asElement().buildNode();9  fs.writeFileSync('test.html', html);10  fs.writeFileSync('test.json', JSON.stringify(node));11  await browser.close();12})();13{14    {15      "attributes": {16      },17        {18            {19              "attributes": {20              }21            },22            {23                {24                }25            }26        },27        {Using AI Code Generation
1const { buildNode } = require('playwright');2const { chromium } = require('playwright');3const { webkit } = require('playwright');4const { firefox } = require('playwright');5async function main() {6  const builder = await buildNode();7  const browser = await builder.buildChromium();8  const page = await browser.newPage();9  await page.screenshot({ path: 'example.png' });10  await browser.close();11}12main();13const builder = await buildNode();14const browser = await builder.buildChromium();15const page = await browser.newPage();16await page.screenshot({ path: 'example.png' });17await browser.close();18const builder = await buildNode();19const browser = await builder.buildChromium();20const page = await browser.newPage();21await page.screenshot({ path: 'example.png' });22await browser.close();23const builder = await buildNode();24const browser = await builder.buildChromium();25const page = await browser.newPage();26await page.screenshot({ path: 'example.png' });27await browser.close();28const builder = await buildNode();29const browser = await builder.buildChromium();30const page = await browser.newPage();31await page.screenshot({ path: 'example.png' });32await browser.close();33const builder = await buildNode();34const browser = await builder.buildChromium();35const page = await browser.newPage();36await page.screenshot({ path: 'example.png' });37await browser.close();38const builder = await buildNode();39const browser = await builder.buildChromium();40const page = await browser.newPage();41await page.screenshot({ path: 'example.png' });42await browser.close();Using AI Code Generation
1const { buildNode } = require('playwright-core/lib/server/dom.js');2const { parse } = require('playwright-core/lib/server/common/html.js');3const { ElementHandle } = require('playwright-core/lib/server/dom.js');4const html = `<div id="foo">Hello World</div>`;5const document = parse(html);6const node = document.getElementById('foo');7const elementHandle = new ElementHandle(buildNode(node), null, null, null);8console.log(elementHandle);9elementHandle.textContent().then(console.log);10const { chromium } = require('playwright-core');11(async () => {12  const browser = await chromium.launch();13  const context = await browser.newContext();14  const page = await context.newPage();15  const elementHandle = await page.$('div#foo');16  console.log(elementHandle);17  elementHandle.textContent().then(console.log);18  await browser.close();19})();Using AI Code Generation
1const { buildNode } = require('playwright-core/lib/server/dom');2const { jsdom } = require("jsdom");3const dom = new jsdom().window.document;4const node = buildNode(dom);5console.log(node);6const { buildNode } = require('playwright-core/lib/server/dom');7const { jsdom } = require("jsdom");8const dom = new jsdom().window.document;9const node = buildNode(dom);10console.log(node);11const { buildNode } = require('playwright-core/lib/server/dom');12const { jsdom } = require("jsdom");13const dom = new jsdom().window.document;14const node = buildNode(dom);15console.log(node);16const { buildNode } = require('playwright-core/lib/server/dom');17const { jsdom } = require("jsdom");18const dom = new jsdom().window.document;19const node = buildNode(dom);20console.log(node);21const { buildNode } = require('playwright-core/lib/server/dom');22const { jsdom } = require("jsdom");23const dom = new jsdom().window.document;24const node = buildNode(dom);25console.log(node);26const { buildNode } = require('playwright-core/lib/server/dom');27const { jsdom } = require("jsdom");28const dom = new jsdom().window.document;29const node = buildNode(dom);30console.log(node);31const { buildNode } = require('playwright-core/lib/server/dom');32const { jsdom } = require("jsdom");33const dom = new jsdom().window.document;34const node = buildNode(dom);35console.log(node);36const { buildNode } = require('playwright-core/lib/server/dom');37const { jsdom } = require("jsdom");38const dom = new jsdom().window.document;39const node = buildNode(dom);40console.log(node);41const { buildNode } = require('playwright-core/lib/server/dom');42const {Using AI Code Generation
1const { buildNode } = require('playwright-core/lib/server/dom.js');2const { parse } = require('playwright-core/lib/server/common/dom.js');3const { buildNode } = require('playwright-core/lib/server/dom.js');4const { parse } = require('playwright-core/lib/server/common/dom.js');5const html = '<div><span>hello</span><span>world</span></div>';6const parsedHtml = parse(html);7const dom = buildNode(parsedHtml);8console.log(dom.outerHTML);9const { buildNode } = require('playwright-core/lib/server/dom.js');10const { parse } = require('playwright-core/lib/server/common/dom.js');11const html = '<div><span>hello</span><span>world</span></div>';12const parsedHtml = parse(html);13const dom = buildNode(parsedHtml);14console.log(dom.outerHTML);15const { buildNode } = require('playwright-core/lib/server/dom.js');16const { parse } = require('playwright-core/lib/server/common/dom.js');17const html = '<div><span>hello</span><span>world</span></div>';18const parsedHtml = parse(html);19const dom = buildNode(parsedHtml);20console.log(dom.outerHTML);21const { buildNode } = require('playwright-core/lib/server/dom.js');22const { parse } = require('playwright-core/lib/server/common/dom.js');23const html = '<div><span>hello</span><span>world</span></div>';24const parsedHtml = parse(html);25const dom = buildNode(parsedHtml);26console.log(dom.outerHTML);27const { buildNodeUsing AI Code Generation
1const { buildNode } = require('playwright-core/lib/server/dom.js');2const { buildNode } = require('playwright/lib/server/dom.js');3const node = buildNode({4    attributes: {5    },6        { name: 'span', text: 'Hello' },7        { name: 'span', text: 'World' }8});9console.log(node.outerHTML);10import { buildNode } from 'playwright-core/lib/server/dom';11import { buildNode } from 'playwright/lib/server/dom';12const node = buildNode({13    attributes: {14    },15        { name: 'span', text: 'Hello' },16        { name: 'span', text: 'World' }17});18console.log(node.outerHTML);19const { buildNode } = require('playwright-core/lib/server/dom.js');20const { buildNode } = require('playwright/lib/server/dom.js');21const node = buildNode({22    attributes: {23    },24        { name: 'span', text: 'Hello' },25        { name: 'span', text: 'World' }26});27console.log(node.outerHTML);28import { buildNode } from 'playwright-core/lib/server/dom';29import { buildNode } from 'playwright/lib/server/dom';30const node = buildNode({31    attributes: {32    },33        { name: 'span', text: 'Hello' },Using AI Code Generation
1const { InternalApi } = require('playwright');2const { buildNode } = new InternalApi();3const node = buildNode('div');4const textNode = buildNode('text', 'Hello World');5node.appendChild(textNode);6console.log(node);Using AI Code Generation
1const { buildNode } = require('playwright-core/lib/server/dom.js');2const { createJSHandle } = require('playwright-core/lib/server/frames.js');3const { document: doc } = new JSDOM().window;4const node = buildNode(doc, {5    { name: 'id', value: 'hello' },6    { name: 'class', value: 'world' },7});8const handle = createJSHandle(doc.defaultView, node);9console.log(await handle.evaluate(node => node.outerHTML));10const { buildNode } = require('playwright-core/lib/server/dom.js');11const { createJSHandle } = require('playwright-core/lib/server/frames.js');12const { document: doc } = new JSDOM().window;13const node = buildNode(doc, {14    { name: 'id', value: 'hello' },15    { name: 'class', value: 'world' },16});17const handle = createJSHandle(doc.defaultView, node);18console.log(await handle.evaluate(node => node.outerHTML));19const { buildNode } = require('playwright-core/lib/server/dom.js');20const { createJSHandle } = require('playwright-core/lib/server/frames.js');21const { document: doc } = new JSDOM().window;22const node = buildNode(doc, {23    { name: 'id', value: 'hello' },24    { name: 'class', value: 'world' },25});26const handle = createJSHandle(doc.defaultView, node);27console.log(await handle.evaluate(node => node.outerHTML));28const { buildNode } = require('playwright-core/lib/server/dom.js');29const { createJSHandle } = require('playUsing AI Code Generation
1const buildNode = require('playwright-core/lib/server/supplements/recorder/buildNode');2const element = document.querySelector('button');3const node = buildNode(element);4console.log(node);5{ nodeName: 'BUTTON',6  attributes: { type: 'submit', class: 'btn btn-primary' },7  text: 'Submit' }8const { chromium } = require('playwright');9const buildNode = require('playwright-core/lib/server/supplements/recorder/buildNode');10(async () => {11  const browser = await chromium.launch();12  const context = await browser.newContext();13  const page = await context.newPage();14  const element = await page.$('text=Get started');15  const node = buildNode(element);16  console.log(node);17  await browser.close();18})();19{ nodeName: 'A',20  attributes: { href: '/docs/intro' },21  text: 'Get started' }Using AI Code Generation
1const buildNode = require('playwright/lib/utils/buildNode').buildNode;2element.setAttribute('id', 'test-id');3element.setAttribute('class', 'test-class');4element.textContent = 'This is a test';5const { chromium } = require('playwright');6(async () => {7  const browser = await chromium.launch();8  const context = await browser.newContext();9  const page = await context.newPage();10  await page.setContent(element.outerHTML);11  await page.screenshot({ path: 'test.png' });12  await browser.close();13})();14Related Posts: How to test a Progressive Web App (PWA) using…15How to test a Progressive Web App (PWA) using…LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!
