Skip to content

Commit 7443df1

Browse files
committed
fix(models-sync): unblock CI: mock tauri event module in tests, apply Prettier
Two changes required to make PR AOSSIE-Org#1371 pass the "PR Check" (Linting + Frontend Tests) workflow: - jest.setup.ts: mock '@tauri-apps/api/event' (listen/emit). The new cross-window sync listener in UserPreferencesCard calls listen() at mount; without the mock the real event module calls core.transformCallback on the mocked core and throws "core.transformCallback is not a function", crashing the Jest worker for SettingsPage / PageSanity / allPages suites. - Apply repo Prettier config to the four files touched by the PR (model_manager.json, useUserPreferences.tsx, ModelManager.tsx, UserPreferencesCard.tsx): normalize the JSON permissions array, remove stray blank-line runs and trailing whitespace, and fix the onCloseRequested useEffect indentation. No behavior change. Verified: full frontend suite 150/150 passing, prettier --check and eslint --max-warnings 0 clean on all changed files.
1 parent 4652ad5 commit 7443df1

5 files changed

Lines changed: 28 additions & 32 deletions

File tree

frontend/jest.setup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ jest.mock('@tauri-apps/api/core', () => ({
5555
invoke: jest.fn().mockResolvedValue(null),
5656
}));
5757

58+
jest.mock('@tauri-apps/api/event', () => ({
59+
listen: jest.fn().mockResolvedValue(() => {}), // Returns unlisten function
60+
emit: jest.fn().mockResolvedValue(undefined),
61+
}));
62+
5863
jest.mock('@tauri-apps/api/app', () => ({
5964
getVersion: jest.fn().mockResolvedValue('1.0.0'),
6065
getName: jest.fn().mockResolvedValue('PictoPy'),
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"identifier": "model-manager-capabilities",
33
"windows": ["model-manager"],
4-
"permissions": ["core:window:default",
5-
"core:app:allow-version",
4+
"permissions": [
5+
"core:window:default",
6+
"core:app:allow-version",
67
"core:event:default",
7-
"core:window:allow-close",
8-
"core:window:allow-destroy"]
8+
"core:window:allow-close",
9+
"core:window:allow-destroy"
10+
]
911
}

frontend/src/hooks/useUserPreferences.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,8 @@ export const useUserPreferences = () => {
9999
updateYoloModelSize,
100100
toggleGpuAcceleration,
101101

102-
103102
// For refetching preferences after external events (e.g., Model Manager window closing)
104103
refetch: preferencesQuery.refetch,
105-
106-
107104

108105
// Mutation state (for use in UI, e.g., disabling buttons)
109106
isUpdating: updatePreferencesMutation.isPending,

frontend/src/pages/ModelManager/ModelManager.tsx

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,24 @@ export const ModelManager: React.FC = () => {
6666
}
6767
}, [statusData, downloadingTiers, installedJustNow]);
6868

69-
70-
// ISSUE - 1369: Tauri windows don't share state, so Model Manager emits 'models-updated' on close to notify Settings.
69+
// ISSUE - 1369: Tauri windows don't share state, so Model Manager emits 'models-updated' on close to notify Settings.
7170
useEffect(() => {
72-
const unlistenPromise = getCurrentWindow().onCloseRequested(async (event) => {
73-
event.preventDefault();
74-
try {
75-
await emit('models-updated');
76-
} catch (err) {
77-
console.error('Failed to emit models-updated', err);
78-
}
79-
await getCurrentWindow().destroy();
80-
81-
});
82-
83-
return () => {
84-
unlistenPromise.then((unlisten) => unlisten());
85-
};
86-
}, []);
87-
88-
71+
const unlistenPromise = getCurrentWindow().onCloseRequested(
72+
async (event) => {
73+
event.preventDefault();
74+
try {
75+
await emit('models-updated');
76+
} catch (err) {
77+
console.error('Failed to emit models-updated', err);
78+
}
79+
await getCurrentWindow().destroy();
80+
},
81+
);
82+
83+
return () => {
84+
unlistenPromise.then((unlisten) => unlisten());
85+
};
86+
}, []);
8987

9088
const handleTabChange = (newTab: string) => {
9189
if (activeTab === 'Available' && newTab !== 'Available') {

frontend/src/pages/SettingsPage/components/UserPreferencesCard.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ import {
1212
} from '@/components/ui/dropdown-menu';
1313
import { Button } from '@/components/ui/button';
1414

15-
1615
import { invoke } from '@tauri-apps/api/core';
1716
import { listen } from '@tauri-apps/api/event';
1817

19-
2018
import { useUserPreferences } from '@/hooks/useUserPreferences';
2119
import SettingsCard from './SettingsCard';
2220
import { formatTierLabel } from '@/lib/utils';
@@ -108,10 +106,6 @@ const UserPreferencesCard: React.FC = () => {
108106
};
109107
}, [refetch]);
110108

111-
112-
113-
114-
115109
return (
116110
<SettingsCard
117111
icon={Cpu}

0 commit comments

Comments
 (0)