From 2dbaedd5fe4be60a84744e691b32b6aedfe04cb6 Mon Sep 17 00:00:00 2001 From: C0Newb Date: Mon, 24 Apr 2023 23:49:29 -0400 Subject: [PATCH] Hide delete confirmation in testing mode --- Server/src/Windows/mainWindow.js | 18 ++++--- Server/tests/clientDependantTest.guitest.js | 60 +++++++++++++++------ 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/Server/src/Windows/mainWindow.js b/Server/src/Windows/mainWindow.js index 3b384a3..bba920d 100644 --- a/Server/src/Windows/mainWindow.js +++ b/Server/src/Windows/mainWindow.js @@ -36,7 +36,7 @@ class thisTest extends NeptuneWindow { /** @type {ClientManager} */ - clientManager = Neptune.clientManager; + clientManager = global.Neptune.clientManager; /** @type {Map} */ @@ -1354,12 +1354,16 @@ class thisTest extends NeptuneWindow { let cancelButton = new NodeGUI.QPushButton(); cancelButton.setText("No"); - let result = this.displayMessageBox("Delete and unpair " + (client.friendlyName === undefined? "the client" : client.friendlyName) + "?", - "Are you sure you want to delete and unpair with " + (client.friendlyName === undefined? "the client" : client.friendlyName) + "?", - [ - { button: okayButton, buttonRole: NodeGUI.ButtonRole.AcceptRole }, - { button: cancelButton, buttonRole: NodeGUI.ButtonRole.RejectRole }, - ]); + let result = NodeGUI.DialogCode.Accepted; + if (global.testing) { + result = NodeGUI.DialogCode.Rejected; + } else + result = this.displayMessageBox("Delete and unpair " + (client.friendlyName === undefined? "the client" : client.friendlyName) + "?", + "Are you sure you want to delete and unpair with " + (client.friendlyName === undefined? "the client" : client.friendlyName) + "?", + [ + { button: okayButton, buttonRole: NodeGUI.ButtonRole.AcceptRole }, + { button: cancelButton, buttonRole: NodeGUI.ButtonRole.RejectRole }, + ]); if (result != NodeGUI.DialogCode.Accepted) { this.RemoveClientFromDeviceList(client.friendlyName); diff --git a/Server/tests/clientDependantTest.guitest.js b/Server/tests/clientDependantTest.guitest.js index 290e7bb..ec17efb 100644 --- a/Server/tests/clientDependantTest.guitest.js +++ b/Server/tests/clientDependantTest.guitest.js @@ -5,7 +5,6 @@ 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'); @@ -36,22 +35,27 @@ function getClientSettings(value) { } } +const MainWindow = new (require('../src/Windows/mainWindow.js'))(); +MainWindow.show(); + describe("Client class (non-API) tests", () => { - var clientUUID = null; - var client = null; + var clientUUID = undefined; + var client = undefined; - beforeAll(() => { - let MainWindow = new (require('../src/Windows/mainWindow.js'))(); + beforeEach(() => { clientUUID = crypto.randomUUID(); - client = new Client(global.Neptune.configurationManager, clientUUID); + client = global.Neptune.clientManager.getClient(clientUUID); + client.friendlyName = "MyTestDevice"; + client.batteryLevel = 60; + global.testing = true; + MainWindow.AddClientToDeviceList(client); }); - afterAll((done) => { + afterEach((done) => { if (client) { try { - client.delete(); - + client.delete(); setTimeout(() => { done(); }, 1000); @@ -63,22 +67,46 @@ describe("Client class (non-API) tests", () => { } }); - test("Enable clickboard sharing updates buttons", async () => { - + afterAll(() => { + MainWindow.hide(); + }) + + test("Clipboard sharing updates buttons", async () => { + if (MainWindow.chkSyncClipboard.isChecked()) + MainWindow.chkSyncClipboard.click(); // turn off + + expect(MainWindow.btnSendClipboard.isEnabled()).toBe(false); + expect(MainWindow.btnReceiveClipboard.isEnabled()).toBe(false); + + MainWindow.chkSyncClipboard.click(); + + expect(MainWindow.btnSendClipboard.isEnabled()).toBe(true); + expect(MainWindow.btnReceiveClipboard.isEnabled()).toBe(true); }); - /*test("emits delete on delete", () => { - client = new Client(global.Neptune.configurationManager, clientUUID); + test("File sharing updates buttons", async () => { + if (MainWindow.chkFileSharingEnable.isChecked()) + MainWindow.chkFileSharingEnable.click(); // turn off + expect(MainWindow.btnSendFile.isEnabled()).toBe(false); + + MainWindow.chkFileSharingEnable.click(); + + expect(MainWindow.btnSendFile.isEnabled()).toBe(true); + }); + + test("Client emits delete on delete press", () => { + let cclient = global.Neptune.clientManager.getClient(clientUUID); jest.useFakeTimers(); const eventSpy = jest.fn(); - client.eventEmitter.on('deleted', eventSpy); + eventSpy(); + cclient.eventEmitter.on('deleted', eventSpy); - client.delete(); + MainWindow.btnDelete.click(); jest.advanceTimersByTime(1000); // Expect the event to have been emitted expect(eventSpy).toHaveBeenCalledTimes(1); jest.useRealTimers(); - });*/ + }); }); \ No newline at end of file