fixed tests
This commit is contained in:
		
							parent
							
								
									c60ce4a696
								
							
						
					
					
						commit
						389a4cb1c4
					
				
					 3 changed files with 33 additions and 3 deletions
				
			
		|  | @ -9,6 +9,36 @@ describe("RegexMatchViewComponent", () => { | |||
|   }); | ||||
| 
 | ||||
|   describe("filterMatches", () => { | ||||
|     var items: ({value: string})[]; | ||||
| 
 | ||||
|     beforeEach(() => { | ||||
|       items = [{value: "master"}, {value: "develop"}, {value: "production"}]; | ||||
|     }); | ||||
| 
 | ||||
|     it("returns null if given invalid regex expression", () => { | ||||
|       var regexstr: string = "\\asfd\\"; | ||||
| 
 | ||||
|       expect(component.filterMatches(regexstr, items, true)).toBe(null); | ||||
|     }); | ||||
| 
 | ||||
|     it("returns a subset of given items matching the given regex expression if given 'shouldMatch' as true", () => { | ||||
|       var regexstr: string = `^${items[0].value}$`; | ||||
|       var matches: ({value: string})[] = component.filterMatches(regexstr, items, true); | ||||
| 
 | ||||
|       expect(matches.length).toBeGreaterThan(0); | ||||
|       matches.forEach((match) => { | ||||
|         expect(items).toContain(match); | ||||
|       }); | ||||
|     }); | ||||
| 
 | ||||
|     it("returns a subset of given items not matching the given regex expression if given 'shouldMatch' as false", () => { | ||||
|       var regexstr: string = `^${items[0].value}$`; | ||||
|       var nonMatches: ({value: string})[] = component.filterMatches(regexstr, items, false); | ||||
| 
 | ||||
|       expect(nonMatches.length).toBeGreaterThan(0); | ||||
|       nonMatches.forEach((nonMatch) => { | ||||
|         expect(items).toContain(nonMatch); | ||||
|       }); | ||||
|     }); | ||||
|   }); | ||||
| }); | ||||
|  |  | |||
|  | @ -48,7 +48,7 @@ export class RegexMatchViewComponent implements ng.IComponentController { | |||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   public filterMatches(regexstr: string, items: any[], shouldMatch: boolean): any[] { | ||||
|   public filterMatches(regexstr: string, items: ({value: string})[], shouldMatch: boolean): ({value: string})[] | null { | ||||
|     regexstr = regexstr || '.+'; | ||||
| 
 | ||||
|     try { | ||||
|  | @ -58,8 +58,8 @@ export class RegexMatchViewComponent implements ng.IComponentController { | |||
|     } | ||||
| 
 | ||||
|     return items.filter(function(item) { | ||||
|       var value = item['value']; | ||||
|       var m = value.match(regex); | ||||
|       var value: string = item.value; | ||||
|       var m: RegExpMatchArray = value.match(regex); | ||||
|       var matches: boolean = !!(m && m[0].length == value.length); | ||||
|       return matches == shouldMatch; | ||||
|     }); | ||||
|  |  | |||
		Reference in a new issue