fix: extra frontend tests
This commit is contained in:
		
							parent
							
								
									9af2f136eb
								
							
						
					
					
						commit
						1d84d60737
					
				
					 5 changed files with 195 additions and 38 deletions
				
			
		
							
								
								
									
										50
									
								
								frontend/tests/utils/array-utils.test.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								frontend/tests/utils/array-utils.test.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,50 @@ | |||
| import {copyArrayWith} from "../../src/utils/array-utils"; | ||||
| import { describe, it, expect } from "vitest"; | ||||
| 
 | ||||
| describe('copyArrayWith', () => { | ||||
|     it('should replace the element at the specified index', () => { | ||||
|         const original = [1, 2, 3, 4]; | ||||
|         const result = copyArrayWith(2, 99, original); | ||||
|         expect(result).toEqual([1, 2, 99, 4]); | ||||
|     }); | ||||
| 
 | ||||
|     it('should not modify the original array', () => { | ||||
|         const original = ['a', 'b', 'c']; | ||||
|         const result = copyArrayWith(1, 'x', original); | ||||
|         expect(original).toEqual(['a', 'b', 'c']); // Original remains unchanged
 | ||||
|         expect(result).toEqual(['a', 'x', 'c']); | ||||
|     }); | ||||
| 
 | ||||
|     it('should handle replacing the first element', () => { | ||||
|         const original = [true, false, true]; | ||||
|         const result = copyArrayWith(0, false, original); | ||||
|         expect(result).toEqual([false, false, true]); | ||||
|     }); | ||||
| 
 | ||||
|     it('should handle replacing the last element', () => { | ||||
|         const original = ['apple', 'banana', 'cherry']; | ||||
|         const result = copyArrayWith(2, 'date', original); | ||||
|         expect(result).toEqual(['apple', 'banana', 'date']); | ||||
|     }); | ||||
| 
 | ||||
|     it('should work with complex objects', () => { | ||||
|         const original = [{ id: 1 }, { id: 2 }, { id: 3 }]; | ||||
|         const newValue = { id: 99 }; | ||||
|         const result = copyArrayWith(1, newValue, original); | ||||
|         expect(result).toEqual([{ id: 1 }, { id: 99 }, { id: 3 }]); | ||||
|         expect(original[1].id).toBe(2); // Original remains unchanged
 | ||||
|     }); | ||||
| 
 | ||||
| 
 | ||||
|     it('should allow setting to undefined', () => { | ||||
|         const original = [1, 2, 3]; | ||||
|         const result = copyArrayWith(1, undefined, original); | ||||
|         expect(result).toEqual([1, undefined, 3]); | ||||
|     }); | ||||
| 
 | ||||
|     it('should allow setting to null', () => { | ||||
|         const original = [1, 2, 3]; | ||||
|         const result = copyArrayWith(1, null, original); | ||||
|         expect(result).toEqual([1, null, 3]); | ||||
|     }); | ||||
| }); | ||||
							
								
								
									
										87
									
								
								frontend/tests/utils/assignment-utils.test.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								frontend/tests/utils/assignment-utils.test.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,87 @@ | |||
| import {LearningPathNode} from "@dwengo-1/backend/dist/entities/content/learning-path-node.entity"; | ||||
| import {calculateProgress} from "../../src/utils/assignment-utils"; | ||||
| import {LearningPath} from "../../src/data-objects/learning-paths/learning-path"; | ||||
| import { describe, it, expect } from "vitest"; | ||||
| 
 | ||||
| describe("calculateProgress", () => { | ||||
|     it("should return 0 when no nodes are completed", () => { | ||||
|         const lp = new LearningPath({ | ||||
|             language: "en", | ||||
|             hruid: "test-path", | ||||
|             title: "Test Path", | ||||
|             description: "Test Description", | ||||
|             amountOfNodes: 10, | ||||
|             amountOfNodesLeft: 10, | ||||
|             keywords: ["test"], | ||||
|             targetAges: { min: 10, max: 15 }, | ||||
|             startNode: {} as LearningPathNode, | ||||
|         }); | ||||
| 
 | ||||
|         expect(calculateProgress(lp)).toBe(0); | ||||
|     }); | ||||
| 
 | ||||
|     it("should return 100 when all nodes are completed", () => { | ||||
|         const lp = new LearningPath({ | ||||
|             language: "en", | ||||
|             hruid: "test-path", | ||||
|             title: "Test Path", | ||||
|             description: "Test Description", | ||||
|             amountOfNodes: 10, | ||||
|             amountOfNodesLeft: 0, | ||||
|             keywords: ["test"], | ||||
|             targetAges: { min: 10, max: 15 }, | ||||
|             startNode: {} as LearningPathNode, | ||||
|         }); | ||||
| 
 | ||||
|         expect(calculateProgress(lp)).toBe(100); | ||||
|     }); | ||||
| 
 | ||||
|     it("should return 50 when half of the nodes are completed", () => { | ||||
|         const lp = new LearningPath({ | ||||
|             language: "en", | ||||
|             hruid: "test-path", | ||||
|             title: "Test Path", | ||||
|             description: "Test Description", | ||||
|             amountOfNodes: 10, | ||||
|             amountOfNodesLeft: 5, | ||||
|             keywords: ["test"], | ||||
|             targetAges: { min: 10, max: 15 }, | ||||
|             startNode: {} as LearningPathNode, | ||||
|         }); | ||||
| 
 | ||||
|         expect(calculateProgress(lp)).toBe(50); | ||||
|     }); | ||||
| 
 | ||||
|     it("should handle floating point progress correctly", () => { | ||||
|         const lp = new LearningPath({ | ||||
|             language: "en", | ||||
|             hruid: "test-path", | ||||
|             title: "Test Path", | ||||
|             description: "Test Description", | ||||
|             amountOfNodes: 3, | ||||
|             amountOfNodesLeft: 1, | ||||
|             keywords: ["test"], | ||||
|             targetAges: { min: 10, max: 15 }, | ||||
|             startNode: {} as LearningPathNode, | ||||
|         }); | ||||
| 
 | ||||
|         expect(calculateProgress(lp)).toBeCloseTo(66.666, 2); | ||||
|     }); | ||||
| 
 | ||||
| 
 | ||||
|     it("should handle edge case where amountOfNodesLeft is negative", () => { | ||||
|         const lp = new LearningPath({ | ||||
|             language: "en", | ||||
|             hruid: "test-path", | ||||
|             title: "Test Path", | ||||
|             description: "Test Description", | ||||
|             amountOfNodes: 10, | ||||
|             amountOfNodesLeft: -5, | ||||
|             keywords: ["test"], | ||||
|             targetAges: { min: 10, max: 15 }, | ||||
|             startNode: {} as LearningPathNode, | ||||
|         }); | ||||
| 
 | ||||
|         expect(calculateProgress(lp)).toBe(150); | ||||
|     }); | ||||
| }); | ||||
		Reference in a new issue
	
	 Joyelle Ndagijimana
						Joyelle Ndagijimana