Skip to content

Commit

Permalink
Add support for window.show() (#151)
Browse files Browse the repository at this point in the history
* Add support for window.show()

* Mock state to ensure method is called
  • Loading branch information
curtisblackwell authored Dec 29, 2024
1 parent 0ef239b commit e14d68e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions resources/js/electron-plugin/src/server/api/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ router.post('/hide', (req, res) => {
return res.sendStatus(200);
});

router.post('/show', (req, res) => {
const { id } = req.body;

if (state.windows[id]) {
state.windows[id].show();
}

return res.sendStatus(200);
});

router.post('/always-on-top', (req, res) => {
const {id, alwaysOnTop} = req.body;

Expand Down
40 changes: 40 additions & 0 deletions resources/js/electron-plugin/tests/endpoints/window.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import startAPIServer, { APIProcess } from "../../src/server/api";
import axios from "axios";
import state from "../../src/server/state";

let apiServer: APIProcess;

jest.mock('../../src/server/state', () => ({
...jest.requireActual('../../src/server/state'),
windows: {
main: {
hide: jest.fn(),
show: jest.fn(),
},
}
}))

describe('Window test', () => {
beforeEach(async () => {
apiServer = await startAPIServer('randomSecret')

axios.defaults.baseURL = `http://localhost:${apiServer.port}/api`;
axios.defaults.headers.common['x-nativephp-secret'] = 'randomSecret';
})

afterEach(done => {
apiServer.server.close(done);
});

it('can hide a window', async () => {
const response = await axios.post('/window/hide', { id: 'main' });
expect(response.status).toBe(200);
expect(state.windows.main.hide).toHaveBeenCalled();
});

it('can show a window', async () => {
const response = await axios.post('/window/show', { id: 'main' });
expect(response.status).toBe(200);
expect(state.windows.main.show).toHaveBeenCalled();
});
});

0 comments on commit e14d68e

Please sign in to comment.