Best JavaScript code snippet using playwright-internal
validatePassword.test.js
Source:validatePassword.test.js
1import { validatePassword } from '../../src';2function checkEqual(value, opts, equalObj) {3 const result = validatePassword(value, opts);4 // console.log(result);5 const { validated, level, containes } = equalObj;6 const { number, lowerCaseLetter, upperCaseLetter, specialCharacter, unallowableCharacter } = containes;7 expect(result.validated).toEqual(validated);8 expect(result.level).toEqual(level);9 expect(result.containes.number).toEqual(number);10 expect(result.containes.lowerCaseLetter).toEqual(lowerCaseLetter);11 expect(result.containes.upperCaseLetter).toEqual(upperCaseLetter);12 expect(result.containes.specialCharacter).toEqual(specialCharacter);13 expect(result.containes.unallowableCharacter).toEqual(unallowableCharacter);14}15describe('validatePassword', () => {16 it('should be defined', () => {17 expect(validatePassword).toBeDefined();18 });19 it('éå符串', () => {20 checkEqual(21 true,22 {},23 {24 validated: false,25 level: 0,26 containes: {27 number: false,28 lowerCaseLetter: false,29 upperCaseLetter: false,30 specialCharacter: false,31 unallowableCharacter: false32 }33 }34 );35 checkEqual(36 1234,37 {},38 {39 validated: false,40 level: 0,41 containes: {42 number: false,43 lowerCaseLetter: false,44 upperCaseLetter: false,45 specialCharacter: false,46 unallowableCharacter: false47 }48 }49 );50 });51 it('1级强度 "1234787"', () => {52 checkEqual(53 '1234787',54 { level: 1 },55 {56 validated: true,57 level: 1,58 containes: {59 number: true,60 lowerCaseLetter: false,61 upperCaseLetter: false,62 specialCharacter: false,63 unallowableCharacter: false64 }65 }66 );67 });68 it('1级强度 "a1234787"', () => {69 checkEqual(70 'a1234787',71 { level: 1 },72 {73 validated: true,74 level: 2,75 containes: {76 number: true,77 lowerCaseLetter: true,78 upperCaseLetter: false,79 specialCharacter: false,80 unallowableCharacter: false81 }82 }83 );84 });85 it('1级强度 "ab1234787"', () => {86 checkEqual(87 'ab1234787',88 { level: 1 },89 {90 validated: true,91 level: 2,92 containes: {93 number: true,94 lowerCaseLetter: true,95 upperCaseLetter: false,96 specialCharacter: false,97 unallowableCharacter: false98 }99 }100 );101 });102 it('1级强度 "1a234787"', () => {103 checkEqual(104 '1a234787',105 { level: 1 },106 {107 validated: true,108 level: 2,109 containes: {110 number: true,111 lowerCaseLetter: true,112 upperCaseLetter: false,113 specialCharacter: false,114 unallowableCharacter: false115 }116 }117 );118 });119 it('1级强度 "a1_234787"', () => {120 checkEqual(121 'a1_234787',122 { level: 1 },123 {124 validated: true,125 level: 3,126 containes: {127 number: true,128 lowerCaseLetter: true,129 upperCaseLetter: false,130 specialCharacter: true,131 unallowableCharacter: false132 }133 }134 );135 });136 it('1级强度 "abc"', () => {137 checkEqual(138 'abc',139 { level: 1 },140 {141 validated: true,142 level: 1,143 containes: {144 number: false,145 lowerCaseLetter: true,146 upperCaseLetter: false,147 specialCharacter: false,148 unallowableCharacter: false149 }150 }151 );152 });153 it('1级强度 "*_ )"', () => {154 checkEqual(155 '*_ )',156 { level: 1 },157 {158 validated: false,159 level: 1,160 containes: {161 number: false,162 lowerCaseLetter: false,163 upperCaseLetter: false,164 specialCharacter: true,165 unallowableCharacter: true166 }167 }168 );169 });170 it('1级强度 "!@#$%^&*()-=_+[]|{},./?<>~`"', () => {171 checkEqual(172 '!@#$%^&*()-=_+[]|{},./?<>~`',173 { level: 1 },174 {175 validated: true,176 level: 1,177 containes: {178 number: false,179 lowerCaseLetter: false,180 upperCaseLetter: false,181 specialCharacter: true,182 unallowableCharacter: false183 }184 }185 );186 });187 it('2级强度 "!@#$%^&*()-=_+[]|{},./?<>~`"', () => {188 checkEqual(189 '!@#$%^&*()-=_+[]|{},./?<>~`',190 { level: 2 },191 {192 validated: false,193 level: 1,194 containes: {195 number: false,196 lowerCaseLetter: false,197 upperCaseLetter: false,198 specialCharacter: true,199 unallowableCharacter: false200 }201 }202 );203 });204 it('2级强度 "a12345678"', () => {205 checkEqual(206 'a12345678',207 { level: 2 },208 {209 validated: true,210 level: 2,211 containes: {212 number: true,213 lowerCaseLetter: true,214 upperCaseLetter: false,215 specialCharacter: false,216 unallowableCharacter: false217 }218 }219 );220 });221 it('2级强度 "a1_234787"', () => {222 checkEqual(223 'a1_234787',224 { level: 2 },225 {226 validated: true,227 level: 3,228 containes: {229 number: true,230 lowerCaseLetter: true,231 upperCaseLetter: false,232 specialCharacter: true,233 unallowableCharacter: false234 }235 }236 );237 });238 it('2级强度 "aa_234787"', () => {239 checkEqual(240 'aa_234787',241 { level: 2 },242 {243 validated: true,244 level: 3,245 containes: {246 number: true,247 lowerCaseLetter: true,248 upperCaseLetter: false,249 specialCharacter: true,250 unallowableCharacter: false251 }252 }253 );254 });255 it('3级强度 "a12345678"', () => {256 checkEqual(257 'a12345678',258 { level: 3 },259 {260 validated: false,261 level: 2,262 containes: {263 number: true,264 lowerCaseLetter: true,265 upperCaseLetter: false,266 specialCharacter: false,267 unallowableCharacter: false268 }269 }270 );271 });272 it('3级强度ï¼ä¸å¿½ç¥å¤§å°å "Aa12345678"', () => {273 checkEqual(274 'Aa12345678',275 { level: 3 },276 {277 validated: true,278 level: 3,279 containes: {280 number: true,281 lowerCaseLetter: true,282 upperCaseLetter: true,283 specialCharacter: false,284 unallowableCharacter: false285 }286 }287 );288 });289 it('3级强度ï¼å¿½ç¥å¤§å°å "Aa12345678"', () => {290 checkEqual(291 'Aa12345678',292 { level: 3, ignoreCase: true },293 {294 validated: false,295 level: 2,296 containes: {297 number: true,298 lowerCaseLetter: true,299 upperCaseLetter: true,300 specialCharacter: false,301 unallowableCharacter: false302 }303 }304 );305 });306 it('3级强度ï¼å¿½ç¥å¤§å°å "_Aa12345678" => true', () => {307 checkEqual(308 '_Aa12345678',309 { level: 3, ignoreCase: true },310 {311 validated: true,312 level: 3,313 containes: {314 number: true,315 lowerCaseLetter: true,316 upperCaseLetter: true,317 specialCharacter: true,318 unallowableCharacter: false319 }320 }321 );322 });323 it('3级强度ï¼éæ³å符 "_ Aa12345678"', () => {324 checkEqual(325 '_ Aa12345678',326 { level: 3, ignoreCase: true },327 {328 validated: false,329 level: 3,330 containes: {331 number: true,332 lowerCaseLetter: true,333 upperCaseLetter: true,334 specialCharacter: true,335 unallowableCharacter: true336 }337 }338 );339 });340 it('3级强度ï¼éæ³å符 "_Aaä¸äºä¸45678"', () => {341 checkEqual(342 '_Aaä¸äºä¸45678',343 { level: 3, ignoreCase: true },344 {345 validated: false,346 level: 3,347 containes: {348 number: true,349 lowerCaseLetter: true,350 upperCaseLetter: true,351 specialCharacter: true,352 unallowableCharacter: true353 }354 }355 );356 });357 it('3级强度ï¼èªå®ä¹ç¹æ®å符1', () => {358 checkEqual(359 '_Aaä¸äºä¸45678',360 { level: 3, ignoreCase: true, special: '_ä¸äºä¸' },361 {362 validated: true,363 level: 3,364 containes: {365 number: true,366 lowerCaseLetter: true,367 upperCaseLetter: true,368 specialCharacter: true,369 unallowableCharacter: false370 }371 }372 );373 });374 it('3级强度ï¼èªå®ä¹ç¹æ®å符2', () => {375 checkEqual(376 '_Aaä¸äºä¸45678=',377 { level: 3, ignoreCase: true, special: '_ä¸äºä¸' },378 {379 validated: false,380 level: 3,381 containes: {382 number: true,383 lowerCaseLetter: true,384 upperCaseLetter: true,385 specialCharacter: true,386 unallowableCharacter: true387 }388 }389 );390 });...
test.js
Source:test.js
1const isStartWithUpper = require('../src/isStartingWithUpperCase');2describe('isStartWithUpper', () => {3 describe('returns true if the first letter of the string is uppercase', () => {4 test('single length', () => {5 for(let i = 65; i < 91; i += 1) {6 const upperCaseLetter = String.fromCharCode(i);7 expect(isStartWithUpper(upperCaseLetter)).toBe(true);8 }9 })10 test('single length - falsy', () => {11 for(let i = 65; i < 91; i += 1) {12 const upperCaseLetter = String.fromCharCode(i);13 expect(isStartWithUpper(upperCaseLetter)).not.toBe(false);14 }15 })16 test('various lengths', () => {17 for(let i = 65; i < 91; i += 1) {18 const upperCaseLetter = String.fromCharCode(i);19 const charCode = 65 + Math.floor(Math.random() * 58);20 const continuations = `${String.fromCharCode(charCode).repeat(Math.ceil(Math.random() * 100))}`;21 const string = `${upperCaseLetter}${continuations}`22 expect(isStartWithUpper(string)).toBe(true);23 }24 })25 test('various lengths - falsy', () => {26 for(let i = 65; i < 91; i += 1) {27 const upperCaseLetter = String.fromCharCode(i);28 const charCode = 65 + Math.floor(Math.random() * 58);29 const continuations = `${String.fromCharCode(charCode).repeat(Math.ceil(Math.random() * 100))}`;30 const string = `${upperCaseLetter}${continuations}`31 expect(isStartWithUpper(string)).not.toBe(false);32 }33 })34 })35 describe('returns false if the first letter of the string is downcase', () => {36 test('single length - before 65', () => {37 for(let i = 0; i < 65; i += 1) {38 const upperCaseLetter = String.fromCharCode(i);39 expect(isStartWithUpper(upperCaseLetter)).toBe(false);40 }41 })42 test('single length - before 65 - falsy', () => {43 for(let i = 0; i < 65; i += 1) {44 const upperCaseLetter = String.fromCharCode(i);45 expect(isStartWithUpper(upperCaseLetter)).not.toBe(true);46 }47 })48 test('single length - after 91', () => {49 for(let i = 91; i < 65535; i += 1) {50 const upperCaseLetter = String.fromCharCode(i);51 expect(isStartWithUpper(upperCaseLetter)).toBe(false);52 }53 })54 test('single length - after 91 - falsy', () => {55 for(let i = 91; i < 65535; i += 1) {56 const upperCaseLetter = String.fromCharCode(i);57 expect(isStartWithUpper(upperCaseLetter)).not.toBe(true);58 }59 })60 })61 describe('edge cases', () => {62 test('empty string argument returns false', () => {63 expect(isStartWithUpper('')).toBe(false);64 })65 test('empty string argument returns false - falsy', () => {66 expect(isStartWithUpper('')).not.toBe(true);67 })68 test('no argument returns false', () => {69 expect(isStartWithUpper()).toBe(false);70 })71 test('no argument returns false - falsy', () => {72 expect(isStartWithUpper()).not.toBe(true);73 })74 describe('input validation', () => {75 test('pass an object returns false', () => {76 expect(isStartWithUpper({})).toBe(false);77 })78 test('pass an object returns false - falsy', () => {79 expect(isStartWithUpper({})).not.toBe(true);80 })81 test('pass an array returns false', () => {82 expect(isStartWithUpper([])).toBe(false);83 })84 test('pass an array returns false - falsy', () => {85 expect(isStartWithUpper([])).not.toBe(true);86 })87 test('pass undefined returns false', () => {88 expect(isStartWithUpper(undefined)).toBe(false);89 })90 test('pass undefined returns false - falsy', () => {91 expect(isStartWithUpper(undefined)).not.toBe(true);92 })93 test('pass null returns false', () => {94 expect(isStartWithUpper(null)).toBe(false);95 })96 test('pass null returns false - falsy', () => {97 expect(isStartWithUpper(null)).not.toBe(true);98 })99 test('pass boolean returns false', () => {100 expect(isStartWithUpper(false)).toBe(false);101 })102 test('pass boolean returns false - falsy', () => {103 expect(isStartWithUpper(false)).not.toBe(true);104 })105 test('pass number returns false', () => {106 expect(isStartWithUpper(123)).toBe(false);107 })108 test('pass number returns false - falsy', () => {109 expect(isStartWithUpper(123)).not.toBe(true);110 })111 test('pass function returns false', () => {112 expect(isStartWithUpper(function fName() {})).toBe(false);113 })114 test('pass function returns false - falsy', () => {115 expect(isStartWithUpper(function fName() {})).not.toBe(true);116 })117 test('pass symbol returns false', () => {118 expect(isStartWithUpper(Symbol('sym'))).toBe(false);119 })120 test('pass symbol returns false - falsy', () => {121 expect(isStartWithUpper(Symbol('sym'))).not.toBe(true);122 })123 })124 })125 describe('real world examples', () => {126 test('Help Scout', () => {127 expect(isStartWithUpper('Help Scout')).toBe(true)128 })129 test('Help Scout - falsy', () => {130 expect(isStartWithUpper('Help Scout')).not.toBe(false)131 })132 test('HelpScout', () => {133 expect(isStartWithUpper('HelpScout')).toBe(true)134 })135 test('HelpScout - falsy', () => {136 expect(isStartWithUpper('HelpScout')).not.toBe(false)137 })138 test('Scout', () => {139 expect(isStartWithUpper('Scout')).toBe(true)140 })141 test('Scout - falsy', () => {142 expect(isStartWithUpper('Scout')).not.toBe(false)143 })144 test('help scout', () => {145 expect(isStartWithUpper('help scout')).toBe(false)146 })147 test('help scout - falsy', () => {148 expect(isStartWithUpper('help scout')).not.toBe(true)149 })150 test('scout', () => {151 expect(isStartWithUpper('scout')).toBe(false)152 })153 test('scout - falsy', () => {154 expect(isStartWithUpper('scout')).not.toBe(true)155 })156 })...
script.js
Source:script.js
1// Define variables2var userinput;3var picknumber;4var pickSpecialCharacter;5var pickUppercase;6var pickLowercase;7var picks;8var specialcharacter = [" ", "!", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", "\:", "\;", "<", "=", ">", "?", "@", "[", "\\", "]", "^", "_", "`", "{", "|", "}", "~"];9var number = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];10var letter = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];11var uppercaseletter = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];12var generateBtn = document.querySelector("#generate");13// Define a function when generate button is clicked14generateBtn.addEventListener("click", function () {15 var password = generatePassword();16 document.getElementById("password").placeholder = password;17});18// Prompt user to pick and choose random combinations19function generatePassword() {20 userinput = prompt("Please choose between 8 and 128 characters for your password");21 if (!userinput) {22 alert("No empty value");23 } else if (userinput < 8 || userinput > 128) {24 userinput = alert("Choose between 8 and 128, TRY AGAIN!");25 } else {26 picknumber = confirm("Do you want to include numbers?");27 pickSpecialCharacter = confirm("Do you want to include special characters?");28 pickUppercase = confirm("Do you want to include Uppercase letters?");29 pickLowercase = confirm("Do you want to include Lowercase letters?");30 };31 if (!pickSpecialCharacter && !picknumber && !pickUppercase && !pickLowercase) {32 picks = alert("You didn't choose anything");33 }34 else if (pickSpecialCharacter && picknumber && pickUppercase && pickLowercase) {35 picks = specialcharacter.concat(number, letter, uppercaseletter);36 }37 else if (pickSpecialCharacter && picknumber && pickUppercase) {38 picks = specialcharacter.concat(number, uppercaseletter);39 }40 else if (pickSpecialCharacter && picknumber && pickLowercase) {41 picks = specialcharacter.concat(number, letter);42 }43 else if (pickSpecialCharacter && pickLowercase && pickUppercase) {44 picks = specialcharacter.concat(letter, uppercaseletter);45 }46 else if (picknumber && pickLowercase && pickUppercase) {47 picks = number.concat(letter, uppercaseletter);48 }49 else if (pickSpecialCharacter && picknumber) {50 picks = specialcharacter.concat(number);51 } else if (pickSpecialCharacter && pickLowercase) {52 picks = specialcharacter.concat(letter);53 } else if (pickSpecialCharacter && pickUppercase) {54 picks = specialcharacter.concat(uppercaseletter);55 }56 else if (pickLowercase && picknumber) {57 picks = letter.concat(number);58 } else if (pickLowercase && pickUppercase) {59 picks = letter.concat(uppercaseletter);60 } else if (picknumber && pickUppercase) {61 picks = number.concat(uppercaseletter);62 }63 else if (pickSpecialCharacter) {64 picks = specialcharacter;65 }66 else if (picknumber) {67 picks = number;68 }69 else if (pickLowercase) {70 picks = letter;71 }72 else if (pickUppercase) {73 picks = uppercaseletter;74 };75 var password = [];76 for (var i = 0; i < userinput; i++) {77 var randompick = picks[Math.floor(Math.random() * picks.length)];78 password.push(randompick);79 }80 var password = password.join("");81 UserInput(password);82 return password;83}84function UserInput(password) {85 document.getElementById("password").textContent = password;86}87//Function to copy generated password to text box88function copyPassword() {89 document.getElementById("password").select();90 document.execCommand("Copy");91}92var copy = document.querySelector("#password");93 copy.addEventListener("click", function () {94 copyPassword();...
mfr-lec.js
Source:mfr-lec.js
1// Pop quiz!2// -----------------------------------------------------------------------3// What do we mean by map, filter, reduce?4// How do these affect our arrays?5// What data type are we using these methods on?6// -----------------------------------------------------------------------7// Problem: Manipulate an array of numbers in a way that we see a new8// array of just the even numbers from the previous array.9var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];10var evens = [];11// How do we do this with our current knowledge?12// numbers.forEach(function(data){13// if(data % 2 === 0) {14// evens.push(data);15// }16// });17// console.log(numbers);18// console.log(evens);19//Get ready to hate me...20// evens = numbers.filter(n => n % 2 === 0);21// console.log(evens);22// Problem: Create an array by filtering an array of integers that only23// has numbers that have square roots that are whole numbers.24// let wholeSquareRoots = numbers.filter(n => {25// let sqrt = Math.sqrt(n);26// return sqrt % 1 === 0;27// });28//29// console.log(wholeSquareRoots);30// -----------------------------------------------------------------------31// Problem: Create an array from another array where each number from32// the previous array is squared.33// const squares = numbers.map(n => {34// return n * n;35// });36// console.log(squares);37// -----------------------------------------------------------------------38// Problem: Create a function that will take an array of sales person39// objects and return the average sales for the staff.40let salesPersons = [41 {name: 'David', sales: 3200, empId: 620774},42 {name: 'Justin', sales: 3800, empId: 613310},43 {name: 'Terrell', sales: 2200, empId: 609482},44 {name: 'Sophie', sales: 4400, empId: 620612},45 {name: 'Fernando', sales: 5200, empId: 600350},46 {name: 'Daniel', sales: 3600, empId: 618090},47 {name: 'Ryan', sales: 3800, empId: 599135},48 {name: 'Zach', sales: 4000, empId: 599991},49 {name: 'Maggie', sales: 3800, empId: 618921}50];51// const getAverageSales = employees => {52// let totalSales = employees.reduce((accumulator,employee) => {53// return employee.sales + accumulator;54// }, 0);55// console.log(totalSales);56// return totalSales/employees.length;57// };58//59// console.log(getAverageSales(salesPersons));60// -----------------------------------------------------------------------61// Problem: Create a function that reduces a string, and returns the62// longest word from it. If there is a tie, it will return the earlier63// word.64const testSentence1 = "It's Supercalifragilisticexpialidocious; even though the sound of it is something quite atrocious";65const testSentence2 = "The relish fish was delish and it made quite a dish.";66// const longestWord = sentence => {67// // How do I do this?68// let splitSentence = sentence.split(" ");69// let longestWord = splitSentence.reduce((biggestWord, word) => {70// if (word.length > biggestWord.length){71// biggestWord = word;72// }73// return biggestWord;74// }, "");75// return longestWord;76// };77//78// console.log(longestWord(testSentence1));79// console.log(longestWord(testSentence2));80// -----------------------------------------------------------------------81// Problem: Create a function that will take in a word, set all the82// letters to upper case, and remove the vowels (Y is a consonant).83// const withoutVowels = word => {84// let splitWord = word.split("");85// return splitWord.reduce((accumulator, letter) => {86// let uppercaseLetter = letter.toUpperCase();87// if (uppercaseLetter !== "A" && uppercaseLetter !== "E" && uppercaseLetter !== "I" && uppercaseLetter !== "O" && uppercaseLetter !== "U"){88// return accumulator + uppercaseLetter;89// }90// return accumulator;91// }, "")92// };...
register.js
Source:register.js
1$("#username").on("change keyup", function () {2 if (this.value.length > 0) {3 $.post("/check", { "user": this.value }, function (result) {4 $("#register").prop("disabled", result);5 });6 } else {7 $("#register").prop("disabled", !result);8 }9});101112$(function () {13 var $password = $(".form-control[type='password']");14 var $passwordAlert = $(".password-alert");15 var $requirements = $(".requirements");16 var leng, upperCaseLetter, num, specialChar;17 var $leng = $(".leng");18 var $upperCaseLetter = $(".uppercase-letter");19 var $num = $(".num");20 var $specialChar = $(".special-char");21 var specialChars = "!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?`~";22 var numbers = "0123456789";2324 $requirements.addClass("wrong");25 $password.on("focus", function () { $passwordAlert.show(); });2627 $password.on("input blur", function (e) {28 var el = $(this);29 var val = el.val();30 $passwordAlert.show();3132 if (val.length < 8) {33 leng = false;34 } else if (val.length > 7) {35 leng = true;36 }373839 if (val.toLowerCase() == val) {40 upperCaseLetter = false;41 } else { upperCaseLetter = true; }4243 num = false;44 for (var i = 0; i < val.length; i++) {45 for (var j = 0; j < numbers.length; j++) {46 if (val[i] == numbers[j]) {47 num = true;48 }49 }50 }5152 specialChar = false;53 for (var i = 0; i < val.length; i++) {54 for (var j = 0; j < specialChars.length; j++) {55 if (val[i] == specialChars[j]) {56 specialChar = true;57 }58 }59 }6061 if (leng == true && upperCaseLetter == true && num == true && specialChar == true) {62 $(this).addClass("valid").removeClass("invalid");63 $requirements.removeClass("wrong").addClass("good");64 $passwordAlert.removeClass("alert-warning").addClass("alert-success");65 $passwordAlert.hide();66 $("#register").prop("disabled", false);67 } else {68 $(this).addClass("invalid").removeClass("valid");69 $passwordAlert.removeClass("alert-success").addClass("alert-warning");70 $("#register").prop("disabled", true);7172 if (leng == false) {73 $leng.addClass("wrong").removeClass("good");74 } else {75 $leng.addClass("good").removeClass("wrong");76 }7778 if (upperCaseLetter == false) {79 $upperCaseLetter.addClass("wrong").removeClass("good");80 } else {81 $upperCaseLetter.addClass("good").removeClass("wrong");82 }8384 if (num == false) {85 $num.addClass("wrong").removeClass("good");86 } else {87 $num.addClass("good").removeClass("wrong");88 }8990 if (specialChar == false) {91 $specialChar.addClass("wrong").removeClass("good");92 } else {93 $specialChar.addClass("good").removeClass("wrong");94 }95 }96 });
...
index.js
Source:index.js
1import { useState, useRef } from "react";2import '../../styles/global.css';3const isNumberRegx = /\d/;4const upperCaseLetterRegx = /[A-Z]/;5const specialCharacterRegx = /[ !¹²³£¢¬ª~´°@#$%^&*()_+¨§º·`\-[\]/={};':"\\|,.<>?]/;6export function Home() {7 const [password, setPassword] = useState("");8 const numeric = useRef(null);9 const upperCaseLetter = useRef(null);10 const specialCharacter = useRef(null);11 const minimumCharacter = useRef(null);12 const input = useRef(null);13 const onChangePassword = password => {14 setPassword(password);15 if (isNumberRegx.test(password)) {16 numeric.current.style.textDecoration = "line-through";17 numeric.current.style.color = "chartreuse"18 } else {19 numeric.current.style.textDecoration = "";20 numeric.current.style.color = ""21 }22 if (upperCaseLetterRegx.test(password)) {23 upperCaseLetter.current.style.textDecoration = "line-through";24 upperCaseLetter.current.style.color = "chartreuse"25 } else {26 upperCaseLetter.current.style.textDecoration = "";27 upperCaseLetter.current.style.color = ""28 }29 if (specialCharacterRegx.test(password)) {30 specialCharacter.current.style.textDecoration = "line-through";31 specialCharacter.current.style.color = "chartreuse"32 } else {33 specialCharacter.current.style.textDecoration = "";34 specialCharacter.current.style.color = ""35 }36 if (password.length >= 8) {37 minimumCharacter.current.style.textDecoration = "line-through";38 minimumCharacter.current.style.color = "chartreuse"39 } else {40 minimumCharacter.current.style.textDecoration = "";41 minimumCharacter.current.style.color = ""42 }43 if (isNumberRegx.test(password) && upperCaseLetterRegx.test(password) && specialCharacterRegx.test(password) && password.length >= 8) {44 input.current.style.border = "1px solid chartreuse"45 } else {46 input.current.style.border = ""47 }48 }49 return(50 <div className='wrapper'>51 <div>52 <p ref={numeric}>Número</p>53 <p ref={upperCaseLetter}>Letra maiúscula</p>54 <p ref={specialCharacter}>Caractere especial</p>55 <p ref={minimumCharacter}>MÃnimo de 8 caracteres</p>56 </div>57 <div className='password'>58 <input59 type='text'60 placeholder='Informe a sua senha'61 ref={input}62 value={password}63 onChange={e => onChangePassword(e.target.value)}64 />65 </div>66 </div>67 );...
Quote.js
Source:Quote.js
1export class Quote {2 constructor(text) {3 this.text = text;4 this.guessed = [];5 }6 getContent() {7 let content = "";8 for (const char of this.text) {9 if (char == ' ' || this.guessed.includes(char)) {10 content += char;11 }12 else content += '_';13 }14 return content;15 }16 guess(letter) {17 const upperCaseLetter = letter.toUpperCase();18 const lowerCaseLetter = letter;19 if (this.text.includes(upperCaseLetter)) {20 this.guessed.push(upperCaseLetter);21 if (this.text.includes(lowerCaseLetter)) {22 this.guessed.push(lowerCaseLetter);23 }24 return true;25 }26 if (this.text.includes(lowerCaseLetter)) {27 this.guessed.push(lowerCaseLetter);28 if (this.text.includes(upperCaseLetter)) {29 this.guessed.push(upperCaseLetter);30 }31 return true;32 }33 return false;34 }...
capitalize-word.js
Source:capitalize-word.js
1/* exported capitalizeWord */2// 2 capitalizeWord(word)3function capitalizeWord(word) {4 var lowerCase = word.toLowerCase();5 if (lowerCase === 'javascript') {6 return 'JavaScript';7 } else {8 var upperCaseLetter = lowerCase[0].toUpperCase();9 upperCaseLetter = upperCaseLetter + word.toLowerCase().slice(1);10 return upperCaseLetter;11 }...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click('#navbar a:has-text("Docs")');
Using AI Code Generation
1const { test, expect } = require('@playwright/test');2test('uppercaseLetter', async ({ page }) => {3 await page.click('text=Get started');4 await page.click('text=API');5 await page.click('text=Internal API');6 await page.click('text=class Page');7 await page.click('text=uppercaseLetter');8 await page.click('text=Usage');9 const text = await page.$eval('pre', (e) => e.textContent);10 expect(text).toContain('page.uppercaseLetter');11});12const { test, expect } = require('@playwright/test');13test('uppercaseLetter', async ({ page }) => {14 await page.click('text=Get started');15 await page.click('text=API');16 await page.click('text=Internal API');17 await page.click('text=class Page');18 await page.click('text=uppercaseLetter');19 await page.click('text=Usage');20 const text = await page.$eval('pre', (e) => e.textContent);21 expect(text).toContain('page.uppercaseLetter');22});23const { test, expect } = require('@playwright/test');24test('uppercaseLetter', async ({ page }) => {25 await page.click('text=Get started');26 await page.click('text=API');27 await page.click('text=Internal API');28 await page.click('text=class Page');29 await page.click('text=uppercaseLetter');30 await page.click('text=Usage');31 const text = await page.$eval('pre', (e) => e.textContent);32 expect(text).toContain('page.uppercaseLetter');33});34const { test, expect } = require('@playwright/test');35test('uppercaseLetter', async ({ page }) => {36 await page.click('text=Get started');37 await page.click('text=API');38 await page.click('text=Internal API');39 await page.click('text=
Using AI Code Generation
1const { uppercaseLetter } = require('@playwright/test');2const { test } = require('@playwright/test');3test('uppercase', async ({page}) => {4 const title = await page.innerText('.navbar__inner .navbar__title');5 expect(uppercaseLetter(title)).toBe('PLAYWRIGHT');6});7const { lowercaseLetter } = require('@playwright/test');8const { test } = require('@playwright/test');9test('lowercase', async ({page}) => {10 const title = await page.innerText('.navbar__inner .navbar__title');11 expect(lowercaseLetter(title)).toBe('playwright');12});13const { titlecaseLetter } = require('@playwright/test');14const { test } = require('@playwright/test');15test('titlecase', async ({page}) => {16 const title = await page.innerText('.navbar__inner .navbar__title');17 expect(titlecaseLetter(title)).toBe('Playwright');18});19const { camelcaseLetter } = require('@playwright/test');20const { test } = require('@playwright/test');21test('camelcase', async ({page}) => {22 const title = await page.innerText('.navbar__inner .navbar__title');23 expect(camelcaseLetter(title)).toBe('playwright');24});25const { pascalcaseLetter } = require('@playwright/test');26const { test } = require('@playwright/test');27test('pascalcase', async ({page}) => {28 const title = await page.innerText('.navbar__inner .navbar__title');29 expect(pascalcaseLetter(title)).toBe('Playwright');30});31const { snakecaseLetter } = require('@playwright/test');32const { test } = require('@playwright/test');33test('snakecase', async ({page}) => {
Using AI Code Generation
1const { uppercaseLetter } = require('playwright-internal-library');2console.log(uppercaseLetter('hello'));3const { uppercaseLetter } = require('playwright-internal-library');4module.exports = {5 testDir: uppercaseLetter('test')6};7"dependencies": {8}
Using AI Code Generation
1const { helper } = require('@playwright/test');2const { toTitleCase } = require('to-title-case');3const { helper } = require('@playwright/test');4const { toTitleCase } = require('to-title-case');5const toTitleCase = (text) => {6 return text.split(' ').map(word => word[0].toUpperCase() + word.slice(1).toLowerCase()).join(' ');7};8const toTitleCase = (text) => {9 return text.split(' ').map(word => word[0].toUpperCase() + word.slice(1).toLowerCase()).join(' ');10};11const { helper } = require('@playwright/test');12const { toTitleCase } = require('to-title-case');13const toTitleCase = (text) => {14 return text.split(' ').map(word => word[0].toUpperCase() + word.slice(1).toLowerCase()).join(' ');15};16const { helper } = require('@playwright/test');17const { toTitleCase } = require('to-title-case');18const toTitleCase = (text) => {19 return text.split(' ').map(word => word[0].toUpperCase() + word.slice(1).toLowerCase()).join(' ');20};21const toTitleCase = (text) => {22 return text.split(' ').map(word => word[0].toUpperCase() + word.slice(1).toLowerCase()).join(' ');23};24const { helper } = require('@playwright/test');25const { toTitleCase } = require('to-title-case');26const toTitleCase = (text) => {27 return text.split(' ').map(word => word[0].toUpperCase() + word.slice(1).toLowerCase()).join(' ');28};29const toTitleCase = (text) => {30 return text.split(' ').map(word => word[0].toUpperCase() + word.slice(1).toLowerCase()).join(' ');31};32const { helper } = require('@playwright/test');33const { toTitleCase } = require('to-title-case');34const toTitleCase = (text) => {35 return text.split(' ').map(word => word[0].toUpperCase() + word.slice(
Using AI Code Generation
1const {uppercaseLetter} = require('@playwright/test/lib/utils');2const result = uppercaseLetter(text);3console.log(result);4randomString(length, chars)5const {randomString} = require('@playwright/test/lib/utils');6const length = 10;7const chars = 'abc';8const result = randomString(length, chars);9console.log(result);10randomNumber(min, max)11const {randomNumber} = require('@playwright/test/lib/utils');12const min = 0;13const max = 10;14const result = randomNumber(min, max);15console.log(result);
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!!