Best JavaScript code snippet using ava
page.js
Source:page.js
1define(['data'], function (dataManager) {2 return {3 init: function (vm) {4 vm.nextPage = function () {5 var $index = vm.currentPage();6 if ($index < vm.pageList().length - 1) {7 vm.currentPage($index + 1);8 }9 };10 vm.prevPage = function () {11 var $index = vm.currentPage();12 if ($index > 0) {13 vm.currentPage($index - 1);14 }15 };16 vm.addPage = function () {17 var $index;18 var slideList;19 var slide;20 var sid = (new Date).valueOf();21 $index = vm.currentPage();22 vm.pageList.splice($index + 1, 0, {sid: sid, title: ''});23 slideList = dataManager.getSlideList();24 slide = {25 sid: sid,26 template: 'normal', layout: 'normal',27 items: {28 title: {type: 'text', value: ''},29 content: {type: 'text', value: ''}30 }31 };32 slideList.splice($index + 1, 0, slide);33 vm.currentPage($index + 1);34 dataManager.save();35 };36 vm.clonePage = function () {37 var $index;38 var page;39 var slideList;40 var slide;41 var sid = (new Date).toString();42 $index = vm.currentPage();43 page = JSON.stringify(vm.pageList.slice($index, $index + 1)[0]);44 page.sid = sid;45 page = JSON.parse(page);46 vm.pageList.splice($index + 1, 0, page);47 slideList = dataManager.getSlideList();48 slide = JSON.stringify(dataManager.getSlide($index));49 slide.sid = sid;50 slide = JSON.parse(slide);51 slideList.splice($index + 1, 0, slide);52 vm.currentPage($index + 1);53 dataManager.save();54 };55 vm.removePage = function () {56 var $index;57 var slideList;58 $index = vm.currentPage();59 if (vm.pageList().length == 1) {60 return;61 }62 if ($index == vm.pageList().length - 1) {63 vm.currentPage($index - 1);64 }65 vm.pageList.splice($index, 1);66 slideList = dataManager.getSlideList();67 slideList.splice($index, 1);68 dataManager.save();69 };70 vm.moveUpPage = function () {71 var $index;72 var slideList;73 var page;74 var slide;75 $index = vm.currentPage();76 slideList = dataManager.getSlideList();77 if ($index > 0) {78 page = vm.pageList.splice($index, 1)[0];79 vm.pageList.splice($index - 1, 0, page);80 slide = slideList.splice($index, 1)[0];81 slideList.splice($index - 1, 0, slide);82 vm.currentPage($index - 1);83 dataManager.save();84 }85 };86 vm.moveDownPage = function () {87 var $index;88 var slideList;89 var page;90 var slide;91 $index = vm.currentPage();92 slideList = dataManager.getSlideList();93 if ($index < vm.pageList().length - 1) {94 page = vm.pageList.splice($index, 1)[0];95 vm.pageList.splice($index + 1, 0, page);96 slide = slideList.splice($index, 1)[0];97 slideList.splice($index + 1, 0, slide);98 vm.currentPage($index + 1);99 dataManager.save();100 }101 };102 }103 };...
NativeManager.js
Source:NativeManager.js
1// 'use strict';2Wiz.NativeManager = function () {3 this.__defineGetter__('mozillaCtrl', this.getMozillaClient);4};5Wiz.NativeManager.SAVE_CONTENT = 'save_content';6Wiz.NativeManager.SAVE_FULLPAGE = 'save_all';7Wiz.NativeManager.SAVE_SELECTION = 'save_sel';8Wiz.NativeManager.SAVE_URL = 'save_url';9//æ¬å°è°ç¨XPCOMçclient10Wiz.NativeManager.prototype._MozillaNativeCtrl = null;11//domä¸è°ç¨çclient12Wiz.NativeManager.prototype._DOMNativeCtrl = null;13Wiz.NativeManager.prototype.startNativeClip = function (info) {14 if (info) {15 info.cmd = this.getCmdByClipType(info.clipType);16 Wiz.logger.debug('Wiz.NativeManager.startNativeClip ' + info.cmd);17 }18 this.mozillaCtrl.startClip(info);19};20Wiz.NativeManager.prototype.initDOMNativeController = function (win, embedId) {21 this._DOMNativeCtrl = new Wiz.DOMNativeController(win, embedId);22}23Wiz.NativeManager.prototype.getCmdByClipType = function (cliptype) {24 var cmd = null;25 switch (cliptype) {26 case 'fullPage' :27 cmd = Wiz.NativeManager.SAVE_FULLPAGE;28 break;29 case 'article' :30 cmd = Wiz.NativeManager.SAVE_CONTENT;31 break;32 case 'selection' :33 cmd = Wiz.NativeManager.SAVE_SELECTION ;34 break;35 case 'url' :36 cmd = Wiz.NativeManager.SAVE_URL;37 break;38 }39 return cmd;40};41Wiz.NativeManager.prototype.getMozillaClient = function () {42 if (!this._MozillaNativeCtrl) {43 this._MozillaNativeCtrl = new Wiz.MozillaNativeController();44 }45 return this._MozillaNativeCtrl;46};47Wiz.NativeManager.prototype.getDOMClient = function () {48 return this._DOMNativeCtrl;49};50Wiz.NativeManager.prototype.bInstall = function () {51 return this.mozillaCtrl.bInstall();52};53Wiz.NativeManager.prototype.hasNativeClient = function () {54 if (this._DOMNativeCtrl) {55 return this._DOMNativeCtrl.hasNativeClient();56 }57 Wiz.logger.error('Wiz.NativeManager.hasNativeClient() Error: _DOMNativeCtrl not initialize');58};59Wiz.NativeManager.prototype.getNativeCategoryStr = function () {60 var nowUserName = Wiz.prefStorage.get(Wiz.Pref.NOW_USER, 'char');61 if (this._DOMNativeCtrl) {62 return this._DOMNativeCtrl.getNativeCategory(nowUserName);63 }64 Wiz.logger.error('Wiz.NativeManager.getNativeCategoryStr() Error: _DOMNativeCtrl not initialize');...
undo-stack-spec.es6
Source:undo-stack-spec.es6
1import UndoStack from "../src/undo-stack";2describe("UndoStack", function UndoStackSpecs() {3 beforeEach(() => {4 this.undoManager = new UndoStack();5 });6 afterEach(() => {7 advanceClock(500);8 })9 describe("undo", () => {10 it("can restore history items, and returns null when none are available", () => {11 this.undoManager.save("A")12 this.undoManager.save("B")13 this.undoManager.save("C")14 expect(this.undoManager.current()).toBe("C")15 expect(this.undoManager.undo()).toBe("B")16 expect(this.undoManager.current()).toBe("B")17 expect(this.undoManager.undo()).toBe("A")18 expect(this.undoManager.current()).toBe("A")19 expect(this.undoManager.undo()).toBe(null)20 expect(this.undoManager.current()).toBe("A")21 });22 it("limits the undo stack to the MAX_HISTORY_SIZE", () => {23 this.undoManager._MAX_STACK_SIZE = 324 this.undoManager.save("A")25 this.undoManager.save("B")26 this.undoManager.save("C")27 this.undoManager.save("D")28 expect(this.undoManager.current()).toBe("D")29 expect(this.undoManager.undo()).toBe("C")30 expect(this.undoManager.undo()).toBe("B")31 expect(this.undoManager.undo()).toBe(null)32 expect(this.undoManager.current()).toBe("B")33 });34 });35 describe("undo followed by redo", () => {36 it("can restore previously undone history items", () => {37 this.undoManager.save("A")38 this.undoManager.save("B")39 this.undoManager.save("C")40 expect(this.undoManager.current()).toBe("C")41 expect(this.undoManager.undo()).toBe("B")42 expect(this.undoManager.current()).toBe("B")43 expect(this.undoManager.redo()).toBe("C")44 expect(this.undoManager.current()).toBe("C")45 });46 it("cannot be used after pushing additional items", () => {47 this.undoManager.save("A")48 this.undoManager.save("B")49 this.undoManager.save("C")50 expect(this.undoManager.current()).toBe("C")51 expect(this.undoManager.undo()).toBe("B")52 this.undoManager.save("D")53 expect(this.undoManager.redo()).toBe(null)54 expect(this.undoManager.current()).toBe("D")55 });56 });...
Using AI Code Generation
1var manager = require("node-manager");2manager.save("test", "test", "test", "test", function(err, result) {3 if (err) {4 console.log(err);5 } else {6 console.log(result);7 }8});9var manager = require("node-manager");10manager.delete("test", function(err, result) {11 if (err) {12 console.log(err);13 } else {14 console.log(result);15 }16});17var manager = require("node-manager");18manager.get("test", function(err, result) {19 if (err) {20 console.log(err);21 } else {22 console.log(result);23 }24});25var manager = require("node-manager");26manager.getAll(function(err, result) {27 if (err) {28 console.log(err);29 } else {30 console.log(result);31 }32});33var manager = require("node-manager");34manager.getAllKeys(function(err, result) {35 if (err) {36 console.log(err);37 } else {38 console.log(result);39 }40});41var manager = require("node-manager");42manager.getAllValues(function(err, result) {43 if (err) {44 console.log(err);45 } else {46 console.log(result);47 }48});49var manager = require("node-manager");50manager.update("test", "test", "test", "test", function(err, result) {51 if (err) {52 console.log(err);53 } else {54 console.log(result);55 }56});
Using AI Code Generation
1var manager = require('./manager.js');2var myManager = new manager.Manager();3myManager.save('some data', function(err, data) {4 console.log('saved data');5});6var manager = require('./manager.js');7module.exports = {8 Manager: function() {9 this.save = function(data, callback) {10 };11 }12};13var manager = require('./manager.js');14module.exports = {15 Manager: function() {16 this.save = function(data, callback) {17 };18 }19};20var manager = require('./manager.js');21module.exports = {22 Manager: function() {23 this.save = function(data, callback) {24 };25 }26};27var manager = require('./manager.js');28module.exports = {29 Manager: function() {30 this.save = function(data, callback) {31 };32 }33};34var manager = require('./manager.js');35module.exports = {36 Manager: function() {37 this.save = function(data, callback) {38 };39 }40};41var manager = require('./manager.js');42module.exports = {43 Manager: function() {44 this.save = function(data, callback) {45 };46 }47};48var manager = require('./manager.js');49module.exports = {50 Manager: function() {51 this.save = function(data, callback) {52 };53 }54};55var manager = require('./manager.js');56module.exports = {57 Manager: function() {58 this.save = function(data, callback) {59 };60 }61};
Using AI Code Generation
1const manager = require('managers');2manager.save('test.txt', 'hello world', function(err) {3 if (err) {4 console.log(err);5 }6 else {7 console.log('File saved');8 }9});10manager.save('test.txt', 'hello world', function(err) {11 if (err) {12 console.log(err);13 }14 else {15 console.log('File saved');16 }17});18manager.save('test.txt', 'hello world', function(err) {19 if (err) {20 console.log(err);21 }22 else {23 console.log('File saved');24 }25});26manager.save('test.txt', 'hello world', function(err) {27 if (err) {28 console.log(err);29 }30 else {31 console.log('File saved');32 }33});34manager.save('test.txt', 'hello world', function(err) {35 if (err) {36 console.log(err);37 }38 else {39 console.log('File saved');40 }41});42manager.save('test.txt', 'hello world', function(err) {43 if (err) {44 console.log(err);45 }46 else {47 console.log('File saved');48 }49});50manager.save('test.txt', 'hello world', function(err) {51 if (err) {52 console.log(err);53 }54 else {55 console.log('File saved');56 }57});58manager.save('test.txt', 'hello world', function(err) {59 if (err) {60 console.log(err);61 }62 else {63 console.log('File saved');64 }65});66manager.save('test.txt', 'hello world', function(err) {67 if (err) {68 console.log(err);69 }70 else {71 console.log('File saved');72 }73});
Using AI Code Generation
1manager.save()2.then((manager) => {3})4.catch((error) => {5});6manager.update()7.then((manager) => {8})9.catch((error) => {10});11manager.delete()12.then((manager) => {13})14.catch((error) => {15});16manager.fetch()17.then((manager) => {18})19.catch((error) => {20});21manager.fetchList()22.then((managers) => {23})24.catch((error) => {25});26manager.fetchCount()27.then((count) => {28})29.catch((error) => {30});31managerType.save()32.then((managerType) => {33})34.catch((error) => {35});
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!!