Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed scrollbars and reduced first responder juggling #2327

Merged
merged 5 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions deltachat-ios-uitests/ChatTests.swift
Amzd marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
//
// deltachat_ios_uitestsLaunchTests.swift
// deltachat-ios-uitests
//
// Created by Casper Zandbergen on 13/10/2024.
// Copyright © 2024 merlinux GmbH. All rights reserved.
//

import XCTest
import SnapshotTesting
@testable import deltachat_ios

final class ChatTests: XCTestCase {
var bundleIdentifier: String = "chat.delta.amzd"

override func setUp() {
continueAfterFailure = false
}

func testCreateAccount() throws {
// let url = URL(string: "chat.delta.deeplink://?chatId=1")!
// let url = URL(string: "dcaccount://https://nine.testrun.org/new")!
let app = XCUIApplication(bundleIdentifier: bundleIdentifier)
// app.open(url)
app.launchArguments += ["-last_active_tab2", "12"]
app.launchArguments += ["-last_active_chat_id", "0"]
app.launchArguments += ["--UITests"]
app.launch()
// TODO: get localizable strings from app
// XCTAssertFalse(app.navigationBars["Welcome to Delta Chat"].exists)
app.buttons["Create New Profile"].tap()
app.textFields["Your Name"].tap()
app.textFields["Your Name"].typeText("UITest")


app.buttons["Agree & Create Profile"].tap()
let notificationsAlert = app.alerts["“Delta Chat” Would Like to Send You Notifications"]
if notificationsAlert.exists {
notificationsAlert.buttons["Allow"].tap()
}

screenshot(app, named: "Created Account")
}

/// Make sure an account is logged in eg through testCreateAccount()
/// Warning: This clears your saved messages
func testChatViewController() {
let app = XCUIApplication(bundleIdentifier: bundleIdentifier)

// AppStateRestorer.Tab.chatTab = 12
app.launchArguments += ["-last_active_tab2", "12"]
app.launchArguments += ["-last_active_chat_id", "0"]
app.launchArguments += ["--UITests"]
app.launch()
app.staticTexts["Saved Messages"].tap()

// Clear Saved Messages
app.buttons["View Profile"].tap()
app.staticTexts["Clear Chat"].tap()
if app.buttons["Clear Chat"].exists {
app.buttons["Clear Chat"].tap()
} else { // chat was already empty
app.navigationBars.buttons["Chat"].tap()
}

// Send message
app.textViews["Write a message"].tap()
app.textViews["Write a message"].typeText("Hey!")
app.buttons["Send"].tap()
XCTAssert(app.cells[containing: "Delivery status: Delivered"].waitForExistence(timeout: 5))
screenshot(app, named: "Sent Message")

// Send Contact
app.buttons["Add Attachment"].tap()
app.buttons["Contact"].tap()
XCTAssert(app.navigationBars["Contacts"].waitForExistence(timeout: 3))
XCTAssertFalse(app.keyboards.firstMatch.exists)
screenshot(app, named: "Selecting Contact")
app.staticTexts["Me"].tap()
XCTAssert(app.keyboards.firstMatch.exists)
screenshot(app, named: "Sending Contact")
app.buttons["Send"].tap()
screenshot(app, named: "Sent Contact")

app.buttons["Add Attachment"].tap()
app.buttons["Voice Message"].tap()
let notificationsAlert = app.alerts["“Delta Chat” Would Like to Access the Microphone"]
if notificationsAlert.exists {
notificationsAlert.buttons["Allow"].tap()
}
XCTAssert(app.navigationBars["00:03"].waitForExistence(timeout: 5))
app.buttons["Send"].tap()
screenshot(app, named: "Sent Voice message")

// TODO: Make current date cell say "Today" so this test works tomorrow too
}
}

extension XCTestCase {
func screenshot(
_ app: XCUIApplication,
named name: String,
record recording: Bool? = nil,
timeout: TimeInterval = 5,
fileID: StaticString = #fileID,
file filePath: StaticString = #filePath,
testName: String = #function,
line: UInt = #line,
column: UInt = #column
) {
let previousContinueAfterFailure = continueAfterFailure
continueAfterFailure = true
assertSnapshot(
of: app.screenshot().image,
as: .image,
named: name + " - \(UIDevice.current.name) (\(UIDevice.current.systemVersion))",
record: recording,
timeout: timeout,
fileID: fileID,
file: filePath,
testName: testName,
line: line,
column: column
)
continueAfterFailure = previousContinueAfterFailure
}
}

extension XCUIElementQuery {
subscript(with part: String = "label", containing string: String) -> XCUIElement {
precondition(!string.contains("'"))
return self.element(matching: .init(format: "\(part) CONTAINS '\(string)'"))
}
}
32 changes: 32 additions & 0 deletions deltachat-ios.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"configurations" : [
{
"id" : "25A440E8-B4D6-45EB-A536-7CCD973EECAC",
"name" : "Configuration 1",
"options" : {

}
}
],
"defaultOptions" : {
"codeCoverage" : false,
"targetForVariableExpansion" : {
"containerPath" : "container:deltachat-ios.xcodeproj",
"identifier" : "7A9FB13F1FB061E2001FEA36",
"name" : "deltachat-ios"
}
},
"testTargets" : [
{
"skippedTests" : [
"ChatTests\/testCreateAccount()"
],
"target" : {
"containerPath" : "container:deltachat-ios.xcodeproj",
"identifier" : "5FAA92DD2CBC0FB300FA8F68",
"name" : "deltachat-ios-uitests"
}
}
],
"version" : 1
}
24 changes: 24 additions & 0 deletions deltachat-ios.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"originHash" : "09b08963887ce6eac26952e8acb25256a8ec102f2b5528ae68a97fa296723712",
"pins" : [
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "7b0bbbae90c41f848f90ac7b4df6c4f50068256d",
"version" : "1.17.5"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "0687f71944021d616d34d922343dcef086855920",
"version" : "600.0.1"
}
}
],
"version" : 3
}
2 changes: 1 addition & 1 deletion deltachat-ios/Chat/Views/DraftArea.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit
import DcCore

public class DraftArea: UIView, InputItem {
public var inputBarAccessoryView: InputBarAccessoryView?
public weak var inputBarAccessoryView: InputBarAccessoryView?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! excellent!

public var parentStackViewPosition: InputStackView.Position?
public func textViewDidChangeAction(with textView: InputTextView) {}
public func keyboardSwipeGestureAction(with gesture: UISwipeGestureRecognizer) {}
Expand Down