From 2afc156986086fa360d1ed4f1f0389c9bab4db3e Mon Sep 17 00:00:00 2001 From: Elvanos Date: Wed, 13 Sep 2023 23:58:02 +0200 Subject: [PATCH] fixed multi-instance allowing during testing --- src-electron/mainScripts/appManagement.ts | 2 +- src-electron/mainScripts/mainWindowCreation.ts | 7 ++++++- .../GlobalWindowButtons.playwright.test.ts | 15 +++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src-electron/mainScripts/appManagement.ts b/src-electron/mainScripts/appManagement.ts index 2a3666e..87ac4d3 100644 --- a/src-electron/mainScripts/appManagement.ts +++ b/src-electron/mainScripts/appManagement.ts @@ -16,7 +16,7 @@ export const openAppWindowManager = () => { // Create the app window in the normal way app.whenReady().then(mainWindowCreation) - // Create the app window + // Create the app window, if it still doesn't exist yet app.on('activate', () => { mainWindowCreation() }) diff --git a/src-electron/mainScripts/mainWindowCreation.ts b/src-electron/mainScripts/mainWindowCreation.ts index 2593f0a..3d49344 100644 --- a/src-electron/mainScripts/mainWindowCreation.ts +++ b/src-electron/mainScripts/mainWindowCreation.ts @@ -1,11 +1,14 @@ import { BrowserWindow, app } from 'electron' import { enable } from '@electron/remote/main' import path from 'path' - /** * Prevent app to launch a secondary instance */ const preventSecondaryAppInstance = (appWindow: BrowserWindow | undefined) => { + // Do not limit the window amount if we are in auto-test mode + if (process.env.TEST_ENV && (process.env.TEST_ENV === 'components' || process.env.TEST_ENV === 'e2e')) { + return + } /** * Determines if the app is the primary instance * - This exists as a variable due to the app bugging out if used directly from "app" @@ -76,4 +79,6 @@ export const mainWindowCreation = () => { // Check if we are on the primary or secondary instance of the app preventSecondaryAppInstance(appWindow) + + return appWindow } diff --git a/src/components/GlobalWindowButtons/GlobalWindowButtons.playwright.test.ts b/src/components/GlobalWindowButtons/GlobalWindowButtons.playwright.test.ts index d5d3c1f..0a51d63 100644 --- a/src/components/GlobalWindowButtons/GlobalWindowButtons.playwright.test.ts +++ b/src/components/GlobalWindowButtons/GlobalWindowButtons.playwright.test.ts @@ -76,11 +76,18 @@ test('Click resize button - "maximize"', async () => { // Check if the tested element exists if (resizeButton !== null) { - // Click twice - await resizeButton.click() - await resizeButton.click() + let isMaximized = await appWindow.evaluate(() => window.faWindowControlAPI.checkWindowMaximized()) - const isMaximized = await appWindow.evaluate(() => window.faWindowControlAPI.checkWindowMaximized()) + // Check if the window if maximized of not, react accordingly + if (isMaximized) { + // Click twice + await resizeButton.click() + await resizeButton.click() + } else { + await resizeButton.click() + } + + isMaximized = await appWindow.evaluate(() => window.faWindowControlAPI.checkWindowMaximized()) expect(isMaximized).toBe(true) } else {