diff --git a/Server/jest-GUI.config.js b/Server/jest-GUI.config.js index ab3a0b2..2f2f2e2 100644 --- a/Server/jest-GUI.config.js +++ b/Server/jest-GUI.config.js @@ -31,4 +31,6 @@ module.exports = { roots: [ "\\tests" ], + + setupFilesAfterEnv: ["./tests/JestSetupEachTest.js"], }; diff --git a/Server/tests/ExampleWindow.guitest.js b/Server/tests/ExampleWindow.guitest.js index ebb13ad..293f36c 100644 --- a/Server/tests/ExampleWindow.guitest.js +++ b/Server/tests/ExampleWindow.guitest.js @@ -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 @@ -14,4 +15,6 @@ test('Example Window test', async () => { aboutWindow.getWidget("btnClose").click(); expect(aboutWindow.isVisible()).toBe(false); -}); \ No newline at end of file +}); + +global.Neptune.tearDownConfigurations(); \ No newline at end of file diff --git a/Server/tests/JestSetupEachTest.js b/Server/tests/JestSetupEachTest.js index c8a731d..7612660 100644 --- a/Server/tests/JestSetupEachTest.js +++ b/Server/tests/JestSetupEachTest.js @@ -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"); @@ -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); @@ -60,4 +66,9 @@ Neptune.tearDownConfigurations = function() { } else { console.warn("Neptune not defined"); } -} \ No newline at end of file +} + +Neptune.events = { + application: new EventEmitter("application"), + server: new EventEmitter("server") +} diff --git a/Server/tests/clientDependantTest.guitest.js b/Server/tests/clientDependantTest.guitest.js new file mode 100644 index 0000000..290e7bb --- /dev/null +++ b/Server/tests/clientDependantTest.guitest.js @@ -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(); + });*/ +}); \ No newline at end of file diff --git a/Server/tests/nonClientDependantTest.guitest.js b/Server/tests/nonClientDependantTest.guitest.js new file mode 100644 index 0000000..31b8c5d --- /dev/null +++ b/Server/tests/nonClientDependantTest.guitest.js @@ -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();