Skip to content

Commit c5d99f3

Browse files
talissoncostaclaude
andcommitted
feat(test): add Jest config for JSX parsing and removeAccents tests
- Add tsconfig.jest.json with jsx: react for Jest to parse TSX files - Add jest.setup.js to provide global Utils object for tests - Update jest.config.js to use Jest-specific tsconfig and setup file - Add 12 test cases for Format.removeAccents function - Revert removeAccents to match original JS behaviour (per PR review) - Document remaining untested time-relative functions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cb7c103 commit c5d99f3

5 files changed

Lines changed: 48 additions & 4 deletions

File tree

frontend/common/utils/__tests__/format.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,39 @@ describe('Format', () => {
200200
expect(Format.userDisplayName(user)).toBe(expected)
201201
})
202202
})
203+
204+
describe('removeAccents', () => {
205+
it.each`
206+
input | expected
207+
${'Café'} | ${'Cafe'}
208+
${'naïve'} | ${'naive'}
209+
${'Müller'} | ${'Muller'}
210+
${'Agüero'} | ${'Aguero'}
211+
${'résumé'} | ${'resume'}
212+
${'Ångström'} | ${'Angstrom'}
213+
${'Señor'} | ${'Senor'}
214+
${'Łódź'} | ${'Lodz'}
215+
${'hello'} | ${'hello'}
216+
${'HELLO'} | ${'HELLO'}
217+
${null} | ${null}
218+
${undefined} | ${undefined}
219+
`('removeAccents("$input") returns "$expected"', ({ expected, input }) => {
220+
expect(Format.removeAccents(input)).toBe(expected)
221+
})
222+
})
223+
224+
/*
225+
* ============================================================================
226+
* UNTESTED FUNCTIONS
227+
* ============================================================================
228+
*
229+
* Date/time wrappers (moment, dateAndTime, monthAndYear, time):
230+
* - These are thin wrappers around moment.js - testing them would just test
231+
* the third-party library, not our code.
232+
*
233+
* Time-relative functions (age, ago, countdown, countdownMinutes):
234+
* - Use moment() to get current time, making output non-deterministic
235+
* - Would need dependency injection (Clock pattern) to test properly
236+
* ============================================================================
237+
*/
203238
})

frontend/common/utils/format.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,11 @@ const Format = {
165165
return str
166166
}
167167

168-
let result = str
169168
for (let i = 0; i < Utils.accents.length; i++) {
170-
result = result.replace(Utils.accents[i].letters, Utils.accents[i].base)
169+
str = str.replace(Utils.accents[i].letters, Utils.accents[i].base)
171170
}
172171

173-
return result
172+
return str
174173
},
175174

176175
shortenNumber(number: number): string {

frontend/jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ module.exports = {
1616
},
1717
preset: 'ts-jest',
1818
roots: ['<rootDir>'],
19+
setupFiles: ['<rootDir>/jest.setup.js'],
1920
testEnvironment: 'node',
2021
testMatch: ['**/__tests__/**/*.test.ts', '**/*.test.ts'],
2122
transform: {
2223
'^.+\\.(js|jsx)$': 'babel-jest',
2324
'^.+\\.(ts|tsx)$': [
2425
'ts-jest',
2526
{
26-
tsconfig: 'tsconfig.json',
27+
tsconfig: 'tsconfig.jest.json',
2728
},
2829
],
2930
},

frontend/jest.setup.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Set up global Utils object for tests
2+
// This makes Utils.accents and Utils.isInPast available globally as they are in the app
3+
global.Utils = require('./common/utils/base/_utils')

frontend/tsconfig.jest.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"jsx": "react"
5+
}
6+
}

0 commit comments

Comments
 (0)