Skip to content

Commit

Permalink
added some tests for server, #116 #117
Browse files Browse the repository at this point in the history
  • Loading branch information
Sprinklem committed Apr 25, 2023
1 parent b226367 commit 14a3b9d
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Server/jest-GUI.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ module.exports = {
roots: [
"<rootDir>\\tests"
],

setupFilesAfterEnv: ["./tests/JestSetupEachTest.js"],
};
5 changes: 4 additions & 1 deletion Server/tests/ExampleWindow.guitest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* A smart thing would to load the window as a constant or variable under NeptuneWindow, this way you're not constantly opening the window over and over.
*
*/
global.Neptune.setupConfigurations();

test('Example Window test', async () => {
// Brings up the about window, clicks the "close" button and confirms it is closed
Expand All @@ -14,4 +15,6 @@ test('Example Window test', async () => {

aboutWindow.getWidget("btnClose").click();
expect(aboutWindow.isVisible()).toBe(false);
});
});

global.Neptune.tearDownConfigurations();
13 changes: 12 additions & 1 deletion Server/tests/JestSetupEachTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This is called before each test

const { EventEmitter } = require('node:stream');
const { LogMan } = require('../src/Classes/LogMan.js');
const Version = require('../src/Classes/Version.js');
const fs = require("node:fs");
Expand All @@ -13,8 +14,13 @@ Neptune = {
consoleMessageCharacterLimit: (1250),
fileMessageCharacterLimit: (7500),
}),
events: {
application: new EventEmitter(),
server: new EventEmitter()
}
}
global.Neptune = Neptune;
global.Neptune = Neptune;

const testFilename = path.basename(expect.getState().testPath);
global.jestLogger = Neptune.logMan.getLogger(`Jest-${testFilename}`, false);
Expand Down Expand Up @@ -60,4 +66,9 @@ Neptune.tearDownConfigurations = function() {
} else {
console.warn("Neptune not defined");
}
}
}

Neptune.events = {
application: new EventEmitter("application"),
server: new EventEmitter("server")
}
84 changes: 84 additions & 0 deletions Server/tests/clientDependantTest.guitest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const crypto = require("crypto");
const fs = require("node:fs");


global.Neptune.setupConfigurations();

const Client = require("../src/Classes/Client");
const IPAddress = require("../src/Classes/IPAddress");
const ClientManager = require('../src/Classes/ClientManager.js');



/** @type {ClientManager} */
global.Neptune.clientManager = new ClientManager(global.Neptune.configurationManager);



function getClientSettings(value) {
return {
fileSharingSettings: {
allowClientToDownload: value,
allowClientToUpload: value,
enabled: value,
notifyOnClientUpload: value,
requireConfirmationOnClinetUploads: value,
},
clipboardSettingsAllFalse: {
allowClientToGet: value,
allowClientToSet: value,
enabled: value,
synchronizeClipboardToClient: value,
},
notificationSettings: {
enabled: value,
}
}
}

describe("Client class (non-API) tests", () => {

var clientUUID = null;
var client = null;

beforeAll(() => {
let MainWindow = new (require('../src/Windows/mainWindow.js'))();
clientUUID = crypto.randomUUID();
client = new Client(global.Neptune.configurationManager, clientUUID);
});

afterAll((done) => {
if (client) {
try {
client.delete();

setTimeout(() => {
done();
}, 1000);
} catch {
done();
}
} else {
done();
}
});

test("Enable clickboard sharing updates buttons", async () => {

});

/*test("emits delete on delete", () => {
client = new Client(global.Neptune.configurationManager, clientUUID);
jest.useFakeTimers();
const eventSpy = jest.fn();
client.eventEmitter.on('deleted', eventSpy);
client.delete();
jest.advanceTimersByTime(1000);
// Expect the event to have been emitted
expect(eventSpy).toHaveBeenCalledTimes(1);
jest.useRealTimers();
});*/
});
59 changes: 59 additions & 0 deletions Server/tests/nonClientDependantTest.guitest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Example Jest unit test file (for NodeGUI windows)
*
*
* A smart thing would to load the window as a constant or variable under NeptuneWindow, this way you're not constantly opening the window over and over.
*
*/

global.Neptune.setupConfigurations();

test('Open About Close About Window Test', async () => {
// Brings up the about window, clicks the "close" button and confirms it is closed
let aboutPage = new (require('../src/Windows/aboutWindow.js'))();
aboutPage.show();
expect(aboutPage.isVisible()).toBe(true);

aboutPage.getWidget("btnClose").click();
expect(aboutPage.isVisible()).toBe(false);
});

test('Open Connect Close Connect Window test', async () => {
// Brings up the about window, clicks the "close" button and confirms it is closed
let connectWindow = new (require('../src/Windows/tempConnectWindow.js'))();
connectWindow.show();
expect(connectWindow.isVisible()).toBe(true);

connectWindow.getWidget("closeButton").click();
expect(connectWindow.isVisible()).toBe(false);
});


test('Open Preference Close Preference Window test', async () => {
// Brings up the about window, clicks the "close" button and confirms it is closed
let preferenceWindow = new (require('../src/Windows/preferencePage.js'))();
preferenceWindow.show();
expect(preferenceWindow.isVisible()).toBe(true);

preferenceWindow.getWidget("btnClose").click();
expect(preferenceWindow.isVisible()).toBe(false);
});

async function Shutdown(shutdownTimeout) {
if (typeof shutdownTimeout !== "number") {
shutdownTimeout = 1500;
}

global.shuttingDown = true; // For when we kill the logger
Neptune.events.application.emit('shutdown', shutdownTimeout)
}
process.Shutdown = Shutdown;

/*test('Test Shutdown', async () => {
const eventSpy = jest.fn();
Neptune.events.application.on('shutdown', eventSpy)
expect(eventSpy).toHaveBeenCalledTimes(1);
});*/

global.Neptune.tearDownConfigurations();

0 comments on commit 14a3b9d

Please sign in to comment.