Skip to content

Commit bc71acf

Browse files
authored
Merge pull request #92 from ModusCreateOrg/ADE-66
upgrade frontend packages & add prettier & format the frontend code
2 parents 6d1a22d + 2499432 commit bc71acf

File tree

107 files changed

+19873
-18534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+19873
-18534
lines changed

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"plugins": [],
3+
"printWidth": 100,
4+
"semi": true,
5+
"singleQuote": true,
6+
"tabWidth": 2,
7+
"trailingComma": "all"
8+
}

frontend/package-lock.json

Lines changed: 18107 additions & 17104 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lint": "eslint .",
2222
"lint:scss": "stylelint \"**/*.scss\"",
2323
"lint:all": "npm run lint && npm run lint:scss",
24+
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,scss,css,json,md}\"",
2425
"android": "npx cap sync android && npx cap open android",
2526
"ios": "npx cap sync ios && npx cap open ios",
2627
"prepare": "husky"
@@ -93,7 +94,7 @@
9394
"@typescript-eslint/parser": "8.19.1",
9495
"@vitejs/plugin-legacy": "6.0.0",
9596
"@vitejs/plugin-react": "4.3.4",
96-
"@vitest/coverage-v8": "2.1.9",
97+
"@vitest/coverage-v8": "^3.1.1",
9798
"cypress": "13.17.0",
9899
"eslint": "9.17.0",
99100
"eslint-plugin-react": "7.37.3",
@@ -112,6 +113,7 @@
112113
"typescript": "5.7.2",
113114
"typescript-eslint": "8.19.1",
114115
"vite": "6.0.7",
115-
"vitest": "2.1.9"
116+
"vitest": "^3.1.1",
117+
"prettier": "^3.0.0"
116118
}
117119
}

frontend/src/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const initializeStatusBar = async () => {
2727
try {
2828
if (Capacitor.isPluginAvailable('StatusBar')) {
2929
await StatusBar.setStyle({ style: Style.Light });
30-
30+
3131
if (Capacitor.getPlatform() === 'android') {
3232
// Make status bar transparent on Android
3333
await StatusBar.setBackgroundColor({ color: '#4765ff' });
@@ -44,7 +44,6 @@ const initializeStatusBar = async () => {
4444
* @returns JSX
4545
*/
4646
const App = (): JSX.Element => {
47-
4847
useEffect(() => {
4948
initializeStatusBar();
5049
}, []);

frontend/src/common/api/__tests__/reportService.test.ts

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { vi, describe, test, expect, beforeEach } from 'vitest';
2-
import { uploadReport, ReportError, fetchLatestReports, fetchAllReports, markReportAsRead } from '../reportService';
2+
import {
3+
uploadReport,
4+
ReportError,
5+
fetchLatestReports,
6+
fetchAllReports,
7+
markReportAsRead,
8+
} from '../reportService';
39
import { ReportCategory, ReportStatus } from '../../models/medicalReport';
410
import axios from 'axios';
511

@@ -12,13 +18,13 @@ vi.mock('axios', () => ({
1218
post: vi.fn(),
1319
get: vi.fn(),
1420
patch: vi.fn(),
15-
isAxiosError: vi.fn(() => true)
16-
}
21+
isAxiosError: vi.fn(() => true),
22+
},
1723
}));
1824

1925
// Mock dynamic imports to handle the service functions
2026
vi.mock('../reportService', async (importOriginal) => {
21-
const actual = await importOriginal() as typeof ReportServiceModule;
27+
const actual = (await importOriginal()) as typeof ReportServiceModule;
2228

2329
// Create a new object with the same properties as the original
2430
return {
@@ -38,9 +44,11 @@ vi.mock('../reportService', async (importOriginal) => {
3844
return response.data;
3945
} catch (error) {
4046
// Properly wrap the error in a ReportError
41-
throw new actual.ReportError(error instanceof Error
42-
? `Failed to upload report: ${error.message}`
43-
: 'Failed to upload report');
47+
throw new actual.ReportError(
48+
error instanceof Error
49+
? `Failed to upload report: ${error.message}`
50+
: 'Failed to upload report',
51+
);
4452
}
4553
},
4654

@@ -50,9 +58,11 @@ vi.mock('../reportService', async (importOriginal) => {
5058
const response = await axios.get(`/api/reports/latest?limit=${limit}`);
5159
return response.data;
5260
} catch (error) {
53-
throw new actual.ReportError(error instanceof Error
54-
? `Failed to fetch latest reports: ${error.message}`
55-
: 'Failed to fetch latest reports');
61+
throw new actual.ReportError(
62+
error instanceof Error
63+
? `Failed to fetch latest reports: ${error.message}`
64+
: 'Failed to fetch latest reports',
65+
);
5666
}
5767
},
5868

@@ -62,9 +72,11 @@ vi.mock('../reportService', async (importOriginal) => {
6272
const response = await axios.get(`/api/reports`);
6373
return response.data;
6474
} catch (error) {
65-
throw new actual.ReportError(error instanceof Error
66-
? `Failed to fetch all reports: ${error.message}`
67-
: 'Failed to fetch all reports');
75+
throw new actual.ReportError(
76+
error instanceof Error
77+
? `Failed to fetch all reports: ${error.message}`
78+
: 'Failed to fetch all reports',
79+
);
6880
}
6981
},
7082

@@ -79,10 +91,10 @@ vi.mock('@aws-amplify/auth', () => ({
7991
fetchAuthSession: vi.fn().mockResolvedValue({
8092
tokens: {
8193
idToken: {
82-
toString: () => 'mock-id-token'
83-
}
84-
}
85-
})
94+
toString: () => 'mock-id-token',
95+
},
96+
},
97+
}),
8698
}));
8799

88100
// Mock response data
@@ -100,7 +112,7 @@ const mockReports = [
100112
status: ReportStatus.UNREAD,
101113
category: ReportCategory.BRAIN,
102114
date: '2024-03-24',
103-
}
115+
},
104116
];
105117

106118
describe('reportService', () => {
@@ -122,7 +134,7 @@ describe('reportService', () => {
122134
status: ReportStatus.UNREAD,
123135
category: ReportCategory.GENERAL,
124136
date: '2024-05-10',
125-
}
137+
},
126138
});
127139
});
128140

