Best JavaScript code snippet using ava
Radio.js
Source:Radio.js
2 var field, fieldset;3 function makeField(cfg) {4 field = new Ext.field.Radio(cfg);5 }6 function makeGroup(fields) {7 fields.forEach(function(f) {8 f.name = 'group';9 });10 fieldset = new Ext.form.FieldSet({11 defaultType: 'radiofield',12 items: fields13 });14 fieldset.renderTo(Ext.getBody());15 }16 afterEach(function() {17 fieldset = field = Ext.destroy(field, fieldset);18 });19 describe("getGroupValue", function() {20 it("should return the value of the radio configured with checked: true", function() {21 makeGroup([{22 value: 'red'23 }, {24 checked: true,25 value: 'blue'26 }]);27 var fields = fieldset.query('radiofield');28 fields.forEach(function(f) {29 expect(f.getGroupValue()).toBe('blue');30 });31 });32 it("should return the value of the checked radio when selection changes", function() {33 makeGroup([{34 value: 'red'35 }, {36 checked: true,37 value: 'blue'38 }]);39 fieldset.items.first().check();40 var fields = fieldset.query('radiofield');41 fields.forEach(function(f) {42 expect(f.getGroupValue()).toBe('red');43 });44 });45 it("should return null if no item is checked", function() {46 makeGroup([{47 value: 'red'48 }, {49 value: 'blue'50 }]);51 var fields = fieldset.query('radiofield');52 fields.forEach(function(f) {53 expect(f.getGroupValue()).toBeNull();54 });55 });56 });57 describe("checked state", function() {58 function expectChecked(states) {59 var len = states.length,60 i;61 for (i = 0; i < len; ++i) {62 expect(fieldset.getAt(i).getChecked()).toBe(states[i]);63 }64 }65 it("should be able to have no item checked initially", function() {66 makeGroup([{67 value: 'red'68 }, {69 value: 'blue'70 }, {71 value: 'green'72 }]);73 expectChecked([false, false, false]);74 });75 it("should have the checked item checked, other items unchecked", function() {76 makeGroup([{77 value: 'red'78 }, {79 value: 'blue',80 checked: true81 }, {82 value: 'green'83 }]);84 expectChecked([false, true, false]);85 });86 it("should uncheck the checked item when checking a new item", function() {87 makeGroup([{88 value: 'red'89 }, {90 value: 'blue'91 }, {92 value: 'green'93 }]);94 fieldset.getAt(0).check();95 expectChecked([true, false, false]);96 fieldset.getAt(1).check();97 expectChecked([false, true, false]);98 fieldset.getAt(2).check();99 expectChecked([false, false, true]);100 });101 it("should allow the checked item to be unchecked", function() {102 makeGroup([{103 value: 'red',104 checked: true105 }, {106 value: 'blue'107 }, {108 value: 'green'109 }]);110 fieldset.getAt(0).uncheck();111 expectChecked([false, false, false]);112 });113 });114 // Currently this fails on Tablets, because it's not translating115 // the click to tap.116 xdescribe("change via the UI", function() {117 it("should set checked when clicking", function() {118 makeGroup([{119 value: 'red',120 checked: true121 }, {122 value: 'blue'123 }]);124 var f = fieldset.getAt(1);125 jasmine.fireMouseEvent(f.getComponent().mask.dom, 'click');126 expect(fieldset.getAt(0).getChecked()).toBe(false);127 expect(f.getChecked()).toBe(true);128 });129 });130 describe("state methods", function() {131 var changeSpy, checkSpy, uncheckSpy;132 beforeEach(function() {133 changeSpy = jasmine.createSpy();134 checkSpy = jasmine.createSpy();135 uncheckSpy = jasmine.createSpy();136 });137 afterEach(function() {138 changeSpy = checkSpy = uncheckSpy = null;139 });140 function attachSpies(f) {141 f.on({142 change: changeSpy,143 check: checkSpy,144 uncheck: uncheckSpy145 });146 }147 describe("setChecked", function() {148 describe("setChecked(true)", function() {149 describe("when not checked", function() {150 beforeEach(function() {151 makeGroup([{152 value: 'red'153 }, {154 value: 'blue'155 }])156 });157 it("should set the checked state", function() {158 var f = fieldset.getAt(0);159 f.setChecked(true);160 expect(f.getChecked()).toBe(true);161 expect(f.isChecked()).toBe(true);162 });163 it("should fire change, check, not fire uncheck", function() {164 var f = fieldset.getAt(0);165 attachSpies(f);166 f.setChecked(true);167 expect(changeSpy.callCount).toBe(1);168 expect(changeSpy.mostRecentCall.args[0]).toBe(f);169 expect(changeSpy.mostRecentCall.args[1]).toBe(true);170 expect(changeSpy.mostRecentCall.args[2]).toBe(false);171 expect(checkSpy.callCount).toBe(1);172 expect(checkSpy.mostRecentCall.args[0]).toBe(f);173 expect(uncheckSpy).not.toHaveBeenCalled();174 });175 });176 describe("when checked", function() {177 beforeEach(function() {178 makeGroup([{179 value: 'red',180 checked: true181 }, {182 value: 'blue'183 }])184 });185 it("should set the checked state", function() {186 var f = fieldset.getAt(0);187 f.setChecked(true);188 expect(f.getChecked()).toBe(true);189 expect(f.isChecked()).toBe(true);190 });191 it("should not fire any events", function() {192 var f = fieldset.getAt(0);193 attachSpies(f);194 f.setChecked(true);195 196 expect(changeSpy).not.toHaveBeenCalled();197 expect(checkSpy).not.toHaveBeenCalled();198 expect(uncheckSpy).not.toHaveBeenCalled();199 });200 });201 });202 describe("setChecked(false)", function() {203 describe("when not checked", function() {204 beforeEach(function() {205 makeGroup([{206 value: 'red'207 }, {208 value: 'blue'209 }])210 });211 it("should set the checked state", function() {212 var f = fieldset.getAt(0);213 f.setChecked(false);214 expect(f.getChecked()).toBe(false);215 expect(f.isChecked()).toBe(false);216 });217 it("should not fire any events", function() {218 var f = fieldset.getAt(0);219 attachSpies(f);220 f.setChecked(false);221 222 expect(changeSpy).not.toHaveBeenCalled();223 expect(checkSpy).not.toHaveBeenCalled();224 expect(uncheckSpy).not.toHaveBeenCalled();225 });226 });227 describe("when checked", function() {228 beforeEach(function() {229 makeGroup([{230 value: 'red',231 checked: true232 }, {233 value: 'blue'234 }])235 });236 it("should set the checked state", function() {237 var f = fieldset.getAt(0);238 f.setChecked(false);239 expect(f.getChecked()).toBe(false);240 expect(f.isChecked()).toBe(false);241 });242 it("should fire change, check, not fire uncheck", function() {243 var f = fieldset.getAt(0);244 attachSpies(f);245 f.setChecked(false);246 expect(changeSpy.callCount).toBe(1);247 expect(changeSpy.mostRecentCall.args[0]).toBe(f);248 expect(changeSpy.mostRecentCall.args[1]).toBe(false);249 expect(changeSpy.mostRecentCall.args[2]).toBe(true);250 expect(uncheckSpy.callCount).toBe(1);251 expect(uncheckSpy.mostRecentCall.args[0]).toBe(f);252 expect(checkSpy).not.toHaveBeenCalled();253 });254 });255 });256 });257 describe("check", function() {258 describe("when not checked", function() {259 beforeEach(function() {260 makeGroup([{261 value: 'red'262 }, {263 value: 'blue'264 }])265 });266 it("should set the checked state", function() {267 var f = fieldset.getAt(0);268 f.check();269 expect(f.getChecked()).toBe(true);270 expect(f.isChecked()).toBe(true);271 });272 it("should fire change, check, not fire uncheck", function() {273 var f = fieldset.getAt(0);274 attachSpies(f);275 f.check();276 expect(changeSpy.callCount).toBe(1);277 expect(changeSpy.mostRecentCall.args[0]).toBe(f);278 expect(changeSpy.mostRecentCall.args[1]).toBe(true);279 expect(changeSpy.mostRecentCall.args[2]).toBe(false);280 expect(checkSpy.callCount).toBe(1);281 expect(checkSpy.mostRecentCall.args[0]).toBe(f);282 expect(uncheckSpy).not.toHaveBeenCalled();283 });284 });285 describe("when checked", function() {286 beforeEach(function() {287 makeGroup([{288 value: 'red',289 checked: true290 }, {291 value: 'blue'292 }])293 });294 it("should set the checked state", function() {295 var f = fieldset.getAt(0);296 f.check();297 expect(f.getChecked()).toBe(true);298 expect(f.isChecked()).toBe(true);299 });300 it("should not fire any events", function() {301 var f = fieldset.getAt(0);302 attachSpies(f);303 f.check();304 305 expect(changeSpy).not.toHaveBeenCalled();306 expect(checkSpy).not.toHaveBeenCalled();307 expect(uncheckSpy).not.toHaveBeenCalled();308 });309 });310 });311 describe("uncheck", function() {312 describe("when not checked", function() {313 beforeEach(function() {314 makeGroup([{315 value: 'red'316 }, {317 value: 'blue'318 }])319 });320 it("should set the checked state", function() {321 var f = fieldset.getAt(0);322 f.uncheck();323 expect(f.getChecked()).toBe(false);324 expect(f.isChecked()).toBe(false);325 });326 it("should not fire any events", function() {327 var f = fieldset.getAt(0);328 attachSpies(f);329 f.uncheck();330 331 expect(changeSpy).not.toHaveBeenCalled();332 expect(checkSpy).not.toHaveBeenCalled();333 expect(uncheckSpy).not.toHaveBeenCalled();334 });335 });336 describe("when checked", function() {337 beforeEach(function() {338 makeGroup([{339 value: 'red',340 checked: true341 }, {342 value: 'blue'343 }])344 });345 it("should set the checked state", function() {346 var f = fieldset.getAt(0);347 f.uncheck();348 expect(f.getChecked()).toBe(false);349 expect(f.isChecked()).toBe(false);350 });351 it("should fire change, check, not fire uncheck", function() {352 var f = fieldset.getAt(0);...
Using AI Code Generation
1var makeGroup = require('./methods').makeGroup;2var group = makeGroup();3group.add(1);4group.add(2);5group.add(3);6group.add(4);7group.add(5);8console.log(group.has(3));9group.delete(3);10console.log(group.has(3));11var makeGroup = require('./methods').makeGroup;12var group = makeGroup();13group.add(1);14group.add(2);15group.add(3);16group.add(4);17group.add(5);18console.log(group.has(3));19group.delete(3);20console.log(group.has(3));21var makeGroup = require('./methods').makeGroup;22var group = makeGroup();23group.add(1);24group.add(2);25group.add(3);26group.add(4);27group.add(5);28console.log(group.has(3));29group.delete(3);30console.log(group.has(3));31var makeGroup = require('./methods').makeGroup;32var group = makeGroup();33group.add(1);34group.add(2);35group.add(3);36group.add(4);37group.add(5);38console.log(group.has(3));39group.delete(3);40console.log(group.has(3));41var makeGroup = require('./methods').makeGroup;42var group = makeGroup();43group.add(1);44group.add(2);45group.add(3);46group.add(4);47group.add(5);48console.log(group.has(3));49group.delete(3);50console.log(group.has(3));51var makeGroup = require('./methods').makeGroup;52var group = makeGroup();53group.add(1);54group.add(2);55group.add(3);56group.add(4);57group.add(5);58console.log(group.has(3));59group.delete(3);60console.log(group.has(3));61var makeGroup = require('./methods').makeGroup;62var group = makeGroup();63group.add(1);64group.add(2);65group.add(3);66group.add(4);67group.add(5);68console.log(group.has(3));69group.delete(3);70console.log(group.has(3));
Using AI Code Generation
1var Avatar = require('./avatar');2var avatar = new Avatar();3var group = avatar.makeGroup('group1');4group.add(avatar.makeAvatar('avatar1'));5group.add(avatar.makeAvatar('avatar2'));6group.add(avatar.makeAvatar('avatar3'));7group.add(avatar.makeAvatar('avatar4'));8group.add(avatar.makeAvatar('avatar5'));9group.add(avatar.makeAvatar('avatar6'));10group.add(avatar.makeAvatar('avatar7'));11group.add(avatar.makeAvatar('avatar8'));12group.add(avatar.makeAvatar('avatar9'));13group.add(avatar.makeAvatar('avatar10'));14group.add(avatar.makeAvatar('avatar11'));15group.add(avatar.makeAvatar('avatar12'));16group.add(avatar.makeAvatar('avatar13'));17group.add(avatar.makeAvatar('avatar14'));18group.add(avatar.makeAvatar('avatar15'));19group.add(avatar.makeAvatar('avatar16'));20group.add(avatar.makeAvatar('avatar17'));21group.add(avatar.makeAvatar('avatar18'));22group.add(avatar.makeAvatar('avatar19'));23group.add(avatar.makeAvatar('avatar20'));24group.add(avatar.makeAvatar('avatar21'));25group.add(avatar.makeAvatar('avatar22'));26group.add(avatar.makeAvatar('avatar23'));27group.add(avatar.makeAvatar('avatar24'));28group.add(avatar.makeAvatar('avatar25'));29group.add(avatar.makeAvatar('avatar26'));30group.add(avatar.makeAvatar('avatar27'));31group.add(avatar.makeAvatar('avatar28'));32group.add(avatar.makeAvatar('avatar29'));33group.add(avatar.makeAvatar('avatar30'));34group.add(avatar.makeAvatar('avatar31'));35group.add(avatar.makeAvatar('avatar32'));36group.add(avatar.makeAvatar('avatar33'));37group.add(avatar.makeAvatar('avatar34'));38group.add(avatar.makeAvatar('avatar35'));39group.add(avatar.makeAvatar('avatar36'));40group.add(avatar.makeAvatar('avatar37'));41group.add(avatar.makeAvatar('avatar38'));42group.add(avatar.makeAvatar('avatar39'));43group.add(avatar.makeAvatar('avatar40'));44group.add(avatar.makeAvatar('avatar41'));45group.add(avatar.makeAvatar('avatar42'));46group.add(avatar.makeAvatar('avatar43'));47group.add(avatar.makeAvatar('avatar44'));48group.add(avatar.makeAvatar('avatar45'));49group.add(avatar.makeAvatar('avatar46'));50group.add(avatar.makeAvatar('avatar47'));51group.add(avatar
Using AI Code Generation
1var availableGroups = require('./availableGroups.js');2var myGroup = new availableGroups();3myGroup.makeGroup('my group', ['a','b','c','d','e','f','g','h','i','j']);4myGroup.addMember('my group', 'k');5myGroup.addMember('my group', 'l');6myGroup.addMember('my group', 'm');7myGroup.addMember('my group', 'n');8myGroup.addMember('my group', 'o');9myGroup.addMember('my group', 'p');10myGroup.addMember('my group', 'q');11myGroup.addMember('my group', 'r');12myGroup.addMember('my group', 's');13myGroup.addMember('my group', 't');14myGroup.addMember('my group', 'u');15myGroup.addMember('my group', 'v');16myGroup.addMember('my group', 'w');17myGroup.addMember('my group', 'x');18myGroup.addMember('my group', 'y');19myGroup.addMember('my group', 'z');20myGroup.addMember('my group', 'aa');21myGroup.addMember('my group', 'bb');22myGroup.addMember('my group', 'cc');23myGroup.addMember('my group', 'dd');24myGroup.addMember('my group', 'ee');25myGroup.addMember('my group', 'ff');26myGroup.addMember('my group', 'gg');27myGroup.addMember('my group', 'hh');28myGroup.addMember('my group', 'ii');29myGroup.addMember('my group', 'jj');30myGroup.addMember('my group', 'kk');31myGroup.addMember('my group', 'll');32myGroup.addMember('my group', 'mm');33myGroup.addMember('my group', 'nn');34myGroup.addMember('my group', 'oo');35myGroup.addMember('my group', 'pp');36myGroup.addMember('my group', 'qq');37myGroup.addMember('my group', 'rr');38myGroup.addMember('my group', 'ss');39myGroup.addMember('my group', 'tt');40myGroup.addMember('my group', 'uu');41myGroup.addMember('my group', 'vv');42myGroup.addMember('my group', 'ww');43myGroup.addMember('my group', 'xx');44myGroup.addMember('my group', '
Using AI Code Generation
1var availableGroups = require("./availableGroups.js");2var mongoose = require("mongoose");3var Group = require("./group.js");4var group = new Group();5group.name = "group1";6group.description = "this is group1";7group.owner = "owner";8group.members = ["member1", "member2"];9availableGroups.makeGroup(group, function(err) {10 if (err) {11 console.log(err);12 }13 else {14 console.log("success");15 }16});17availableGroups.getGroup("group1", function(err, group) {18 if (err) {19 console.log(err);20 }21 else {22 console.log(group);23 }24});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!