Skip to content

Commit e14d68e

Browse files
Add support for window.show() (#151)
* Add support for window.show() * Mock state to ensure method is called
1 parent 0ef239b commit e14d68e

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

resources/js/electron-plugin/src/server/api/window.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ router.post('/hide', (req, res) => {
108108
return res.sendStatus(200);
109109
});
110110

111+
router.post('/show', (req, res) => {
112+
const { id } = req.body;
113+
114+
if (state.windows[id]) {
115+
state.windows[id].show();
116+
}
117+
118+
return res.sendStatus(200);
119+
});
120+
111121
router.post('/always-on-top', (req, res) => {
112122
const {id, alwaysOnTop} = req.body;
113123

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import startAPIServer, { APIProcess } from "../../src/server/api";
2+
import axios from "axios";
3+
import state from "../../src/server/state";
4+
5+
let apiServer: APIProcess;
6+
7+
jest.mock('../../src/server/state', () => ({
8+
...jest.requireActual('../../src/server/state'),
9+
windows: {
10+
main: {
11+
hide: jest.fn(),
12+
show: jest.fn(),
13+
},
14+
}
15+
}))
16+
17+
describe('Window test', () => {
18+
beforeEach(async () => {
19+
apiServer = await startAPIServer('randomSecret')
20+
21+
axios.defaults.baseURL = `http://localhost:${apiServer.port}/api`;
22+
axios.defaults.headers.common['x-nativephp-secret'] = 'randomSecret';
23+
})
24+
25+
afterEach(done => {
26+
apiServer.server.close(done);
27+
});
28+
29+
it('can hide a window', async () => {
30+
const response = await axios.post('/window/hide', { id: 'main' });
31+
expect(response.status).toBe(200);
32+
expect(state.windows.main.hide).toHaveBeenCalled();
33+
});
34+
35+
it('can show a window', async () => {
36+
const response = await axios.post('/window/show', { id: 'main' });
37+
expect(response.status).toBe(200);
38+
expect(state.windows.main.show).toHaveBeenCalled();
39+
});
40+
});

0 commit comments

Comments
 (0)