Skip to content

Commit

Permalink
Hide delete confirmation in testing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
C0Newb committed Apr 25, 2023
1 parent 14a3b9d commit 2dbaedd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 23 deletions.
18 changes: 11 additions & 7 deletions Server/src/Windows/mainWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class thisTest extends NeptuneWindow {


/** @type {ClientManager} */
clientManager = Neptune.clientManager;
clientManager = global.Neptune.clientManager;


/** @type {Map<string, Client>} */
Expand Down Expand Up @@ -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);
Expand Down
60 changes: 44 additions & 16 deletions Server/tests/clientDependantTest.guitest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');


Expand Down Expand Up @@ -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);
Expand All @@ -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();
});*/
});
});

0 comments on commit 2dbaedd

Please sign in to comment.