Best JavaScript code snippet using best
model-types.ts
Source:model-types.ts
1import 'reflect-metadata';2import { Type } from '@angular/core';3export interface IBindType {4 serverPropertyTypeName: string;5 serverPropertyName: string;6 itemType?: Type<HttpBase> | null;7 booleanTrueValue?: any;8 booleanFalseValue?: any;9}10export function HttpBind(serverPropertyName: string) {11 return (target: HttpBase, propertyName: string) => {12 const resValue: IBindType = {serverPropertyTypeName: 'normal', serverPropertyName};13 Reflect.defineMetadata(propertyName, resValue, target);14 };15}16export function HttpBindObject(serverPropertyName: string, itemType: Type<HttpBase>) {17 return (target: HttpBase, propertyName: string) => {18 const resValue: IBindType = {serverPropertyTypeName: 'object', serverPropertyName, itemType};19 Reflect.defineMetadata(propertyName, resValue, target);20 };21}22export function HttpBindArray(serverPropertyName: string, itemType: Type<HttpBase>) {23 return (target: HttpBase, propertyName: string) => {24 const resValue: IBindType = {serverPropertyTypeName: 'array', serverPropertyName, itemType};25 Reflect.defineMetadata(propertyName, resValue, target);26 };27}28export function HttpBindBoolean(serverPropertyName: string, trueValue: any, falseValue: any) {29 return (target: HttpBase, propertyName: string) => {30 const resValue: IBindType = {31 serverPropertyTypeName: 'boolean',32 serverPropertyName,33 booleanTrueValue: trueValue,34 booleanFalseValue: falseValue35 };36 Reflect.defineMetadata(propertyName, resValue, target);37 };38}39export abstract class HttpBase {40 constructor(public res?: object) {41 this.prepareInit();42 }43 protected prepareInit() {44 }45 protected afterInit() {46 }47 protected preparePost() {48 }49 getPostBody(): { [key: string]: any } {50 this.preparePost();51 const postBody = {};52 const metadataKeys: Array<string> = Reflect.getMetadataKeys(this);53 metadataKeys.forEach((propertyKey: string) => {54 const property = Reflect.get(this, propertyKey);55 const metadataValue: IBindType = Reflect.getMetadata(propertyKey, this);56 if (metadataValue.serverPropertyTypeName === 'array') {57 const reqArray = property as Array<HttpBase>;58 const reqPropertyValue = new Array<{ [key: string]: string }>();59 reqArray.forEach(reqItem => reqPropertyValue.push(reqItem.getPostBody()));60 Reflect.set(postBody, metadataValue.serverPropertyName, reqPropertyValue);61 } else if (metadataValue.serverPropertyTypeName === 'object') {62 const reqObject = property as HttpBase;63 Reflect.set(postBody, metadataValue.serverPropertyName, reqObject.getPostBody());64 } else if (metadataValue.serverPropertyTypeName === 'boolean') {65 const booleanValue = property ? metadataValue.booleanTrueValue : metadataValue.booleanFalseValue;66 Reflect.set(postBody, metadataValue.serverPropertyName, booleanValue);67 } else {68 Reflect.set(postBody, metadataValue.serverPropertyName, property);69 }70 });71 return postBody;72 }73 initFromRes() {74 if (!this.res || typeof this.res !== 'object') {75 return;76 }77 const metadataKeys: Array<string> = Reflect.getMetadataKeys(this);78 metadataKeys.forEach((propertyKey: string) => {79 const property = Reflect.get(this, propertyKey);80 const metadataValue: IBindType = Reflect.getMetadata(propertyKey, this);81 if (metadataValue.serverPropertyTypeName === 'array') {82 if (Reflect.has(this.res, metadataValue.serverPropertyName)) {83 const resArray = Reflect.get(this.res, metadataValue.serverPropertyName) as Array<object>;84 const propertyArray = property as Array<HttpBase>;85 if (resArray && resArray.length > 0) {86 resArray.forEach(resItem => {87 const item = new (metadataValue.itemType as Type<HttpBase>)(resItem);88 item.initFromRes();89 propertyArray.push(item);90 });91 }92 }93 } else if (metadataValue.serverPropertyTypeName === 'object') {94 if (Reflect.has(this.res, metadataValue.serverPropertyName)) {95 const resValue = Reflect.get(this.res, metadataValue.serverPropertyName);96 const item = new (metadataValue.itemType as Type<HttpBase>)(resValue);97 item.initFromRes();98 Reflect.set(this, propertyKey, item);99 }100 } else if (metadataValue.serverPropertyTypeName === 'boolean') {101 if (Reflect.has(this.res, metadataValue.serverPropertyName)) {102 const resValue = Reflect.get(this.res, metadataValue.serverPropertyName);103 Reflect.set(this, propertyKey, resValue === metadataValue.booleanTrueValue);104 }105 } else {106 if (Reflect.has(this.res, metadataValue.serverPropertyName) &&107 Reflect.get(this.res, metadataValue.serverPropertyName)) {108 const resValue = Reflect.get(this.res, metadataValue.serverPropertyName);109 Reflect.set(this, propertyKey, resValue);110 }111 }112 });113 this.afterInit();114 }115}116export class Pagination extends HttpBase {117 @HttpBind('page_index') PageIndex = 1;118 @HttpBind('page_size') PageSize = 1;119 @HttpBind('total_count') TotalCount = 0;120 @HttpBind('page_count') PageCount = 0;121}122export abstract class ResponsePaginationBase<T extends HttpBase> {123 list: Array<T>;124 pagination: Pagination;125 abstract ListKeyName(): string;126 abstract CreateOneItem(res: object): T;127 constructor(public res?: object) {128 this.list = Array<T>();129 this.pagination = new Pagination(this.getObject('pagination'));130 this.pagination.initFromRes();131 const resList = this.getObject(this.ListKeyName());132 if (Array.isArray(resList)) {133 (resList as Array<object>).forEach(response => {134 const item = this.CreateOneItem(response);135 item.initFromRes();136 this.list.push(item);137 }138 );139 }140 }141 [Symbol.iterator]() {142 let index = 0;143 const self = this;144 return {145 next() {146 if (index < self.list.length) {147 return {value: self.list[index++], done: false};148 } else {149 return {value: undefined, done: true};150 }151 }152 };153 }154 getObject(key: string): object {155 if (this.res && Reflect.has(this.res, key)) {156 return Reflect.get(this.res, key);157 } else {158 return {};159 }160 }...
BooleanFilter.test.js
Source:BooleanFilter.test.js
1/*2 * This file is part of ag-gird-components lib.3 * (c) Basis Europe <eu@basis.com>4 *5 * For the full copyright and license information, please view the LICENSE6 * file that was distributed with this source code.7 */8/* eslint-disable no-undef */9describe('#BooleanFilter ', function() {10 let gridOptions = null11 const columnDefs = [12 {13 field: 'booleans',14 filter: 'BooleanFilter',15 filterParams: {16 booleanTrueValue: true, // default17 booleanFalseValue: false, // default18 },19 },20 {21 field: 'booleansYesNo',22 filter: 'BooleanFilter',23 filterParams: {24 booleanTrueValue: 'yes',25 booleanFalseValue: 'no',26 },27 },28 {29 field: 'booleansMixed',30 filter: 'BooleanFilter',31 filterParams: {32 booleanTrueValue: ['yes', true],33 booleanFalseValue: ['no', false],34 },35 },36 ]37 const rowData = [38 {39 booleans: true,40 booleansYesNo: 'yes',41 booleansMixed: true,42 },43 {44 booleans: true,45 booleansYesNo: 'yes',46 booleansMixed: 'yes',47 },48 {49 booleans: false,50 booleansYesNo: 'no',51 booleansMixed: 'no',52 },53 {54 booleans: false,55 booleansYesNo: 'no',56 booleansMixed: false,57 },58 ]59 afterEach(() => {60 gridOptions.api.destroy()61 })62 beforeEach(() => {63 return setupGridForTests({64 components: {65 // eslint-disable-next-line no-undef66 BooleanFilter: Basis.AgGridComponents.BooleanFilter,67 },68 columnDefs,69 rowData,70 }).then(options => {71 gridOptions = options72 })73 })74 it('Gird is initialized successfully', () => {75 expect(gridOptions.api.getDisplayedRowCount()).to.equal(4)76 expect(gridOptions.columnApi.getAllColumns()).to.have.lengthOf(3)77 })78 columnDefs.forEach(column => {79 describe(`#setModel for column "${column.field}"`, () => {80 const models = [{ value: 'true' }, { value: 'false' }]81 models.forEach(model => {82 describe(`can filter "${model.value}" values`, () => {83 beforeEach(() => {84 gridOptions.api.getFilterInstance(column.field).setModel({85 value: model.value,86 })87 gridOptions.api.onFilterChanged()88 gridOptions.api.selectAllFiltered()89 })90 afterEach(() => {91 gridOptions.api.deselectAll()92 gridOptions.api.setFilterModel(null)93 gridOptions.api.onFilterChanged()94 })95 it(`${column.field} filter is active`, () => {96 expect(97 gridOptions.api.getFilterInstance(column.field).isFilterActive()98 ).to.be.true99 })100 it('number of filtered rows is 2', () => {101 const selected = gridOptions.api.getSelectedRows()102 expect(selected, 'selected rows length is 2').to.have.lengthOf(2)103 })104 it(`${column.field} field of each filtered row is "${105 model.value === 'true'106 ? column.filterParams.booleanTrueValue107 : column.filterParams.booleanFalseValue108 }"`, () => {109 const selected = gridOptions.api.getSelectedRows()110 selected.forEach((row, i) => {111 expect(112 row[column.field],113 `rows[${i}].${column.field} is "${114 model.value === 'true'115 ? column.filterParams.booleanTrueValue116 : column.filterParams.booleanFalseValue117 }"`118 ).to.be.oneOf(119 model.value === 'true'120 ? [].concat(column.filterParams.booleanTrueValue)121 : [].concat(column.filterParams.booleanFalseValue)122 )123 })124 })125 })126 })127 })128 })...
BooleanEditor.test.js
Source:BooleanEditor.test.js
1/* eslint-disable no-undef */2/*3 * This file is part of ag-gird-components lib.4 * (c) Basis Europe <eu@basis.com>5 *6 * For the full copyright and license information, please view the LICENSE7 * file that was distributed with this source code.8 */9describe('#BooleanEditor ', function() {10 let gridOptions = null11 const columnDefs = [12 {13 field: 'booleans',14 cellEditor: 'BooleanEditor',15 cellEditorParams: {16 booleanTrueValue: true, // default17 booleanFalseValue: false, // default18 },19 },20 {21 field: 'booleansYesNo',22 cellEditor: 'BooleanEditor',23 cellEditorParams: {24 booleanTrueValue: 'yes',25 booleanFalseValue: 'no',26 },27 },28 {29 field: 'booleansMixed',30 cellEditor: 'BooleanEditor',31 cellEditorParams: {32 booleanTrueValue: ['yes', true],33 booleanFalseValue: ['no', false],34 booleanUsedTrueValue: true,35 booleanUsedFalseValue: false,36 },37 },38 ]39 const rowData = [40 {41 booleans: true,42 booleansYesNo: 'yes',43 booleansMixed: true,44 },45 {46 booleans: true,47 booleansYesNo: 'yes',48 booleansMixed: 'yes',49 },50 {51 booleans: false,52 booleansYesNo: 'no',53 booleansMixed: false,54 },55 {56 booleans: false,57 booleansYesNo: 'no',58 booleansMixed: 'no',59 },60 ]61 afterEach(() => {62 gridOptions.api.destroy()63 })64 beforeEach(() => {65 return setupGridForTests({66 components: {67 BooleanEditor: Basis.AgGridComponents.BooleanEditor,68 },69 defaultColDef: {70 editable: true,71 },72 columnDefs,73 rowData,74 }).then(options => {75 gridOptions = options76 })77 })78 it('Gird is initialized successfully', () => {79 expect(gridOptions.api.getDisplayedRowCount()).to.equal(4)80 expect(gridOptions.columnApi.getAllColumns()).to.have.lengthOf(3)81 })82 describe('#editing cells', () => {83 rowData.forEach((row, index) => {84 columnDefs.forEach(column => {85 it(`cell [${index}][${column.field}] content by reversing the value`, () => {86 const api = gridOptions.api87 const colKey = column.field88 const currentValue = row[colKey]89 const cellEditorParams = column.cellEditorParams || {}90 const booleanTrueValue = cellEditorParams.booleanTrueValue91 ? [].concat(cellEditorParams.booleanTrueValue)92 : [true]93 const booleanFalseValue = cellEditorParams.booleanFalseValue94 ? [].concat(cellEditorParams.booleanFalseValue)95 : [false]96 const booleanUsedTrueValue =97 typeof cellEditorParams.booleanUsedTrueValue !== 'undefined'98 ? cellEditorParams.booleanUsedTrueValue99 : booleanTrueValue[0]100 const booleanUsedFalseValue =101 typeof cellEditorParams.booleanUsedFalseValue !== 'undefined'102 ? cellEditorParams.booleanUsedFalseValue103 : booleanFalseValue[0]104 let reverseValue = currentValue105 if (booleanTrueValue.indexOf(currentValue) > -1) {106 reverseValue = reverseBoolean(booleanUsedTrueValue)107 } else {108 reverseValue = reverseBoolean(booleanUsedFalseValue)109 }110 api.startEditingCell({111 rowIndex: index,112 colKey: column.field,113 charPress: reverseValue,114 })115 api.stopEditing()116 const newValue = api.getValue(117 colKey,118 api.getDisplayedRowAtIndex(index)119 )120 expect(newValue).to.deep.equal(reverseValue)121 })122 })123 })124 })...
Using AI Code Generation
1var BestPracticeOne = require('./BestPracticeOne');2var BestPracticeTwo = require('./BestPracticeTwo');3var BestPracticeThree = require('./BestPracticeThree');4var BestPracticeFour = require('./BestPracticeFour');5var BestPracticeFive = require('./BestPracticeFive');6var BestPracticeSix = require('./BestPracticeSix');7var BestPracticeSeven = require('./BestPracticeSeven');8var BestPracticeEight = require('./BestPracticeEight');9var BestPracticeNine = require('./BestPracticeNine');10var BestPracticeTen = require('./BestPracticeTen');11var BestPracticeEleven = require('./BestPracticeEleven');12var BestPracticeTwelve = require('./BestPracticeTwelve');13var BestPracticeThirteen = require('./BestPracticeThirteen');14var BestPracticeFourteen = require('./BestPracticeFourteen');15var BestPracticeFifteen = require('./BestPracticeFifteen');16var BestPracticeSixteen = require('./BestPracticeSixteen');17var BestPracticeSeventeen = require('./BestPracticeSeventeen');18var BestPracticeEighteen = require('./BestPracticeEighteen');19var BestPracticeNineteen = require('./BestPracticeNineteen');20var BestPracticeTwenty = require('./BestPracticeTwenty');21var BestPracticeTwentyOne = require('./BestPracticeTwentyOne');22var BestPracticeTwentyTwo = require('./BestPracticeTwentyTwo');23var BestPracticeTwentyThree = require('./BestPracticeTwentyThree');24var BestPracticeTwentyFour = require('./BestPracticeTwentyFour');25var BestPracticeTwentyFive = require('./BestPracticeTwentyFive');26var BestPracticeTwentySix = require('./BestPracticeTwentySix');27var BestPracticeTwentySeven = require('./BestPracticeTwentySeven');28var BestPracticeTwentyEight = require('./BestPracticeTwentyEight');29var BestPracticeTwentyNine = require('./BestPracticeTwentyNine');30var BestPracticeThirty = require('./BestPracticeThirty');31var BestPracticeThirtyOne = require('./BestPracticeThirtyOne');32var BestPracticeThirtyTwo = require('./BestPracticeThirtyTwo');33var BestPracticeThirtyThree = require('./BestPracticeThirtyThree');34var BestPracticeThirtyFour = require('./BestPracticeThirtyFour');35var BestPracticeThirtyFive = require('./BestPracticeThirtyFive');36var BestPracticeThirtySix = require('./BestPracticeThirtySix');37var BestPracticeThirtySeven = require('./BestPracticeThirtySeven');38var BestPracticeThirtyEight = require('./BestPracticeThirtyEight');39var BestPracticeThirtyNine = require('./BestPracticeThirtyNine');
Using AI Code Generation
1var BestPracticeOne = require('./BestPracticeOne');2console.log(BestPracticeOne.booleanTrueValue());3var BestPracticeOne = require('./BestPracticeOne');4console.log(BestPracticeOne.booleanFalseValue());5var BestPracticeOne = require('./BestPracticeOne');6console.log(BestPracticeOne.booleanTrueValue());7var BestPracticeOne = require('./BestPracticeOne');8console.log(BestPracticeOne.booleanFalseValue());9var BestPracticeOne = require('./BestPracticeOne');10console.log(BestPracticeOne.booleanTrueValue());11var BestPracticeOne = require('./BestPracticeOne');12console.log(BestPracticeOne.booleanFalseValue());13var BestPracticeOne = require('./BestPracticeOne');14console.log(BestPracticeOne.booleanTrueValue());15var BestPracticeOne = require('./BestPracticeOne');16console.log(BestPracticeOne.booleanFalseValue());17var BestPracticeOne = require('./BestPracticeOne');18console.log(BestPracticeOne.booleanTrueValue());19var BestPracticeOne = require('./BestPracticeOne');20console.log(BestPracticeOne.booleanFalseValue());21var BestPracticeOne = require('./BestPracticeOne');22console.log(BestPracticeOne.booleanTrueValue());23var BestPracticeOne = require('./BestPracticeOne');24console.log(BestPracticeOne.booleanFalseValue());
Using AI Code Generation
1var BestLibrary = require('./BestLibrary');2console.log(BestLibrary.booleanTrueValue());3console.log(BestLibrary.booleanFalseValue());4console.log(BestLibrary.booleanRandomValue());5console.log(BestLibrary.numberRandomValue());6console.log(BestLibrary.numberRandomValueBetween(1, 100));7console.log(BestLibrary.numberRandomValueBetween(100, 1));8console.log(BestLibrary.numberRandomValueBetween(1, 1));9console.log(BestLibrary.numberRandomValueBetween(-100, -1));10console.log(BestLibrary.numberRandomValueBetween(-1, -100));11console.log(BestLibrary.numberRandomValueBetween(-100, -100));12console.log(BestLibrary.numberRandomValueBetween(-100, 100));13console.log(BestLibrary.randomArrayValue(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']));14console.log(BestLibrary.randomArrayValue(['a']));15console.log(BestLibrary.randomArrayValue([]));16console.log(BestLibrary.randomArrayValue([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));17console.log(BestLibrary.randomArrayValue([1]));18console.log(BestLibrary.randomArrayValue([1, 'a']));19console.log(BestLibrary.randomArrayValue([true, false]));
Using AI Code Generation
1var BestLibrary = require('bestlibrary');2var bl = new BestLibrary();3var result = bl.booleanTrueValue();4var BestLibrary = require('bestlibrary');5var bl = new BestLibrary();6var result = bl.booleanFalseValue();7var BestLibrary = require('bestlibrary');8var bl = new BestLibrary();9var result = bl.booleanTrueValue();10var BestLibrary = require('bestlibrary');11var bl = new BestLibrary();12var result = bl.booleanFalseValue();13var BestLibrary = require('bestlibrary');14var bl = new BestLibrary();15var result = bl.booleanTrueValue();16var BestLibrary = require('bestlibrary');17var bl = new BestLibrary();18var result = bl.booleanFalseValue();19var BestLibrary = require('bestlibrary');20var bl = new BestLibrary();21var result = bl.booleanTrueValue();22var BestLibrary = require('bestlibrary');23var bl = new BestLibrary();24var result = bl.booleanFalseValue();25var BestLibrary = require('bestlibrary');26var bl = new BestLibrary();27var result = bl.booleanTrueValue();28var BestLibrary = require('bestlibrary');29var bl = new BestLibrary();30var result = bl.booleanFalseValue();
Using AI Code Generation
1var BestLibrary = require('BestLibrary');2var bestLibrary = new BestLibrary();3var booleanTrueValue = bestLibrary.booleanTrueValue();4var BestLibrary = require('BestLibrary');5var bestLibrary = new BestLibrary();6var booleanFalseValue = bestLibrary.booleanFalseValue();7var BestLibrary = require('BestLibrary');8var bestLibrary = new BestLibrary();9var booleanTrueValue = bestLibrary.booleanTrueValue();10var BestLibrary = require('BestLibrary');11var bestLibrary = new BestLibrary();12var booleanFalseValue = bestLibrary.booleanFalseValue();13var BestLibrary = require('BestLibrary');14var bestLibrary = new BestLibrary();15var booleanTrueValue = bestLibrary.booleanTrueValue();16var BestLibrary = require('BestLibrary');17var bestLibrary = new BestLibrary();18var booleanFalseValue = bestLibrary.booleanFalseValue();19var BestLibrary = require('BestLibrary');20var bestLibrary = new BestLibrary();21var booleanTrueValue = bestLibrary.booleanTrueValue();22var BestLibrary = require('BestLibrary');23var bestLibrary = new BestLibrary();24var booleanFalseValue = bestLibrary.booleanFalseValue();25var BestLibrary = require('BestLibrary');26var bestLibrary = new BestLibrary();27var booleanTrueValue = bestLibrary.booleanTrueValue();
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!!