Skip to content

Commit

Permalink
Cleanup async reject errors in tests (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
bingenito authored May 16, 2018
1 parent 96f9998 commit ffc4f4e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ export abstract class ContainerBase extends Container {
});

if (!found) {
const group = layout.windows.find(win => win.name === window.name).group;
const matchingWindow = layout.windows.find(win => win.name === window.name);
const group = matchingWindow ? matchingWindow.group : undefined;
if (group && group.length > 0) {
groupMap.set(window, group.filter(id => id !== window.id));
}
Expand Down
8 changes: 5 additions & 3 deletions src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,11 @@ export class GroupWindowManager {
} else {
// Attach handlers to any new windows that open
ContainerWindow.addListener("window-created", (args) => {
this.container.getWindowById(args.windowId).then(window => {
this.attach(window);
});
if (this.container) {
this.container.getWindowById(args.windowId).then(window => {
this.attach(window);
});
}
});

// Attach handlers to any windows already open
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/OpenFin/openfin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,10 @@ describe("OpenFinContainer", () => {
let app;

beforeEach(() => {
desktop = jasmine.createSpyObj("desktop", ["Application"]);
desktop = jasmine.createSpyObj("desktop", ["Application", "InterApplicationBus"]);
app = jasmine.createSpyObj("application", ["getCurrent", "registerUser", "addEventListener"]);
Object.defineProperty(desktop, "Application", { value: app });
Object.defineProperty(desktop, "InterApplicationBus", { value: new MockInterApplicationBus() });
app.getCurrent.and.returnValue(app);
});

Expand Down Expand Up @@ -663,11 +664,12 @@ describe("OpenFinDisplayManager", () => {
let system;

beforeEach(() => {
desktop = jasmine.createSpyObj("desktop", ["Application", "System"]);
desktop = jasmine.createSpyObj("desktop", ["Application", "System", "InterApplicationBus"]);
app = jasmine.createSpyObj("application", ["getCurrent", "addEventListener"]);
system = jasmine.createSpyObj("system", ["getMonitorInfo"]);
Object.defineProperty(desktop, "Application", { value: app });
Object.defineProperty(desktop, "System", { value: system });
Object.defineProperty(desktop, "InterApplicationBus", { value: new MockInterApplicationBus() });
system.getMonitorInfo.and.callFake(callback => callback(
{
primaryMonitor: {
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class TestContainer extends ContainerBase {
}

getWindowByName(): Promise<ContainerWindow> {
const win = jasmine.createSpyObj("ContainerWindow", ["setBounds"]);
const win = jasmine.createSpyObj("ContainerWindow", ["setBounds", "joinGroup"]);
Object.defineProperty(win, "id", { value: "1" });
return Promise.resolve(win);
}
Expand Down Expand Up @@ -127,8 +127,11 @@ describe("container", () => {
});

describe("window management", () => {
beforeEach(() => {
spyOn(container, "createWindow").and.returnValue(jasmine.createSpyObj("window", ["joinGroup"]));
});

it("loadLayout", (done) => {
spyOn(container, "createWindow").and.callThrough();
container.loadLayout("Test").then(layout => {
expect(layout).toBeDefined();
expect(container.createWindow).toHaveBeenCalledWith("url", { name: "1" });
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/window.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class MockWindow extends ContainerWindow {
protected attachListener(eventName: WindowEventType, listener: (event: EventArgs) => void): void {
return;
}

public minimize(): Promise<void> { return Promise.resolve(); }
public restore(): Promise<void> { return Promise.resolve(); }
}

describe ("static events", () => {
Expand Down Expand Up @@ -302,7 +305,10 @@ describe("SnapAssistWindowManager", () => {
win.addListener.and.callFake((event, fn) => callback = fn);
win.getGroup.and.returnValue(Promise.resolve([]));
win.getBounds.and.returnValue(Promise.resolve(new Rectangle(0, 0, 50, 50)));
win.setBounds.and.callFake(done);
win.setBounds.and.callFake(() => {
done();
return Promise.resolve();
});

const win2 = jasmine.createSpyObj("targetWindow", ["addListener", "getBounds"]);
Object.defineProperty(win2, "id", { value: "2" });
Expand Down

0 comments on commit ffc4f4e

Please sign in to comment.