Skip to content

Commit

Permalink
Fixing intermittent test
Browse files Browse the repository at this point in the history
  • Loading branch information
araujoarthur0 committed Feb 7, 2025
1 parent cee5ed4 commit 8d63ed3
Showing 1 changed file with 64 additions and 33 deletions.
97 changes: 64 additions & 33 deletions __tests__/__main__/windows.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ describe('Windows tests', () =>
ipcMain.removeHandler(IpcConstants.GetLanguageData);
ipcMain.handle(IpcConstants.GetLanguageData, () => ({
'language': 'en',
'data': {}
'data': {
'translation': {
'$Preferences': {
'hideNonWorkingDay': ''
}
}
}
}));
ipcMain.handle(IpcConstants.GetWaiverStoreContents, () =>
{
Expand Down Expand Up @@ -77,18 +83,27 @@ describe('Windows tests', () =>
const mainWindow = new BrowserWindow({
show: false
});
Windows.openWaiverManagerWindow(mainWindow);
Windows.openWaiverManagerWindow(mainWindow);
assert.notStrictEqual(Windows.getWaiverWindow(), null);

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

Windows.getWaiverWindow().webContents.ipc.on(IpcConstants.WindowReadyToShow, () =>
let firstShow = true;
showSpy.callsFake(() =>
{
assert.strictEqual(showSpy.calledTwice, true);
done();
if (firstShow)
{
firstShow = false;
Windows.openWaiverManagerWindow(mainWindow);
}
else
{
assert.notStrictEqual(Windows.getWaiverWindow(), null);

// It should only load once the URL because it already exists
assert.strictEqual(loadSpy.calledOnce, true);
assert.strictEqual(showSpy.calledTwice, true);
showSpy.restore();
showSpy = stub(BrowserWindow.prototype, 'show');
done();
}
});
Windows.openWaiverManagerWindow(mainWindow);
});

it('Should set global waiverDay when event is sent', (done) =>
Expand Down Expand Up @@ -121,46 +136,62 @@ describe('Windows tests', () =>
});
});

it('Should create preferences window', (done) =>
it('Should create preferences window', function(done)
{
// For some reason this test takes longer in the CI for windows-latest.
// The last requestAnimationFrame() call inside preferences.js has been taking ~2s.
this.timeout(5000);

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);
showSpy.callsFake(() =>
{
assert.notStrictEqual(Windows.getPreferencesWindow(), null);
assert.strictEqual(Windows.getPreferencesWindow() instanceof BrowserWindow, true);

assert.strictEqual(loadSpy.calledOnce, 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);

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

showSpy.restore();
showSpy = stub(BrowserWindow.prototype, 'show');
done();
});

Windows.openPreferencesWindow(mainWindow);
});

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, () =>
let firstShow = true;
showSpy.callsFake(() =>
{
assert.strictEqual(showSpy.calledTwice, true);
done();
if (firstShow)
{
firstShow = false;
Windows.openPreferencesWindow(mainWindow);
}
else
{
assert.notStrictEqual(Windows.getPreferencesWindow(), null);

// It should only load once the URL because it already exists
assert.strictEqual(loadSpy.calledOnce, true);
assert.strictEqual(showSpy.calledTwice, true);
showSpy.restore();
showSpy = stub(BrowserWindow.prototype, 'show');
done();
}
});
Windows.openPreferencesWindow(mainWindow);
});

it('Should reset preferences window on close', (done) =>
Expand Down

0 comments on commit 8d63ed3

Please sign in to comment.