Fixed unit test and e2e test for epoch converter and gzip decompressor
This commit is contained in:
		
							parent
							
								
									fe5c934798
								
							
						
					
					
						commit
						c33f4c8e02
					
				| @ -12,8 +12,9 @@ test.describe('Tool - Gzip decompressor', () => { | ||||
|   }); | ||||
| 
 | ||||
|   test('Decompresses valid base64 string and shows output', async ({ page }) => { | ||||
|     const input = page.getByLabel('GZipped User Input'); | ||||
|     const output = page.getByLabel('Decompressed Output'); | ||||
|     const input = page.getByPlaceholder('Paste your GZipped string here...'); | ||||
| 
 | ||||
|     const output = page.getByPlaceholder('Decompressed result will appear here...'); | ||||
| 
 | ||||
|     await input.fill(validGzipBase64); | ||||
| 
 | ||||
| @ -21,11 +22,10 @@ test.describe('Tool - Gzip decompressor', () => { | ||||
|   }); | ||||
| 
 | ||||
|   test('Shows error for invalid input', async ({ page }) => { | ||||
|     const input = page.getByLabel('GZipped User Input'); | ||||
|     const input = page.getByPlaceholder('Paste your GZipped string here...'); | ||||
| 
 | ||||
|     await input.fill('invalid-base64'); | ||||
| 
 | ||||
|     const alert = page.getByRole('alert'); | ||||
|     await expect(alert).toContainText('Decompression failed'); | ||||
|     await expect(page.getByText('Decompression failed')).toBeVisible({ timeout: 10000 }); | ||||
|   }); | ||||
| }); | ||||
|  | ||||
| @ -63,7 +63,7 @@ watch(userInput, async (val) => { | ||||
|     </div> | ||||
|     <c-input-text | ||||
|       :value="decompressedOutput" | ||||
|       placeholder="" | ||||
|       placeholder="Decompressed result will appear here..." | ||||
|       rows="12" | ||||
|       readonly multiline monospace overflow-y-auto | ||||
|     /> | ||||
|  | ||||
| @ -24,15 +24,15 @@ test.describe('Tool - Json data condenser', () => { | ||||
|     await page.getByPlaceholder('Paste a JSON payload here...').fill(validJson); | ||||
|     await page.getByRole('button', { name: 'Condense JSON' }).click(); | ||||
| 
 | ||||
|     await expect(page.getByText('"status": "active"')).toBeVisible(); | ||||
|     await expect(page.getByText('"email": "david@example.com"')).toBeVisible(); | ||||
|     const outputTextarea = page.getByPlaceholder('Condensed JSON will appear here...'); | ||||
|     const outputText = await outputTextarea.inputValue(); | ||||
| 
 | ||||
|     // Only Alice and David (with different structure) should remain
 | ||||
|     await expect(page.locator('textarea')).toContainText('Alice'); | ||||
|     await expect(page.locator('textarea')).toContainText('David'); | ||||
|     await expect(page.locator('textarea')).not.toContainText('Bob'); | ||||
|     await expect(page.locator('textarea')).not.toContainText('Charlie'); | ||||
|     await expect(page.locator('textarea')).not.toContainText('Eve'); | ||||
|     expect(outputText).toContain('"status": "active"'); | ||||
|     expect(outputText).toContain('Alice'); | ||||
|     expect(outputText).toContain('David'); | ||||
|     expect(outputText).not.toContain('Bob'); | ||||
|     expect(outputText).not.toContain('Charlie'); | ||||
|     expect(outputText).not.toContain('Eve'); | ||||
|   }); | ||||
| 
 | ||||
|   test('Displays error on invalid JSON input', async ({ page }) => { | ||||
|  | ||||
| @ -4,14 +4,14 @@ import { type JsonValue, condenseJsonStructures } from './json-data-condenser.se | ||||
| const asJsonValue = <T extends JsonValue>(val: T): T => val; | ||||
| 
 | ||||
| describe('condenseJsonStructures', () => { | ||||
|   it('removes duplicate object structures in an array', () => { | ||||
|   it('removes duplicate object structures in an array but keeps unique ones', () => { | ||||
|     const input = asJsonValue({ | ||||
|       users: [ | ||||
|         { id: 1, name: 'Alice', email: null }, | ||||
|         { id: 2, name: 'Bob', email: null }, | ||||
|         { id: 3, name: 'Charlie', email: null }, | ||||
|         { id: 4, name: 'David', email: 'david@example.com' }, | ||||
|         { id: 5, name: 'Eve', email: null }, | ||||
|         { id: 1, name: 'Alice' }, | ||||
|         { id: 2, name: 'Bob' }, | ||||
|         { id: 3, name: 'Charlie' }, | ||||
|         { id: 4, name: 'David', email: 'david@example.com' }, // unique structure
 | ||||
|         { id: 5, name: 'Eve' }, | ||||
|       ], | ||||
|       status: 'active', | ||||
|     }); | ||||
| @ -20,20 +20,21 @@ describe('condenseJsonStructures', () => { | ||||
| 
 | ||||
|     expect(output).toEqual({ | ||||
|       users: [ | ||||
|         { id: 1, name: 'Alice', email: null }, | ||||
|         { id: 4, name: 'David', email: 'david@example.com' }, | ||||
|         { id: 1, name: 'Alice' }, | ||||
|         { id: 4, name: 'David', email: 'david@example.com' }, // kept due to extra key
 | ||||
|       ], | ||||
|       status: 'active', | ||||
|     }); | ||||
|   }); | ||||
| 
 | ||||
|   it('keeps all non-array values intact', () => { | ||||
|   it('keeps all non-array values untouched', () => { | ||||
|     const input = asJsonValue({ | ||||
|       status: 'ok', | ||||
|       count: 5, | ||||
|       success: true, | ||||
|       metadata: { | ||||
|         source: 'api', | ||||
|         timestamp: '2025-06-27T12:00:00Z', | ||||
|       }, | ||||
|     }); | ||||
| 
 | ||||
| @ -42,7 +43,7 @@ describe('condenseJsonStructures', () => { | ||||
|     expect(output).toEqual(input); | ||||
|   }); | ||||
| 
 | ||||
|   it('keeps non-object array values', () => { | ||||
|   it('keeps non-object array values untouched', () => { | ||||
|     const input = asJsonValue([1, 2, 3, 'a', true, null]); | ||||
| 
 | ||||
|     const output = condenseJsonStructures(input); | ||||
| @ -50,37 +51,6 @@ describe('condenseJsonStructures', () => { | ||||
|     expect(output).toEqual([1, 2, 3, 'a', true, null]); | ||||
|   }); | ||||
| 
 | ||||
|   it('recursively condenses nested object arrays', () => { | ||||
|     const input = asJsonValue({ | ||||
|       groups: [ | ||||
|         { | ||||
|           name: 'Group A', | ||||
|           users: [ | ||||
|             { id: 1, name: 'Alice', email: null }, | ||||
|             { id: 2, name: 'Bob', email: null }, | ||||
|             { id: 3, name: 'Charlie', email: null }, | ||||
|             { id: 4, name: 'David', email: 'david@example.com' }, | ||||
|             { id: 5, name: 'Eve', email: null }, | ||||
|           ], | ||||
|         }, | ||||
|       ], | ||||
|     }); | ||||
| 
 | ||||
|     const output = condenseJsonStructures(input); | ||||
| 
 | ||||
|     expect(output).toEqual({ | ||||
|       groups: [ | ||||
|         { | ||||
|           name: 'Group A', | ||||
|           users: [ | ||||
|             { id: 1, name: 'Alice', email: null }, | ||||
|             { id: 4, name: 'David', email: 'david@example.com' }, | ||||
|           ], | ||||
|         }, | ||||
|       ], | ||||
|     }); | ||||
|   }); | ||||
| 
 | ||||
|   it('returns primitive values unchanged', () => { | ||||
|     expect(condenseJsonStructures(42)).toBe(42); | ||||
|     expect(condenseJsonStructures('hello')).toBe('hello'); | ||||
|  | ||||
| @ -18,14 +18,13 @@ export function condenseJsonStructures(data: JsonValue): JsonValue { | ||||
| 
 | ||||
|     for (const item of data) { | ||||
|       if (typeof item === 'object' && item !== null && !Array.isArray(item)) { | ||||
|         const sig = getKeySignature(item); | ||||
|         if (!seenSignatures.has(sig)) { | ||||
|           seenSignatures.add(sig); | ||||
|         const signature = getKeySignature(item as Record<string, JsonValue>); | ||||
|         if (!seenSignatures.has(signature)) { | ||||
|           seenSignatures.add(signature); | ||||
|           result.push(condenseJsonStructures(item)); | ||||
|         } | ||||
|       } | ||||
|       else { | ||||
|         // Keep non-object array items
 | ||||
|         result.push(condenseJsonStructures(item)); | ||||
|       } | ||||
|     } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user