Best JavaScript code snippet using wpt
contract.test.ts
Source:contract.test.ts
1/*2 * Copyright 2019 Red Hat, Inc. and/or its affiliates.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16import { alert } from 'store/alert';17import { createIdMapFromList } from 'util/ImmutableCollectionOperations';18import { onGet, onPost, onDelete } from 'store/rest/RestTestUtils';19import { Contract } from 'domain/Contract';20import { mockStore } from '../mockStore';21import { AppState } from '../types';22import * as actions from './actions';23import reducer, { contractSelectors, contractOperations } from './index';24const state: Partial<AppState> = {25 contractList: {26 isLoading: false,27 contractMapById: createIdMapFromList([28 {29 tenantId: 0,30 id: 0,31 version: 0,32 name: 'Contract 1',33 maximumMinutesPerDay: null,34 maximumMinutesPerWeek: null,35 maximumMinutesPerMonth: null,36 maximumMinutesPerYear: null,37 },38 {39 tenantId: 0,40 id: 1,41 version: 0,42 name: 'Contract 2',43 maximumMinutesPerDay: null,44 maximumMinutesPerWeek: 100,45 maximumMinutesPerMonth: null,46 maximumMinutesPerYear: null,47 },48 {49 tenantId: 0,50 id: 2,51 version: 0,52 name: 'Contract 3',53 maximumMinutesPerDay: 100,54 maximumMinutesPerWeek: null,55 maximumMinutesPerMonth: null,56 maximumMinutesPerYear: 100,57 },58 ]),59 },60};61describe('Contract operations', () => {62 it('should dispatch actions and call client on refresh contract list', async () => {63 const { store, client } = mockStore(state);64 const tenantId = store.getState().tenantData.currentTenantId;65 const mockContractList: Contract[] = [{66 tenantId,67 id: 0,68 version: 0,69 name: 'Contract 1',70 maximumMinutesPerDay: null,71 maximumMinutesPerWeek: null,72 maximumMinutesPerMonth: null,73 maximumMinutesPerYear: null,74 }];75 onGet(`/tenant/${tenantId}/contract/`, mockContractList);76 await store.dispatch(contractOperations.refreshContractList());77 expect(store.getActions()).toEqual([actions.setIsContractListLoading(true),78 actions.refreshContractList(mockContractList), actions.setIsContractListLoading(false)]);79 expect(client.get).toHaveBeenCalledTimes(1);80 expect(client.get).toHaveBeenCalledWith(`/tenant/${tenantId}/contract/`);81 });82 it('should dispatch actions and call client on a successful delete contract', async () => {83 const { store, client } = mockStore(state);84 const tenantId = store.getState().tenantData.currentTenantId;85 const contractToDelete = {86 tenantId,87 id: 0,88 version: 0,89 name: 'Contract 1',90 maximumMinutesPerDay: null,91 maximumMinutesPerWeek: null,92 maximumMinutesPerMonth: null,93 maximumMinutesPerYear: null,94 };95 onDelete(`/tenant/${tenantId}/contract/${contractToDelete.id}`, true);96 await store.dispatch(contractOperations.removeContract(contractToDelete));97 expect(store.getActions()).toEqual([98 alert.showSuccessMessage('removeContract', {99 name: contractToDelete.name,100 }),101 actions.removeContract(contractToDelete)]);102 expect(client.delete).toHaveBeenCalledTimes(1);103 expect(client.delete).toHaveBeenCalledWith(`/tenant/${tenantId}/contract/${contractToDelete.id}`);104 });105 it('should call client but not dispatch actions on a failed delete contract', async () => {106 const { store, client } = mockStore(state);107 const tenantId = store.getState().tenantData.currentTenantId;108 const contractToDelete = {109 tenantId,110 id: 0,111 version: 0,112 name: 'Contract 1',113 maximumMinutesPerDay: null,114 maximumMinutesPerWeek: null,115 maximumMinutesPerMonth: null,116 maximumMinutesPerYear: null,117 };118 onDelete(`/tenant/${tenantId}/contract/${contractToDelete.id}`, false);119 await store.dispatch(contractOperations.removeContract(contractToDelete));120 expect(store.getActions()).toEqual([121 alert.showErrorMessage('removeContractError', { name: contractToDelete.name }),122 ]);123 expect(client.delete).toHaveBeenCalledTimes(1);124 expect(client.delete).toHaveBeenCalledWith(`/tenant/${tenantId}/contract/${contractToDelete.id}`);125 });126 it('should dispatch actions and call client on add contract', async () => {127 const { store, client } = mockStore(state);128 const tenantId = store.getState().tenantData.currentTenantId;129 const contractToAdd: Contract = { tenantId,130 name: 'Contract 1',131 maximumMinutesPerDay: null,132 maximumMinutesPerWeek: null,133 maximumMinutesPerMonth: null,134 maximumMinutesPerYear: null };135 const contractWithUpdatedId: Contract = { ...contractToAdd, id: 4, version: 0 };136 onPost(`/tenant/${tenantId}/contract/add`, contractToAdd, contractWithUpdatedId);137 await store.dispatch(contractOperations.addContract(contractToAdd));138 expect(store.getActions()).toEqual([139 alert.showSuccessMessage('addContract', { name: contractToAdd.name }),140 actions.addContract(contractWithUpdatedId)]);141 expect(client.post).toHaveBeenCalledTimes(1);142 expect(client.post).toHaveBeenCalledWith(`/tenant/${tenantId}/contract/add`, contractToAdd);143 });144 it('should dispatch actions and call client on update contract', async () => {145 const { store, client } = mockStore(state);146 const tenantId = store.getState().tenantData.currentTenantId;147 const contractToUpdate: Contract = { tenantId,148 name: 'Contract 1',149 id: 4,150 version: 0,151 maximumMinutesPerDay: null,152 maximumMinutesPerWeek: null,153 maximumMinutesPerMonth: null,154 maximumMinutesPerYear: null };155 const contractWithUpdatedVersion: Contract = { ...contractToUpdate, id: 4, version: 1 };156 onPost(`/tenant/${tenantId}/contract/update`, contractToUpdate, contractWithUpdatedVersion);157 await store.dispatch(contractOperations.updateContract(contractToUpdate));158 expect(store.getActions()).toEqual([159 alert.showSuccessMessage('updateContract', { id: contractToUpdate.id }),160 actions.updateContract(contractWithUpdatedVersion)]);161 expect(client.post).toHaveBeenCalledTimes(1);162 expect(client.post).toHaveBeenCalledWith(`/tenant/${tenantId}/contract/update`, contractToUpdate);163 });164});165describe('Contract reducers', () => {166 const addedContract: Contract = {167 tenantId: 0,168 id: 4,169 version: 0,170 name: 'Contract 4',171 maximumMinutesPerDay: null,172 maximumMinutesPerWeek: 1,173 maximumMinutesPerMonth: 2,174 maximumMinutesPerYear: 3,175 };176 const updatedContract: Contract = {177 tenantId: 0,178 id: 1,179 version: 0,180 name: 'Updated Contract 2',181 maximumMinutesPerDay: 1,182 maximumMinutesPerWeek: 2,183 maximumMinutesPerMonth: 3,184 maximumMinutesPerYear: 4,185 };186 const deletedContract: Contract = {187 tenantId: 0,188 id: 2,189 version: 0,190 name: 'Contract 3',191 maximumMinutesPerDay: 100,192 maximumMinutesPerWeek: null,193 maximumMinutesPerMonth: null,194 maximumMinutesPerYear: 100,195 };196 const { store } = mockStore(state);197 const storeState = store.getState();198 it('set loading', () => {199 expect(200 reducer(state.contractList, actions.setIsContractListLoading(true)),201 ).toEqual({ ...state.contractList, isLoading: true });202 });203 it('add contract', () => {204 expect(205 reducer(state.contractList, actions.addContract(addedContract)),206 ).toEqual({ ...state.contractList,207 contractMapById: storeState.contractList.contractMapById.set(addedContract.id as number, addedContract) });208 });209 it('remove contract', () => {210 expect(211 reducer(state.contractList, actions.removeContract(deletedContract)),212 ).toEqual({ ...state.contractList,213 contractMapById: storeState.contractList.contractMapById.delete(deletedContract.id as number) });214 });215 it('update contract', () => {216 expect(217 reducer(state.contractList, actions.updateContract(updatedContract)),218 ).toEqual({ ...state.contractList,219 contractMapById: storeState.contractList.contractMapById.set(updatedContract.id as number, updatedContract) });220 });221 it('refresh contract list', () => {222 expect(223 reducer(state.contractList, actions.refreshContractList([addedContract])),224 ).toEqual({ ...state.contractList,225 contractMapById: createIdMapFromList([addedContract]) });226 });227});228describe('Contract selectors', () => {229 const { store } = mockStore(state);230 const storeState = store.getState();231 it('should throw an error if contract list is loading', () => {232 expect(() => contractSelectors.getContractById({233 ...storeState,234 contractList: { ...storeState.contractList, isLoading: true },235 }, 0)).toThrow();236 });237 it('should get a contract by id', () => {238 const contract = contractSelectors.getContractById(storeState, 0);239 expect(contract).toEqual({240 tenantId: 0,241 id: 0,242 version: 0,243 name: 'Contract 1',244 maximumMinutesPerDay: null,245 maximumMinutesPerWeek: null,246 maximumMinutesPerMonth: null,247 maximumMinutesPerYear: null,248 });249 });250 it('should return an empty list if contract list is loading', () => {251 const contractList = contractSelectors.getContractList({252 ...storeState,253 contractList: { ...storeState.contractList, isLoading: true },254 });255 expect(contractList).toEqual([]);256 });257 it('should return a list of all contracts', () => {258 const contractList = contractSelectors.getContractList(storeState);259 expect(contractList).toEqual(expect.arrayContaining([260 {261 tenantId: 0,262 id: 0,263 version: 0,264 name: 'Contract 1',265 maximumMinutesPerDay: null,266 maximumMinutesPerWeek: null,267 maximumMinutesPerMonth: null,268 maximumMinutesPerYear: null,269 },270 {271 tenantId: 0,272 id: 1,273 version: 0,274 name: 'Contract 2',275 maximumMinutesPerDay: null,276 maximumMinutesPerWeek: 100,277 maximumMinutesPerMonth: null,278 maximumMinutesPerYear: null,279 },280 {281 tenantId: 0,282 id: 2,283 version: 0,284 name: 'Contract 3',285 maximumMinutesPerDay: 100,286 maximumMinutesPerWeek: null,287 maximumMinutesPerMonth: null,288 maximumMinutesPerYear: 100,289 },290 ]));291 expect(contractList.length).toEqual(3);292 });...
rangemodel.js
Source:rangemodel.js
1goog.provide('goog.ui.RangeModel'); 2goog.require('goog.events.EventTarget'); 3goog.require('goog.ui.Component.EventType'); 4goog.ui.RangeModel = function() { 5 goog.events.EventTarget.call(this); 6}; 7goog.inherits(goog.ui.RangeModel, goog.events.EventTarget); 8goog.ui.RangeModel.prototype.value_ = 0; 9goog.ui.RangeModel.prototype.minimum_ = 0; 10goog.ui.RangeModel.prototype.maximum_ = 100; 11goog.ui.RangeModel.prototype.extent_ = 0; 12goog.ui.RangeModel.prototype.step_ = 1; 13goog.ui.RangeModel.prototype.isChanging_ = false; 14goog.ui.RangeModel.prototype.mute_ = false; 15goog.ui.RangeModel.prototype.setMute = function(muteValue) { 16 this.mute_ = muteValue; 17}; 18goog.ui.RangeModel.prototype.setValue = function(value) { 19 value = this.roundToStepWithMin(value); 20 if(this.value_ != value) { 21 if(value + this.extent_ > this.maximum_) { 22 this.value_ = this.maximum_ - this.extent_; 23 } else if(value < this.minimum_) { 24 this.value_ = this.minimum_; 25 } else { 26 this.value_ = value; 27 } 28 if(! this.isChanging_ && ! this.mute_) { 29 this.dispatchEvent(goog.ui.Component.EventType.CHANGE); 30 } 31 } 32}; 33goog.ui.RangeModel.prototype.getValue = function() { 34 return this.roundToStepWithMin(this.value_); 35}; 36goog.ui.RangeModel.prototype.setExtent = function(extent) { 37 extent = this.roundToStepWithMin(extent); 38 if(this.extent_ != extent) { 39 if(extent < 0) { 40 this.extent_ = 0; 41 } else if(this.value_ + extent > this.maximum_) { 42 this.extent_ = this.maximum_ - this.value_; 43 } else { 44 this.extent_ = extent; 45 } 46 if(! this.isChanging_ && ! this.mute_) { 47 this.dispatchEvent(goog.ui.Component.EventType.CHANGE); 48 } 49 } 50}; 51goog.ui.RangeModel.prototype.getExtent = function() { 52 return this.roundToStep(this.extent_); 53}; 54goog.ui.RangeModel.prototype.setMinimum = function(minimum) { 55 if(this.minimum_ != minimum) { 56 var oldIsChanging = this.isChanging_; 57 this.isChanging_ = true; 58 this.minimum_ = minimum; 59 if(minimum + this.extent_ > this.maximum_) { 60 this.extent_ = this.maximum_ - this.minimum_; 61 } 62 if(minimum > this.value_) { 63 this.setValue(minimum); 64 } 65 if(minimum > this.maximum_) { 66 this.extent_ = 0; 67 this.setMaximum(minimum); 68 this.setValue(minimum); 69 } 70 this.isChanging_ = oldIsChanging; 71 if(! this.isChanging_ && ! this.mute_) { 72 this.dispatchEvent(goog.ui.Component.EventType.CHANGE); 73 } 74 } 75}; 76goog.ui.RangeModel.prototype.getMinimum = function() { 77 return this.roundToStepWithMin(this.minimum_); 78}; 79goog.ui.RangeModel.prototype.setMaximum = function(maximum) { 80 maximum = this.roundToStepWithMin(maximum); 81 if(this.maximum_ != maximum) { 82 var oldIsChanging = this.isChanging_; 83 this.isChanging_ = true; 84 this.maximum_ = maximum; 85 if(maximum < this.value_ + this.extent_) { 86 this.setValue(maximum - this.extent_); 87 } 88 if(maximum < this.minimum_) { 89 this.extent_ = 0; 90 this.setMinimum(maximum); 91 this.setValue(this.maximum_); 92 } 93 if(maximum < this.minimum_ + this.extent_) { 94 this.extent_ = this.maximum_ - this.minimum_; 95 } 96 this.isChanging_ = oldIsChanging; 97 if(! this.isChanging_ && ! this.mute_) { 98 this.dispatchEvent(goog.ui.Component.EventType.CHANGE); 99 } 100 } 101}; 102goog.ui.RangeModel.prototype.getMaximum = function() { 103 return this.roundToStepWithMin(this.maximum_); 104}; 105goog.ui.RangeModel.prototype.getStep = function() { 106 return this.step_; 107}; 108goog.ui.RangeModel.prototype.setStep = function(step) { 109 if(this.step_ != step) { 110 this.step_ = step; 111 var oldIsChanging = this.isChanging_; 112 this.isChanging_ = true; 113 this.setMaximum(this.getMaximum()); 114 this.setExtent(this.getExtent()); 115 this.setValue(this.getValue()); 116 this.isChanging_ = oldIsChanging; 117 if(! this.isChanging_ && ! this.mute_) { 118 this.dispatchEvent(goog.ui.Component.EventType.CHANGE); 119 } 120 } 121}; 122goog.ui.RangeModel.prototype.roundToStepWithMin = function(value) { 123 if(this.step_ == null) return value; 124 return this.minimum_ + Math.round((value - this.minimum_) / this.step_) * this.step_; 125}; 126goog.ui.RangeModel.prototype.roundToStep = function(value) { 127 if(this.step_ == null) return value; 128 return Math.round(value / this.step_) * this.step_; ...
standard.ts
Source:standard.ts
...16 throw new Error('minimum is higher than current maximum')17 }18 this._minimum = minimum;19 }20 set maximum(maximum: number) {21 if(maximum < this.minimum) {22 throw new Error('maximum is lower than current maximum')23 }24 this._maximum = maximum;25 }26 get minimum() : number {27 return this._minimum;28 }29 get maximum() : number {30 return this._maximum;31 }...
Using AI Code Generation
1var page = require('webpage').create();2page.onResourceReceived = function(response) {3 console.log('Response (#' + response.id + ', stage "' + response.stage + '"): ' + JSON.stringify(response));4};5 console.log("Status: " + status);6 if(status === "success") {7 page.render('google.png');8 }9 phantom.exit();10}
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3}, function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log('Test results: ' + JSON.stringify(data));8 }9});
Using AI Code Generation
1var wpt = require('wpt');2var max = wpt.max(2,3);3console.log("Max value is "+max);4var wpt = require('wpt');5var min = wpt.min(2,3);6console.log("Min value is "+min);7var wpt = require('wpt');8var avg = wpt.avg(2,3);9console.log("Average value is "+avg);10var wpt = require('wpt');11var avg = wpt.avg(2,3);12console.log("Average value is "+avg);13var wpt = require('wpt');14var avg = wpt.avg(2,3);15console.log("Average value is "+avg);16var wpt = require('wpt');17var avg = wpt.avg(2,3);18console.log("Average value is "+avg);19var wpt = require('wpt');20var avg = wpt.avg(2,3);21console.log("Average value is "+avg);22var wpt = require('wpt');23var avg = wpt.avg(2,3);24console.log("Average value is "+avg);25var wpt = require('wpt');26var avg = wpt.avg(2,3);27console.log("Average value is "+avg);28var wpt = require('wpt');29var avg = wpt.avg(2,3);30console.log("Average value is "+avg);31var wpt = require('wpt');32var avg = wpt.avg(2,3);33console.log("Average value is "+avg);34var wpt = require('wpt');35var avg = wpt.avg(2,3);36console.log("Average value is "+avg);37var wpt = require('wpt');38var avg = wpt.avg(2
Using AI Code Generation
1var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];2var max = wpt.max(array);3console.log(max);4var object = {a: 1, b: 2, c: 3, d: 4, e: 5};5var max = wpt.max(object);6console.log(max);7var map = new Map();8map.set(1, 1);9map.set(2, 2);10map.set(3, 3);11map.set(4, 4);12map.set(5, 5);13var max = wpt.max(map);14console.log(max);15var set = new Set();16set.add(1);17set.add(2);18set.add(3);19set.add(4);20set.add(5);21var max = wpt.max(set);22console.log(max);23var string = "12345";24var max = wpt.max(string);25console.log(max);26var weakMap = new WeakMap();27weakMap.set(1, 1);28weakMap.set(2, 2);29weakMap.set(3, 3);30weakMap.set(4, 4);31weakMap.set(5, 5);32var max = wpt.max(weakMap);33console.log(max);34var weakSet = new WeakSet();35weakSet.add(1);36weakSet.add(2);37weakSet.add(3);38weakSet.add(4);39weakSet.add(5);40var max = wpt.max(weakSet);41console.log(max);42var typedArray = new Uint8Array([1, 2, 3, 4, 5]);43var max = wpt.max(typedArray);44console.log(max);45var dataView = new DataView(new ArrayBuffer(10));46dataView.setUint8(0, 1);47dataView.setUint8(1, 2);48dataView.setUint8(2, 3);49dataView.setUint8(
Using AI Code Generation
1var wpt = require('webpagetest');2 if (err) throw err;3 console.log(data);4});5var wpt = require('webpagetest');6 if (err) throw err;7 console.log(data);8});9var wpt = require('webpagetest');10 if (err) throw err;11 console.log(data);12});13var wpt = require('webpagetest');14 if (err) throw err;15 console.log(data);16});17var wpt = require('webpagetest');
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!!