1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

Improve tests

This commit is contained in:
2023-03-03 23:11:40 +01:00
parent 13ee618d5c
commit 127d5f4494
7 changed files with 166 additions and 69 deletions

View File

@ -0,0 +1,50 @@
//
// MainMenuTest.swift
// UI Tests
//
// Created by Nico Verbruggen on 03/03/2023.
// Copyright © 2023 Nico Verbruggen. All rights reserved.
//
import XCTest
final class MainMenuTest: UITestCase {
override func setUpWithError() throws {
continueAfterFailure = false
}
final func test_can_open_status_menu_item() throws {
let app = launch(openMenu: true)
assertAllExist([
// "Switch to PHP 8.2 (php)" should be visible since it is aliased to `php`
app.menuItems["\("mi_php_switch".localized) 8.2 (php)"],
// "Switch to PHP 8.1" should be the non-disabled option
app.menuItems["\("mi_php_switch".localized) 8.1 (php@8.1)"],
// "Switch to PHP 8.0" should be the non-disabled option
app.menuItems["\("mi_php_switch".localized) 8.0 (php@8.0)"],
// We should see the about and quit items
app.menuItems["mi_about".localized],
app.menuItems["mi_quit".localized]
])
sleep(2)
}
final func test_can_open_about() throws {
let app = launch(openMenu: true)
app.mainMenuItem(withText: "mi_about".localized).click()
}
final func test_can_open_settings() throws {
let app = launch(openMenu: true)
app.mainMenuItem(withText: "mi_preferences".localized).click()
}
final func test_can_quit_app() throws {
let app = launch(openMenu: true)
app.mainMenuItem(withText: "mi_quit".localized).click()
}
}

View File

@ -20,9 +20,7 @@ final class StartupTest: UITestCase {
var configuration = TestableConfigurations.working
configuration.filesystem["/opt/homebrew/bin/php"] = nil // PHP binary must be missing
let app = XCPMApplication()
app.withConfiguration(configuration)
app.launch()
let app = launch(with: configuration)
// Dialog 1: "PHP is not correctly installed"
assertAllExist([
@ -52,9 +50,7 @@ final class StartupTest: UITestCase {
var configuration = TestableConfigurations.working
configuration.filesystem["/opt/homebrew/etc/php/8.2/php-fpm.d/valet-fpm.conf"] = nil
let app = XCPMApplication()
app.withConfiguration(configuration)
app.launch()
let app = launch(with: configuration)
assertExists(app.staticTexts["alert.php_fpm_broken.title".localized], 3.0)
click(app.buttons["generic.ok".localized])
@ -64,30 +60,9 @@ final class StartupTest: UITestCase {
var configuration = TestableConfigurations.working
configuration.shellOutput["valet --version"] = .instant("Laravel Valet 5.0")
let app = XCPMApplication()
app.withConfiguration(configuration)
app.launch()
let app = launch(with: configuration)
assertExists(app.staticTexts["startup.errors.valet_version_not_supported.title".localized], 3.0)
click(app.buttons["generic.ok".localized])
}
final func test_can_open_status_menu_item() throws {
let app = XCPMApplication()
app.withConfiguration(TestableConfigurations.working)
app.launch()
// Note: If this fails here, make sure the menu bar item can be displayed
// If you use Bartender or something like this, this item may be hidden and tests will fail
app.statusItems.firstMatch.click()
assertAllExist([
// "Switch to PHP 8.1 (php)" should be visible since it is aliased to `php`
app.menuItems["\("mi_php_switch".localized) 8.2 (php)"],
// We should see the about and quit items
app.menuItems["mi_about".localized],
app.menuItems["mi_quit".localized]
])
sleep(2)
}
}

View File

@ -9,7 +9,6 @@
import XCTest
class UITestCase: XCTestCase {
/** Launches the app and opens the menu. */
public func launch(
openMenu: Bool = false,
@ -50,7 +49,15 @@ class UITestCase: XCTestCase {
public func click(_ element: XCUIElement) {
element.click()
}
}
extension XCPMApplication {
/**
Opens a given menu item found in the menu bar's status item.
*/
public func mainMenuItem(withText text: String) -> XCUIElement {
self.statusItems.firstMatch.menuItems[text].firstMatch
}
}
extension XCUIElement {