fantasia-archive/src/components/GlobalWindowButtons/GlobalWindowButtons.playwright.test.ts

91 lines
2.8 KiB
TypeScript
Raw Normal View History

2023-09-04 08:48:18 +12:00
import appRoot from 'app-root-path'
import { _electron as electron } from 'playwright'
import { test, expect } from '@playwright/test'
const electronMainFilePath = appRoot + '/dist/electron/UnPackaged/electron-main.js'
const faFrontendRenderTimer = 1000
test('launch app', async () => {
const electronApp = await electron.launch({ args: [electronMainFilePath] })
// close app
await electronApp.close()
})
test('click resize button - smallify', async () => {
const electronApp = await electron.launch({ args: [electronMainFilePath] })
const appWindow = await electronApp.firstWindow()
await appWindow.waitForTimeout(faFrontendRenderTimer)
const resizeButton = await appWindow.$('.globalWindowButtons__resize')
2023-09-04 08:48:18 +12:00
if (resizeButton !== null) {
await resizeButton.click()
const isMaximized = await appWindow.evaluate(() => window.faWindowControlAPI.checkWindowMaximized())
expect(isMaximized).toBe(false)
} else {
test.fail()
}
// close app
await electronApp.close()
})
test('click resize button - maximize', async () => {
const electronApp = await electron.launch({ args: [electronMainFilePath] })
const appWindow = await electronApp.firstWindow()
await appWindow.waitForTimeout(faFrontendRenderTimer)
const resizeButton = await appWindow.$('.globalWindowButtons__resize')
2023-09-04 08:48:18 +12:00
if (resizeButton !== null) {
await resizeButton.click()
await resizeButton.click()
const isMaximized = await appWindow.evaluate(() => window.faWindowControlAPI.checkWindowMaximized())
expect(isMaximized).toBe(true)
} else {
test.fail()
}
// close app
await electronApp.close()
})
test('click minimize button', async () => {
const electronApp = await electron.launch({ args: [electronMainFilePath] })
const appWindow = await electronApp.firstWindow()
await appWindow.waitForTimeout(faFrontendRenderTimer)
const minimizeButton = await appWindow.$('.globalWindowButtons__minimize')
2023-09-04 08:48:18 +12:00
if (minimizeButton !== null) {
await minimizeButton.click()
const isMaximized = await appWindow.evaluate(() => window.faWindowControlAPI.checkWindowMaximized())
expect(isMaximized).toBe(false)
} else {
test.fail()
}
// close app
await electronApp.close()
})
2023-09-04 08:48:18 +12:00
/* This test can VERY occasionally fail when the window takes too long to close on weaker PCs. Simply rerunning the tests generally fixes this. */
test('click close button', async () => {
const electronApp = await electron.launch({ args: [electronMainFilePath] })
const appWindow = await electronApp.firstWindow()
await appWindow.waitForTimeout(faFrontendRenderTimer)
const closeButton = await appWindow.$('.globalWindowButtons__close')
2023-09-04 08:48:18 +12:00
if (closeButton !== null) {
let windowIsClosed = false
appWindow.on('close', () => {
windowIsClosed = true
})
await closeButton.click()
expect(windowIsClosed).toBe(true)
} else {
test.fail()
}
})