This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it('should failed to save when slide name is empty', fakeAsync(() => { | |
| let notify: NotifyServiceMock = TestBed.get(NotifyService); | |
| spyOn(notify, 'Warning'); | |
| comp.openModal(); | |
| fixture.detectChanges(); | |
| tick(); | |
| // fake favorite name input (two way binding update) | |
| let input = fixture.debugElement.query(By.css('#name')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it('should search a element', fakeAsync(() => { | |
| comp.openModal(); | |
| fixture.detectChanges(); | |
| tick(); | |
| let DOM = fixture.debugElement.nativeElement; | |
| let presentations = DOM.querySelectorAll('#presentationList li'); | |
| expect(presentations.length).toEqual(3); | |
| expect(comp.selectedItem.description).toEqual('description1'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function transform(allValues: any[], value: string) { | |
| if(!allValues) return []; | |
| if (!value || value === '') return allValues; | |
| let pattern = value.replace(/[?=]/g, '\\?').replace(/[!=]/g, '\\!').replace(/[.=]/g, '\\.'); | |
| let regX = new RegExp('(?=.*' + pattern.trim().split(' ').join(')(?=.*') + ').*', 'gi'); | |
| return allValues.filter(item => ('' + item).match(regX)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let arr = [{code: '123',label: 'A'}, {code: '234',label: 'AB'}, {id: '345',label: 'AB C'}]; | |
| let r = transform(arr, 'code', 234); | |
| console.log(r); | |
| function transform(items: any[], field: string, value ? : string): any[] { | |
| if (!items) return []; | |
| let val = (value)?(''+value).trim():value; | |
| if (val) { | |
| console.log ('ici'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Pipe, PipeTransform } from '@angular/core'; | |
| @Pipe({ | |
| name: 'fieldFilter' | |
| }) | |
| export class FieldPipe implements PipeTransform { | |
| transform(items: any[], field: string, value ? : any): any[] { | |
| if (!items) return []; | |
| if (value) { | |
| if (value === '') return items; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let arr = [1, 11, 2, 22, 23, 25, 4, 40]; | |
| let args = "2"; | |
| let pattern = args.replace(/[?=]/g, '\\?').replace(/[!=]/g, '\\!').replace(/[.=]/g, '\\.'); | |
| console.log(pattern); | |
| // global insensitive search | |
| // AND | |
| let regX = new RegExp('(?=.*' + pattern.trim().split(' ').join(')(?=.*') + ').*', 'gi'); | |
| // OR | |
| //let regX = new RegExp('(?=.*' + pattern.trim().split(' ').join(')|(?=.*') + ').*', 'gi'); | |
| console.log(regX); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const f = (arr: any) => Object.keys(arr).map((key) => arr[key]).map((item) => Object.keys(item).map((i) => item[i]).join('_')).map((item) => 'P_' + item); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let arr = {}; | |
| arr['key1'] = {id:1, value:'value1'}; | |
| arr['key2'] = {id:2, value:'value2'}; | |
| console.log(arr); | |
| let keys = Object.keys(arr); | |
| console.log(keys); | |
| let i = Object.keys(arr['key1']); | |
| console.log(i); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var arr = [{id:1, value:'value1'},{id:2, value:'value2'}]; | |
| var arr2 =[{id:3, value:'test'},{id:4, toto:'toto'}]; | |
| var a = arr.map((it)=> Object.keys(it).map((i)=> it[i]).join('_')).map((it) => 'P_'+it).join(','); | |
| console.log(a); | |
| a+= ',' + arr2.map((it)=> Object.keys(it).map((i)=> it[i]).join('_')).map((it) => 'T_'+it).join(','); | |
| console.log(a); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it('should close the dropdown list when focus is lost', () => { | |
| let fixture = TestBed.createComponent(the_component); | |
| const instance = fixture.componentInstance; | |
| fixture.detectChanges(); | |
| let elt = fixture.debugElement.query(By.css('input')); | |
| elt.triggerEventHandler('focus', null); | |
| elt.triggerEventHandler('blur', null); |