@@ -147,7 +159,7 @@ describe('reportService', () => {
147159
status: ReportStatus.UNREAD,
148160
category: ReportCategory.HEART,
149161
date: '2024-05-10',
150-
}
162+
},
151163
});
152164

153165
const heartFile = new File(['test'], 'heart-report.pdf', { type: 'application/pdf' });
@@ -162,7 +174,7 @@ describe('reportService', () => {
162174
status: ReportStatus.UNREAD,
163175
category: ReportCategory.BRAIN,
164176
date: '2024-05-10',
165-
}
177+
},
166178
});
167179

168180
const neuroFile = new File(['test'], 'brain-scan.pdf', { type: 'application/pdf' });
@@ -179,20 +191,18 @@ describe('reportService', () => {
179191
test('should throw ReportError on upload failure', async () => {
180192
// Mock axios.post to fail
181193
(axios.post as ReturnType<typeof vi.fn>).mockRejectedValueOnce(
182-
new Error('API request failed')
194+
new Error('API request failed'),
183195
);
184196

185-
await expect(uploadReport(mockFile, progressCallback))
186-
.rejects
187-
.toThrow(ReportError);
197+
await expect(uploadReport(mockFile, progressCallback)).rejects.toThrow(ReportError);
188198
});
189199
});
190200

