Best JavaScript code snippet using best
IdleMessage.spec.js
Source: IdleMessage.spec.js
1import IdleMessageComponent from './IdleMessage'2import VueRouter from 'vue-router'3import { createLocalVue, shallowMount } from '@vue/test-utils'4const localVue = createLocalVue()5localVue.use(VueRouter)6describe('idle-message component', () => {7 describe('on created hook', () => {8 it('tries to show idle notification message message and being set up correctly', () => {9 sinon.stub(IdleMessageComponent.methods, 'tryShowMessageOnce')10 const wrp = shallowMount(IdleMessageComponent, { localVue })11 expect(IdleMessageComponent.methods.tryShowMessageOnce)12 .to.have.been.calledOnce13 expect(wrp.vm.isMessageShown).to.equal(false)14 IdleMessageComponent.methods.tryShowMessageOnce.restore()15 })16 })17 describe('during life-cycle', () => {18 let wrapper19 beforeEach(() => {20 const router = new VueRouter({21 mode: 'history',22 routes: [],23 })24 wrapper = shallowMount(IdleMessageComponent, { localVue, router })25 })26 describe('on tryShowMessageOnce() call', () => {27 beforeEach(() => {28 sinon.stub(wrapper.vm, 'queryHasIsIdle')29 wrapper.setData({ isMessageShown: false })30 sinon.stub(wrapper.vm, 'cleanQueryIsIdle')31 })32 it('shows the message and prevents from showing it for the second time if isIdle=true present in query', () => {33 wrapper.vm.queryHasIsIdle.returns(true)34 wrapper.vm.tryShowMessageOnce()35 expect(wrapper.vm.queryHasIsIdle).to.has.been.calledOnce36 expect(wrapper.vm.isMessageShown).to.equal(true)37 expect(wrapper.vm.cleanQueryIsIdle).to.has.been.calledOnce38 })39 it('does nothing if isIdle=true absent in query', () => {40 wrapper.vm.queryHasIsIdle.returns(false)41 wrapper.vm.tryShowMessageOnce()42 expect(wrapper.vm.queryHasIsIdle).to.has.been.called43 expect(wrapper.vm.isMessageShown).to.equal(false)44 expect(wrapper.vm.cleanQueryIsIdle).to.has.not.been.called45 })46 })47 describe('on queryHasIsIdle() call', () => {48 describe('returns true if isIdle=true present in query', () => {49 const testCases = [50 { isIdle: true },51 { redirectPath: 'isIdle=true' },52 { redirectPath: '?isIdle=true' },53 { redirectPath: '/some_path?isIdle=true' },54 {55 isIdle: true,56 redirectPath: '/some_path?isIdle=false',57 },58 { redirectPath: '/some_path?someParam=true&isIdle=true' },59 ]60 for (const testCase of testCases) {61 it(JSON.stringify(testCase), () => {62 const result = wrapper.vm.queryHasIsIdle(testCase)63 expect(result).to.equal(true)64 })65 }66 })67 describe('returns false if no isIdle=true present in query', () => {68 const testCases = [69 {},70 { isIdle: false },71 { redirectPath: {} },72 { redirectPath: '' },73 { redirectPath: '/some_path?isIdle=false' },74 {75 isIdle: false,76 redirectPath: '/some_path?isIdle=false',77 },78 '',79 '{}',80 ]81 for (const testCase of testCases) {82 it(JSON.stringify(testCase), () => {83 const result = wrapper.vm.queryHasIsIdle(testCase)84 expect(result).to.equal(false)85 })86 }87 })88 })89 describe('on cleanQueryIsIdle() call', () => {90 describe('redirects to the same route with no isIdle present in query', () => {91 const testCases = [92 {93 routerQuery: { isIdle: true },94 expectedQuery: {},95 },96 {97 routerQuery: { redirectPath: 'isIdle=true' },98 expectedQuery: { redirectPath: '' },99 },100 {101 routerQuery: { redirectPath: '?isIdle=true' },102 expectedQuery: { redirectPath: '' },103 },104 {105 routerQuery: { redirectPath: '/some_path?isIdle=true' },106 expectedQuery: { redirectPath: '/some_path' },107 },108 {109 routerQuery: {110 isIdle: false,111 redirectPath: '/some_path?isIdle=false',112 },113 expectedQuery: { redirectPath: '/some_path' },114 },115 {116 routerQuery: {117 isIdle: true,118 redirectPath: '/some_path',119 },120 expectedQuery: { redirectPath: '/some_path' },121 },122 {123 routerQuery: { redirectPath: '/some_path?someParam=true&isIdle=true' },124 expectedQuery: { redirectPath: '/some_path?someParam=true' },125 },126 ]127 for (const testCase of testCases) {128 it(JSON.stringify(testCase.routerQuery), () => {129 sinon.stub(wrapper.vm.$router, 'push')130 wrapper.vm.cleanQueryIsIdle(testCase.routerQuery)131 expect(wrapper.vm.$router.push).to.has.been.calledWithMatch({132 query: testCase.expectedQuery,133 })134 })135 }136 })137 })138 })...
vrData.js
Source: vrData.js
1var all = [[{2 img: './static/windows.png',3 title: 'dfgdfhgfh1.thoughtworks.com',4 isIdle: true,5 ip: '192.168.0.1',6 url: '/var/lib/cruise-agent',7 browser: ['Firefox', 'Safire'],8 popup: false,9 deny: false10}, {11 img: './static/windows.png',12 title: 'dsgdfhhrtty5.thoughtworks.com',13 isIdle: false,14 ip: '192.168.2.1',15 url: '/var/lib/cruise-agent',16 browser: ['Firefox', 'Safire', 'Ubuntu'],17 popup: false,18 deny: false19}, {20 img: './static/ubuntu.png',21 title: 'ghgfjgjy4.thoughtworks.com',22 isIdle: true,23 ip: '192.168.2.1',24 url: '/var/lib/cruise-agent',25 browser: ['Firefox', 'Safire', 'Ubuntu', 'chrome'],26 popup: false,27 deny: false28}, {29 img: './static/suse.png',30 title: 'hkghggggggggggggggggggggggggggggggggggggggkyu7.thoughtworks.com',31 isIdle: false,32 ip: '192.168.2.1',33 url: '/var/lib/cruise-agent',34 browser: ['Firefox', 'Safire', 'Ubuntu', 'chrome'],35 popup: false,36 deny: false37}, {38 img: './static/windows.png',39 title: 'jghjuytkym6.thoughtworks.com',40 isIdle: true,41 ip: '192.168.2.1',42 url: '/var/lib/cruise-agent',43 browser: ['Firefox', 'Safire', 'Ubuntu', 'chrome'],44 popup: false,45 deny: false46}, {47 img: './static/debin.png',48 title: 'ytjujghjh5.thoughtworks.com',49 isIdle: true,50 ip: '192.168.2.1',51 url: '/var/lib/cruise-agent',52 browser: ['Firefox', 'Safire', 'Ubuntu', 'chrome'],53 popup: false,54 deny: false55}, {56 img: './static/ubuntu.png',57 title: 'aaaaaaaaaaaa3.thoughtworks.com',58 isIdle: true,59 ip: '192.168.2.1',60 url: '/var/lib/cruise-agent',61 browser: ['Firefox', 'Safire', 'Ubuntu', 'chrome'],62 popup: false,63 deny: false64}], [{65 img: './static/windows.png',66 title: 'ggggg3.thoughtworks.com',67 isIdle: true,68 ip: '192.168.0.1',69 url: '/var/lib/cruise-agent',70 browser: ['Firefox', 'Safire'],71 popup: false,72 deny: false73}, {74 img: './static/windows.png',75 title: 'dgsdfgg5.thoughtworks.com',76 isIdle: false,77 ip: '192.168.2.1',78 url: '/var/lib/cruise-agent',79 browser: ['Firefox', 'Safire', 'Ubuntu'],80 popup: false,81 deny: false82}, {83 img: './static/cent_os.png',84 title: 'dgfsssss1.thoughtworks.com',85 isIdle: true,86 ip: '192.168.0.1',87 url: '/var/lib/cruise-agent',88 browser: ['Firefox', 'Safire'],89 popup: false,90 deny: false91}, {92 img: './static/ubuntu.png',93 title: 'dhfgdhtyyyyy6.thoughtworks.com',94 isIdle: false,95 ip: '192.168.2.1',96 url: '/var/lib/cruise-agent',97 browser: ['Firefox', 'Safire', 'Ubuntu'],98 popup: false,99 deny: false100}], [101 {102 img: './static/debin.png',103 title: 'ddddddddd4.thoughtworks.com',104 isIdle: false,105 ip: '192.168.2.1',106 url: '/var/lib/cruise-agent',107 browser: ['Firefox', 'Safire', 'Ubuntu', 'chrome'],108 popup: false,109 deny: false110 }, {111 img: './static/windows.png',112 title: 'qqqqq3.thoughtworks.com',113 isIdle: true,114 ip: '192.168.2.1',115 url: '/var/lib/cruise-agent',116 browser: ['Firefox', 'Safire', 'Ubuntu', 'chrome'],117 popup: false,118 deny: false119 }, {120 img: './static/suse.png',121 title: 'sdewrtegeg4.thoughtworks.com',122 isIdle: false,123 ip: '192.168.2.1',124 url: '/var/lib/cruise-agent',125 browser: ['Firefox', 'Safire', 'Ubuntu', 'chrome'],126 popup: false,127 deny: false128 }, {129 img: './static/cent_os.png',130 title: 'rererererererererere4.thoughtworks.com',131 isIdle: true,132 ip: '192.168.2.1',133 url: '/var/lib/cruise-agent',134 browser: ['Firefox', 'Safire', 'Ubuntu', 'chrome'],135 popup: false,136 deny: false137 }, {138 img: './static/ubuntu.png',139 title: 'trwww4.thoughtworks.com',140 isIdle: true,141 ip: '192.168.2.1',142 url: '/var/lib/cruise-agent',143 browser: ['Firefox', 'Safire', 'Ubuntu', 'chrome'],144 popup: false,145 deny: false146 }147]148];...
is_idle.ts
Source: is_idle.ts
1/* IMPORT */2import {describe} from 'ava-spec';3import delay from 'promise-resolve-timeout';4import {isIdle, onChange, store} from '../../x';5/* IS IDLE */6describe ( 'isIdle', it => {7 it.serial ( 'detects when there are pending changes', async t => {8 const proxy1 = store ({ foo: false }),9 proxy2 = store ({ foo: false });10 t.true ( isIdle () );11 t.true ( isIdle ( proxy1 ) );12 t.true ( isIdle ( proxy2 ) );13 proxy1.foo = true;14 t.false ( isIdle () );15 t.false ( isIdle ( proxy1 ) );16 t.true ( isIdle ( proxy2 ) );17 await delay ( 100 );18 t.true ( isIdle () );19 t.true ( isIdle ( proxy1 ) );20 t.true ( isIdle ( proxy2 ) );21 });22 it.serial ( 'detects when triggering changes', async t => {23 t.plan ( 6 );24 const proxy1 = store ( { foo: false } ),25 proxy2 = store ( { foo: false } );26 onChange ( proxy1, () => {27 t.false ( isIdle () );28 t.false ( isIdle ( proxy1 ) );29 t.true ( isIdle ( proxy2 ) );30 });31 proxy1.foo = true;32 await delay ( 100 );33 t.true ( isIdle () );34 t.true ( isIdle ( proxy1 ) );35 t.true ( isIdle ( proxy2 ) );36 });...
autologout.js
Source: autologout.js
1$(document).ready(function () {2 let isIdle = true;3 $(document).mousemove(function () {4 if (isIdle) {5 isIdle = false;6 }7 });8 $(document).keydown(function () {9 if (isIdle) {10 isIdle = false;11 }12 });13 $(document).mousedown(function () {14 if (isIdle) {15 isIdle = false;16 }17 });18 $(document).ontouchstart = function () {19 if (isIdle) {20 isIdle = false;21 }22 };23 setInterval(function () {24 if (!isIdle) {25 $.post("../includephp/sessionstarter.php", {sessionrenew: true})26 }27 }, 60000);28});29$(document).idle({30 onIdle: function(){31 $.post("../includephp/sessionkiller.php", {killsession: true});32 $("body").css("background", "rgba(0,0,0,0.5)");33 alert("session has been expired");34 },35 idle: 600000...
Using AI Code Generation
1var bestFit = new BestFit();2bestFit.add(1);3bestFit.add(2);4bestFit.add(3);5bestFit.add(4);6bestFit.add(5);7bestFit.add(6);8bestFit.add(7);9bestFit.add(8);10bestFit.add(9);11bestFit.add(10);12bestFit.add(11);13bestFit.add(12);14bestFit.add(13);15bestFit.add(14);16bestFit.add(15);17bestFit.add(16);18bestFit.add(17);19bestFit.add(18);20bestFit.add(19);21bestFit.add(20);22bestFit.add(21);23bestFit.add(22);24bestFit.add(23);25bestFit.add(24);26bestFit.add(25);27bestFit.add(26);28bestFit.add(27);29bestFit.add(28);30bestFit.add(29);31bestFit.add(30);32bestFit.add(31);33bestFit.add(32);34bestFit.add(33);35bestFit.add(34);36bestFit.add(35);37bestFit.add(36);38bestFit.add(37);39bestFit.add(38);40bestFit.add(39);41bestFit.add(40);42bestFit.add(41);43bestFit.add(42);44bestFit.add(43);45bestFit.add(44);46bestFit.add(45);47bestFit.add(46);48bestFit.add(47);49bestFit.add(48);50bestFit.add(49);51bestFit.add(50);52bestFit.add(51);53bestFit.add(52);54bestFit.add(53);55bestFit.add(54);56bestFit.add(55);57bestFit.add(56);58bestFit.add(57);59bestFit.add(58);60bestFit.add(59);61bestFit.add(60);62bestFit.add(61);63bestFit.add(62);64bestFit.add(63);65bestFit.add(64);66bestFit.add(65);67bestFit.add(66);68bestFit.add(67);69bestFit.add(68);70bestFit.add(69);71bestFit.add(70);72bestFit.add(71);73bestFit.add(72);74bestFit.add(73);75bestFit.add(74);76bestFit.add(75);77bestFit.add(76);78bestFit.add(77);79bestFit.add(78);80bestFit.add(79);81bestFit.add(80);82bestFit.add(81);
Using AI Code Generation
1var BestBuy = require('bestbuy')(process.env.BESTBUY_API_KEY);2var bb = new BestBuy();3bb.isIdle(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var BestBuy = require('bestbuy')(process.env.BESTBUY_API_KEY);11var bb = new BestBuy();12bb.get('products', {sku: 12345}, function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var BestBuy = require('bestbuy')(process.env.BESTBUY_API_KEY);20var bb = new BestBuy();21bb.post('orders', {sku: 12345}, function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var BestBuy = require('bestbuy')(process.env.BESTBUY_API_KEY);29var bb = new BestBuy();30bb.put('orders', {sku: 12345}, function(err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var BestBuy = require('bestbuy')(process.env.BESTBUY_API_KEY);38var bb = new BestBuy();39bb.delete('orders', {sku: 12345}, function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var BestBuy = require('bestbuy')(process.env.BESTBUY_API_KEY);47var bb = new BestBuy();48bb.getCategories(function(err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var BestBuy = require('bestbuy')(process.env.B
Using AI Code Generation
1var BestBuy = require('./BestBuy.js');2var bestBuy = new BestBuy();3bestBuy.isIdle(function(isIdle) {4 console.log('Idle: ' + isIdle);5});6var net = require('net');7var BestBuy = function() {
Using AI Code Generation
1var http = require('http');2var url = require('url');3var qs = require('querystring');4var idle = require('idle');5var port = 3000;6http.createServer(function(req, res) {7 var queryData = url.parse(req.url, true).query;8 var apikey = queryData.apikey;9 var idleTime = 1000;10 var options = {11 };12 var req = http.request(options, function(res) {13 console.log('STATUS: ' + res.statusCode);14 console.log('HEADERS: ' + JSON.stringify(res.headers));15 res.setEncoding('utf8');16 res.on('data', function(chunk) {17 console.log('BODY: ' + chunk);18 });19 });20 req.on('error', function(e) {21 console.log('problem with request: ' + e.message);22 });23 req.write('data24');25 req.end();26}).listen(port, function() {
Check out the latest blogs from LambdaTest on this topic:
LambdaTest has recently received two notable awards from the leading business software directory FinancesOnline after their experts were impressed with our test platform’s capabilities in accelerating one’s development process.
The layout of a web page is one of the most important features of a web page. It can affect the traffic inflow by a significant margin. At times, a designer may come up with numerous layout ideas and sometimes he/she may struggle the entire day to come up with one. Moreover, design becomes even more important when it comes to ensuring cross browser compatibility.
Chrome is hands down the most used browsers by developers and users alike. It is the primary reason why there is such a solid chrome community and why there is a huge list of Chrome Extensions targeted at developers.
In a startup, the major strength of the people is that they are multitaskers. Be it anything, the founders and the core team wears multiple hats and takes complete responsibilities to get the ball rolling. From designing to deploying, from development to testing, everything takes place under the hawk eyes of founders and the core members.
We are in the era of the ‘Heads down’ generation. Ever wondered how much time you spend on your smartphone? Well, let us give you an estimate. With over 2.5 billion smartphone users, an average human spends approximately 2 Hours 51 minutes on their phone every day as per ComScore’s 2017 report. The number increases by an hour if we include the tab users as well!
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!!