Skip to content

Commit 0765da1

Browse files
committed
Test in progress of UI
1 parent 7bd8dea commit 0765da1

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

__tests__/app/context/DashboardContext.test.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('<DashboardContext />', () => {
2323
};
2424
// Mock component that has access to Dashboard Context
2525
const TestComponent = () => {
26-
const { applications, getApplications, addApp, deleteApp } = useContext(DashboardContext);
26+
const { applications, getApplications, addApp, deleteApp, mode, changeMode } = useContext(DashboardContext);
2727

2828
return (
2929
<>
@@ -37,6 +37,9 @@ describe('<DashboardContext />', () => {
3737
<button id="getApplications" onClick={() => getApplications()}>
3838
Test getApplications
3939
</button>
40+
<button id="changeMode" onClick={() => changeMode('light mode')}>
41+
Test changeMode
42+
</button>
4043
</>
4144
);
4245
};
@@ -74,4 +77,10 @@ describe('<DashboardContext />', () => {
7477
button.simulate('click');
7578
expect(ipcRenderer.sendSync).toHaveBeenCalledWith('getApps');
7679
});
80+
81+
it("should emit the 'changeMode' event when invoking changeMode", () => {
82+
const button = wrapper.find('#changeMode');
83+
button.simulate('click');
84+
expect(ipcRenderer.sendSync).toHaveBeenCalledWith('changeMode', 'light mode');
85+
});
7786
});

app/context/DashboardContext.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const DashboardContextProvider = React.memo(({ children }: Props) => {
3434
*/
3535
const getApplications = useCallback(() => {
3636
const result = ipcRenderer.sendSync('getApps');
37-
console.log(result);
3837
setApplications(result[0]);
3938
setMode(result[1]);
4039
}, []);

electron/routes/dashboard.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ ipcMain.on('addApp', (message: IpcMainEvent, application: any) => {
3535

3636
/**
3737
* @event getApps
38-
* @desc Retrieves the existing list of applications belonging to the user
38+
* @desc Retrieves the existing list of applications belonging to the user and current user setting for mode of preference
3939
* @return Returns the list of applications
4040
*/
4141
// Load settings.json and returns updated state back to the render process on ipc 'dashboard' request
42+
4243
ipcMain.on('getApps', message => {
4344
// Retrives file contents from settings.json for current Apps
4445
const state = JSON.parse(
@@ -51,7 +52,7 @@ ipcMain.on('getApps', message => {
5152
// Destructure list of services from state to be rendered on the dashboard
5253
const dashboardList = state.services.map((arr: string[]) => [arr[0], arr[3], arr[4]]);
5354

54-
// Sync event - return new applications list w/ Mode
55+
// Sync event - return new applications list w/ user settings: Mode
5556
message.returnValue = [dashboardList,temp["mode"]];
5657
});
5758

@@ -78,7 +79,11 @@ ipcMain.on('deleteApp', (message: IpcMainEvent, index) => {
7879
message.returnValue = state.services.map((arr: string[]) => [arr[0], arr[3], arr[4]]);
7980
});
8081

81-
//Modes
82+
/**
83+
* @event changeMode
84+
* @desc Changes user's mode/theme preference fron settings.json
85+
* @return Returns the newly update setting preference of the app to the renderer end
86+
*/
8287
// Loads existing setting JSON and update settings to include updated mode version
8388
ipcMain.on('changeMode', (message: IpcMainEvent, currMode: string) => {
8489
// Retrives file contents from settings.json

0 commit comments

Comments
 (0)