191201
describe('fetchLatestReports', () => {
192202
beforeEach(() => {
193203
// Setup axios mock response
194204
(axios.get as ReturnType<typeof vi.fn>).mockResolvedValue({
195-
data: mockReports.slice(0, 2)
205+
data: mockReports.slice(0, 2),
196206
});
197207
});
198208

@@ -201,16 +211,18 @@ describe('reportService', () => {
201211

202212
expect(axios.get).toHaveBeenCalled();
203213
expect(reports).toHaveLength(2);
204-
expect(reports[0]).toEqual(expect.objectContaining({
205-
id: expect.any(String),
206-
title: expect.any(String)
207-
}));
214+
expect(reports[0]).toEqual(
215+
expect.objectContaining({
216+
id: expect.any(String),
217+
title: expect.any(String),
218+
}),
219+
);
208220
});
209221

210222
test('should fetch latest reports with custom limit', async () => {
211223
const limit = 1;
212224
(axios.get as ReturnType<typeof vi.fn>).mockResolvedValue({
213-
data: mockReports.slice(0, 1)
225+
data: mockReports.slice(0, 1),
214226
});
215227

216228
const reports = await fetchLatestReports(limit);
@@ -222,16 +234,14 @@ describe('reportService', () => {
222234
test('should throw ReportError on fetch failure', async () => {
223235
(axios.get as ReturnType<typeof vi.fn>).mockRejectedValue(new Error('Network error'));
224236

225-
await expect(fetchLatestReports())
226-
.rejects
227-
.toThrow(ReportError);
237+
await expect(fetchLatestReports()).rejects.toThrow(ReportError);
228238
});
229239
});
230240

231241
describe('fetchAllReports', () => {
232242
beforeEach(() => {
233243
(axios.get as ReturnType<typeof vi.fn>).mockResolvedValue({
234-
data: mockReports
244+
data: mockReports,
235245
});
236246
});
237247

@@ -245,21 +255,19 @@ describe('reportService', () => {
245255
test('should throw ReportError on fetch failure', async () => {
246256
(axios.get as ReturnType<typeof vi.fn>).mockRejectedValue(new Error('Network error'));
247257

248-
await expect(fetchAllReports())
249-
.rejects
250-
.toThrow(ReportError);
258+
await expect(fetchAllReports()).rejects.toThrow(ReportError);
251259
});
252260
});
253261

254262
describe('markReportAsRead', () => {
255263
beforeEach(() => {
256264
const updatedReport = {
257265
...mockReports[0],
258-
status: ReportStatus.READ
266+
status: ReportStatus.READ,
259267
};
260268

261269
(axios.patch as ReturnType<typeof vi.fn>).mockResolvedValue({
262-
data: updatedReport
270+
data: updatedReport,
263271
});
264272
});
265273

@@ -273,9 +281,7 @@ describe('reportService', () => {
273281
test('should throw error when report not found', async () => {
274282
(axios.patch as ReturnType<typeof vi.fn>).mockRejectedValue(new Error('Report not found'));
275283

276-
await expect(markReportAsRead('non-existent-id'))
277-
.rejects
278-
.toThrow(ReportError);
284+
await expect(markReportAsRead('non-existent-id')).rejects.toThrow(ReportError);
279285
});
280286
});
281287
});

frontend/src/common/api/useGetCurrentUser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ export const useGetCurrentUser = () => {
1818
try {
1919
// Get current user from Cognito
2020
const cognitoUser = await CognitoAuthService.getCurrentUser();
21-
21+
2222
if (!cognitoUser) {
2323
throw new Error('User not found');
2424
}
25-
25+
2626
// Map Cognito user data to our application's user model
2727
const userData = {
2828
username: cognitoUser.username || '',
2929
attributes: {
3030
// Extract whatever attributes are available from the user object
3131
email: cognitoUser.signInDetails?.loginId || '',
32-
}
32+
},
3333
};
34-
34+
3535
return mapCognitoUserToAppUser(userData);
3636
} catch (error) {
3737
console.error('Error getting current user:', error);

frontend/src/common/api/useGetUserTokens.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ export const useGetUserTokens = () => {
1313
try {
1414
// Get tokens from Cognito
1515
const tokens = await CognitoAuthService.getUserTokens();
16-
16+
1717
if (!tokens) {
1818
throw new Error('Tokens not found.');
1919
}
20-
20+
2121
return tokens;
2222
} catch (error) {
2323
console.error('Error getting user tokens:', error);

0 commit comments

Comments
 (0)