-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reset state removes proper file with warning * Fix path errors * Cross platfrom data path in test
- Loading branch information
Showing
17 changed files
with
301 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {Brim} from "./brim" | ||
import path from "path" | ||
|
||
const file = `tmp-boot-test/appState.json` | ||
|
||
test("boot starts zqd with defaults", async () => { | ||
const createSession = () => ({ | ||
load: () => Promise.resolve(undefined) | ||
}) | ||
// @ts-ignore | ||
const brim = await Brim.boot(file, createSession) | ||
expect(brim.zqd.root).toBe(path.normalize("/fake/path/data/spaces")) | ||
expect(brim.zqd.suricataRunner).toBe("") | ||
expect(brim.zqd.suricataUpdater).toBe("") | ||
expect(brim.zqd.zeekRunner).toBe("") | ||
}) | ||
|
||
test("gets global state from store", async () => { | ||
const createSession = () => ({ | ||
load: () => | ||
Promise.resolve({ | ||
globalState: { | ||
prefs: { | ||
zeekRunner: "testing123" | ||
} | ||
} | ||
}) | ||
}) | ||
// @ts-ignore | ||
const brim = await Brim.boot(path, createSession) | ||
expect(brim.store.getState().prefs.zeekRunner).toEqual("testing123") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {Brim} from "./brim" | ||
import {app, ipcMain} from "electron" | ||
|
||
function mockIpc(response) { | ||
jest | ||
.spyOn(ipcMain, "once") | ||
// @ts-ignore | ||
.mockImplementationOnce((_channel: string, listener) => | ||
listener(null, response) | ||
) | ||
} | ||
|
||
let brim: Brim | ||
beforeEach(async () => { | ||
// @ts-ignore | ||
app.quit.mockClear() | ||
brim = new Brim() | ||
jest.spyOn(brim.zqd, "start").mockImplementation(() => {}) | ||
jest.spyOn(brim.zqd, "close").mockImplementation(() => Promise.resolve()) | ||
jest | ||
.spyOn(brim.session, "load") | ||
// @ts-ignore | ||
.mockImplementation(() => Promise.resolve("fake-session-state")) | ||
jest.spyOn(brim.session, "save").mockImplementation(() => Promise.resolve()) | ||
await brim.start() | ||
}) | ||
|
||
test("quit and save", async () => { | ||
mockIpc(true) // the confirm ipc | ||
mockIpc(null) // the prepare ipc | ||
mockIpc({state: "test"}) // the update window state ipc | ||
|
||
await brim.quit() | ||
|
||
expect(brim.isQuitting).toBe(true) | ||
expect(brim.session.save).toHaveBeenCalledTimes(1) | ||
expect(brim.zqd.close).toHaveBeenCalledTimes(1) | ||
expect(app.quit).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
test("quit without saving", async () => { | ||
mockIpc(true) // confirm | ||
mockIpc(null) // prepare | ||
|
||
await brim.quit({saveSession: false}) | ||
|
||
expect(brim.isQuitting).toBe(true) | ||
expect(brim.session.save).not.toHaveBeenCalled() | ||
expect(brim.zqd.close).toHaveBeenCalledTimes(1) | ||
expect(app.quit).toHaveBeenCalledTimes(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {app} from "electron" | ||
import {ZQD} from "ppl/zqd/zqd" | ||
import {Brim} from "./brim" | ||
import tron from "./tron" | ||
import windowManager from "./tron/windowManager" | ||
|
||
function mockZqd() { | ||
const zqd = new ZQD("test", "srun", "supdate", "zrun") | ||
jest.spyOn(zqd, "start").mockImplementation(() => {}) | ||
jest.spyOn(zqd, "close").mockImplementation(() => Promise.resolve()) | ||
return zqd | ||
} | ||
|
||
function mockSession() { | ||
const session = tron.session() | ||
jest.spyOn(session, "delete").mockImplementation(() => Promise.resolve()) | ||
jest.spyOn(session, "save").mockImplementation(() => Promise.resolve()) | ||
return session | ||
} | ||
|
||
function mockWindows() { | ||
const windows = windowManager() | ||
jest | ||
.spyOn(windows, "confirmQuit") | ||
.mockImplementation(() => Promise.resolve(true)) | ||
jest | ||
.spyOn(windows, "prepareQuit") | ||
.mockImplementation(() => Promise.resolve([])) | ||
jest.spyOn(windows, "quit").mockImplementation(() => Promise.resolve()) | ||
return windows | ||
} | ||
|
||
test("reset state", async () => { | ||
const brim = new Brim({ | ||
zqd: mockZqd(), | ||
session: mockSession(), | ||
windows: mockWindows() | ||
}) | ||
|
||
await brim.start() | ||
await brim.resetState() | ||
|
||
expect(brim.session.delete).toHaveBeenCalled() | ||
expect(brim.session.save).not.toHaveBeenCalled() | ||
expect(app.relaunch).toHaveBeenCalled() | ||
expect(brim.isQuitting).toBe(true) | ||
}) |
43 changes: 29 additions & 14 deletions
43
src/js/electron/brim.test.ts → src/js/electron/brim-start.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,57 @@ | ||
import {ZQD} from "ppl/zqd/zqd" | ||
import {Brim} from "./brim" | ||
import {installExtensions} from "./extensions" | ||
|
||
jest.mock("./extensions", () => ({ | ||
installExtensions: jest.fn() | ||
})) | ||
import {installExtensions} from "./extensions" | ||
import {Brim} from "./brim" | ||
|
||
function mockZqd() { | ||
const zqd = new ZQD("test", "srun", "supdate", "zrun") | ||
jest.spyOn(zqd, "start").mockImplementation(() => {}) | ||
return zqd | ||
} | ||
|
||
let brim: Brim | ||
beforeEach(() => { | ||
brim = new Brim({ | ||
zqd: mockZqd() | ||
}) | ||
}) | ||
|
||
test("start is called in zqd", async () => { | ||
await brim.start() | ||
expect(brim.zqd.start).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
test("activate when zero windows open", () => { | ||
const brim = new Brim() | ||
expect(brim.windows.count()).toBe(0) | ||
brim.activate() | ||
expect(brim.windows.count()).toBe(1) | ||
}) | ||
|
||
test("actiate when one or more windows open", () => { | ||
const brim = new Brim() | ||
test("actiate when one or more windows open", async () => { | ||
brim.activate() | ||
expect(brim.windows.count()).toBe(1) | ||
brim.activate() | ||
expect(brim.windows.count()).toBe(1) | ||
}) | ||
|
||
test("start opens a window", () => { | ||
const brim = new Brim() | ||
brim.start() | ||
test("start opens a window", async () => { | ||
await brim.start() | ||
expect(brim.windows.count()).toBe(1) | ||
}) | ||
|
||
test("start installs dev extensions if is dev", () => { | ||
const brim = new Brim() | ||
test("start installs dev extensions if is dev", async () => { | ||
jest.spyOn(brim, "isDev").mockImplementation(() => true) | ||
brim.start() | ||
await brim.start() | ||
expect(installExtensions).toHaveBeenCalled() | ||
// @ts-ignore | ||
installExtensions.mockReset() | ||
}) | ||
|
||
test("start does not install dev extensions if not dev", () => { | ||
const brim = new Brim() | ||
test("start does not install dev extensions if not dev", async () => { | ||
jest.spyOn(brim, "isDev").mockImplementation(() => false) | ||
brim.start() | ||
await brim.start() | ||
expect(installExtensions).not.toHaveBeenCalled() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.