| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | import { ref } from "vue"; | 
					
						
							| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  | import { describe, expect, test } from "vitest"; | 
					
						
							|  |  |  | import { usePasswordStrength } from "./use-passwords"; | 
					
						
							| 
									
										
										
										
											2023-01-29 13:01:41 -09:00
										 |  |  | import { stubI18n } from "~/tests/utils"; | 
					
						
							| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe("test usePasswordStrength", () => { | 
					
						
							|  |  |  |   test("weak password", () => { | 
					
						
							| 
									
										
										
										
											2023-01-29 13:01:41 -09:00
										 |  |  |     const pw = ref("123456"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const result = usePasswordStrength(pw, stubI18n()); | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     const { score, strength, color } = result; | 
					
						
							| 
									
										
										
										
											2023-01-29 13:01:41 -09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  |     expect(score.value).toBeGreaterThan(0); | 
					
						
							|  |  |  |     expect(score.value).toBeLessThan(40); | 
					
						
							|  |  |  |     expect(strength.value).toBe("Weak"); | 
					
						
							|  |  |  |     expect(color.value).toBe("error"); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   test("very strong password", () => { | 
					
						
							|  |  |  |     const password = ref("My~Secret~Not~So~Secret?123"); | 
					
						
							| 
									
										
										
										
											2023-01-29 13:01:41 -09:00
										 |  |  |     const { score, strength, color } = usePasswordStrength(password, stubI18n()); | 
					
						
							| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  |     expect(score.value).toBeGreaterThan(90); | 
					
						
							|  |  |  |     expect(score.value).toBe(100); | 
					
						
							|  |  |  |     expect(strength.value).toBe("Very Strong"); | 
					
						
							|  |  |  |     expect(color.value).toBe("success"); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |