Skip to content

Commit

Permalink
Adding preferences window creation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
araujoarthur0 committed Feb 7, 2025
1 parent 995d59e commit cee5ed4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
63 changes: 61 additions & 2 deletions __tests__/__main__/windows.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Windows tests', () =>
assert.strictEqual(Windows.getWaiverWindow(), null);
assert.strictEqual(global.tray, null);
assert.strictEqual(global.contextMenu, null);
assert.strictEqual(global.prefWindow, null);
assert.strictEqual(Windows.getPreferencesWindow(), null);
});

it('Should create waiver window', (done) =>
Expand All @@ -72,7 +72,7 @@ describe('Windows tests', () =>
});
});

it('Should show waiver window it has been created', (done) =>
it('Should show waiver window when it has been created', (done) =>
{
const mainWindow = new BrowserWindow({
show: false
Expand All @@ -99,6 +99,7 @@ describe('Windows tests', () =>
Windows.openWaiverManagerWindow(mainWindow, true);
Windows.getWaiverWindow().webContents.ipc.on(IpcConstants.WindowReadyToShow, () =>
{
assert.strictEqual(showSpy.calledOnce, true);
assert.notStrictEqual(Windows.getWaiverWindow(), null);
assert.strictEqual(global.waiverDay, getDateStr(new Date()));
done();
Expand All @@ -113,12 +114,70 @@ describe('Windows tests', () =>
Windows.openWaiverManagerWindow(mainWindow, true);
Windows.getWaiverWindow().webContents.ipc.on(IpcConstants.WindowReadyToShow, () =>
{
assert.strictEqual(showSpy.calledOnce, true);
Windows.getWaiverWindow().close();
assert.strictEqual(Windows.getWaiverWindow(), null);
done();
});
});

it('Should create preferences window', (done) =>
{
const mainWindow = new BrowserWindow({
show: false
});
Windows.openPreferencesWindow(mainWindow);
assert.notStrictEqual(Windows.getPreferencesWindow(), null);
assert.strictEqual(Windows.getPreferencesWindow() instanceof BrowserWindow, true);

// Values can vary about 10px from 600, 500
const size = Windows.getPreferencesWindow().getSize();
assert.strictEqual(Math.abs(size[0] - 550) < 10, true);
assert.strictEqual(Math.abs(size[1] - 620) < 10, true);

assert.strictEqual(loadSpy.calledOnce, true);

Windows.getPreferencesWindow().webContents.ipc.on(IpcConstants.WindowReadyToShow, () =>
{
assert.strictEqual(showSpy.calledOnce, true);
done();
});
});

it('Should show preferences window when it has been created', (done) =>
{
const mainWindow = new BrowserWindow({
show: false
});
Windows.openPreferencesWindow(mainWindow);
Windows.openPreferencesWindow(mainWindow);
assert.notStrictEqual(Windows.getPreferencesWindow(), null);

// It should only load once the URL because it already exists
assert.strictEqual(loadSpy.calledOnce, true);

Windows.getPreferencesWindow().webContents.ipc.on(IpcConstants.WindowReadyToShow, () =>
{
assert.strictEqual(showSpy.calledTwice, true);
done();
});
});

it('Should reset preferences window on close', (done) =>
{
const mainWindow = new BrowserWindow({
show: false
});
Windows.openPreferencesWindow(mainWindow, true);
Windows.getPreferencesWindow().webContents.ipc.on(IpcConstants.WindowReadyToShow, () =>
{
assert.strictEqual(showSpy.calledOnce, true);
Windows.getPreferencesWindow().close();
assert.strictEqual(Windows.getPreferencesWindow(), null);
done();
});
});

it('Should get dialog coordinates', () =>
{
const coordinates = Windows.getDialogCoordinates(500, 250, {
Expand Down
5 changes: 5 additions & 0 deletions js/windows.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class Windows
return global.waiverWindow;
}

static getPreferencesWindow()
{
return global.prefWindow;
}

static resetWindowsElements()
{
global.waiverWindow = null;
Expand Down

0 comments on commit cee5ed4

Please sign in to comment.