| 
									
										
										
										
											2023-09-11 18:43:10 +02:00
										 |  |  | import { expect, expectAsync, tap } from '@push.rocks/tapbundle'; | 
					
						
							| 
									
										
										
										
											2022-12-31 11:21:29 +01:00
										 |  |  | import * as smartrouter from '../ts/index.js'; | 
					
						
							| 
									
										
										
										
											2020-07-15 18:51:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | let testrouter: smartrouter.SmartRouter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tap.test('first test', async () => { | 
					
						
							|  |  |  |   testrouter = new smartrouter.SmartRouter({}); | 
					
						
							| 
									
										
										
										
											2022-01-22 13:29:23 +01:00
										 |  |  |   expect(testrouter).toBeInstanceOf(smartrouter.SmartRouter); | 
					
						
							| 
									
										
										
										
											2020-07-15 18:51:17 +00:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 21:46:21 +02:00
										 |  |  | tap.test('should handle a route change', async (toolsArg) => { | 
					
						
							|  |  |  |   const done = toolsArg.defer(); | 
					
						
							| 
									
										
										
										
											2020-07-15 18:51:17 +00:00
										 |  |  |   testrouter.on('/myawesomeroute/:any', async (routeInfoArg) => { | 
					
						
							| 
									
										
										
										
											2022-01-22 13:29:23 +01:00
										 |  |  |     expect(routeInfoArg.params.any).toEqual('hello'); | 
					
						
							| 
									
										
										
										
											2020-07-15 18:51:17 +00:00
										 |  |  |     done.resolve(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   testrouter.pushUrl('/myawesomeroute/hello'); | 
					
						
							|  |  |  |   await done.promise; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 21:46:21 +02:00
										 |  |  | tap.test('should handle a route change', async (toolsArg) => { | 
					
						
							|  |  |  |   const done = toolsArg.defer(); | 
					
						
							| 
									
										
										
										
											2020-07-15 18:51:17 +00:00
										 |  |  |   testrouter.on('/myawesomeroute2/:wow', async (routeInfoArg) => { | 
					
						
							| 
									
										
										
										
											2022-01-22 13:29:23 +01:00
										 |  |  |     expect(routeInfoArg.params.wow).toEqual('hello2'); | 
					
						
							| 
									
										
										
										
											2020-07-15 18:51:17 +00:00
										 |  |  |     done.resolve(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   testrouter.pushUrl('/myawesomeroute2/hello2'); | 
					
						
							|  |  |  |   await done.promise; | 
					
						
							| 
									
										
										
										
											2022-01-22 13:29:23 +01:00
										 |  |  |   expect(window.location.href).toEqual('http://localhost:3007/myawesomeroute2/hello2'); | 
					
						
							| 
									
										
										
										
											2020-07-15 18:51:17 +00:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 21:46:21 +02:00
										 |  |  | tap.test('should find a query param', async (toolsArg) => { | 
					
						
							|  |  |  |   const done = toolsArg.defer(); | 
					
						
							|  |  |  |   testrouter.on('/myawesomeroute2/:wow', async (routeInfoArg) => { | 
					
						
							| 
									
										
										
										
											2022-01-22 13:29:23 +01:00
										 |  |  |     expect(routeInfoArg.params.wow).toEqual('hello2'); | 
					
						
							|  |  |  |     expect(routeInfoArg.queryParams.aparam).toEqual('Yes'); | 
					
						
							| 
									
										
										
										
											2021-09-08 21:46:21 +02:00
										 |  |  |     console.log('Here is what queryParams looks like'); | 
					
						
							| 
									
										
										
										
											2021-09-08 21:49:40 +02:00
										 |  |  |     console.log(JSON.stringify(routeInfoArg.queryParams)); | 
					
						
							| 
									
										
										
										
											2021-09-08 21:46:21 +02:00
										 |  |  |     done.resolve(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   testrouter.pushUrl('/myawesomeroute2/hello2?aparam=Yes'); | 
					
						
							|  |  |  |   await done.promise; | 
					
						
							| 
									
										
										
										
											2022-01-22 13:29:23 +01:00
										 |  |  |   expect(window.location.href).toEqual('http://localhost:3007/myawesomeroute2/hello2?aparam=Yes'); | 
					
						
							| 
									
										
										
										
											2021-09-08 21:49:40 +02:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-09-08 21:46:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-15 18:51:17 +00:00
										 |  |  | tap.start(); |