oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1import XCTest
2
3/// Runs against the production composer with the debug fake transport.
4final class AttachmentSourceUITests: XCTestCase {
5 @MainActor func testMenuPresentsPrivatePhotosPicker() throws {
6 let app = XCUIApplication()
7 app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent"
8 app.launch()
9 XCTAssertTrue(app.buttons["Attach"].waitForExistence(timeout: 10))
10 XCTAssertGreaterThanOrEqual(app.buttons["Attach"].frame.width, 44)
11 XCTAssertGreaterThanOrEqual(app.buttons["Attach"].frame.height, 44)
12 app.buttons["Attach"].tap()
13 if app.buttons["Not now"].waitForExistence(timeout: 2) {
14 app.buttons["Not now"].tap()
15 app.buttons["Attach"].tap()
16 }
17 XCTAssertTrue(app.buttons["Photos"].waitForExistence(timeout: 5))
18 XCTAssertTrue(app.buttons["Files"].exists)
19 XCTAssertTrue(app.buttons["Paste"].exists)
20 capture("iphone-add-menu")
21 app.buttons["Photos"].tap()
22 XCTAssertTrue(app.navigationBars["Photos"].waitForExistence(timeout: 10))
23 capture("iphone-photos-picker")
24 }
25 @MainActor func testComposerAppearances() throws {
26 for mode in ["light", "dark"] {
27 let app = XCUIApplication()
28 app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent"
29 app.launchEnvironment["EQUIPO_FIXTURE_DARK"] = mode == "dark" ? "1" : "0"
30 app.launch()
31 let field = app.textFields.firstMatch
32 XCTAssertTrue(field.waitForExistence(timeout: 10))
33 capture("iphone-" + mode + "-keyboard-down")
34 field.tap()
35 field.typeText("Please fix the sign-in button.")
36 XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 5))
37 capture("iphone-" + mode + "-keyboard-up")
38 app.terminate()
39 }
40 }
41 @MainActor func testConversationDragDismissesKeyboard() throws {
42 let app = XCUIApplication()
43 app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent"
44 app.launch()
45 let field = app.textFields.firstMatch
46 XCTAssertTrue(field.waitForExistence(timeout: 10))
47 field.tap()
48 field.typeText("Please fix the sign-in button.")
49 XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 5))
50 let message = app.staticTexts["You said: Home’s sign-in button is cut off on my phone."]
51 message.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
52 .press(forDuration: 0.01, thenDragTo: app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.99)), withVelocity: .fast, thenHoldForDuration: 0)
53 XCTAssertTrue(app.keyboards.firstMatch.waitForNonExistence(timeout: 5))
54 XCTAssertEqual(field.value as? String, "Please fix the sign-in button.")
55 field.tap()
56 XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 5))
57 app.scrollViews["conversation-scroll"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
58 .press(forDuration: 0.01, thenDragTo: app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.99)), withVelocity: .fast, thenHoldForDuration: 0)
59 XCTAssertTrue(app.keyboards.firstMatch.waitForNonExistence(timeout: 5))
60 }
61 /// The real phone tabs: the composer sits directly above the keyboard,
62 /// and reading (a scroll, a tap on the conversation) puts it away.
63 @MainActor func testKeyboardKeepsComposerAboveItInTabs() throws {
64 for mode in ["light", "dark"] {
65 let app = XCUIApplication()
66 app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent"
67 app.launchEnvironment["EQUIPO_FIXTURE_TABS"] = "1"
68 app.launchEnvironment["EQUIPO_FIXTURE_DARK"] = mode == "dark" ? "1" : "0"
69 app.launch()
70 let field = app.textFields.firstMatch
71 XCTAssertTrue(field.waitForExistence(timeout: 10))
72 field.tap()
73 field.typeText("Please fix the sign-in button.")
74 let keyboard = app.keyboards.firstMatch
75 XCTAssertTrue(keyboard.waitForExistence(timeout: 5))
76 Thread.sleep(forTimeInterval: 0.6)
77 XCTAssertTrue(field.isHittable, "the composer is hidden behind the keyboard")
78 XCTAssertLessThanOrEqual(field.frame.maxY, keyboard.frame.minY + 1, "the composer is not above the keyboard: \(field.frame) vs \(keyboard.frame)")
79 XCTAssertGreaterThan(field.frame.maxY, keyboard.frame.minY - 120, "the composer is not directly above the keyboard: \(field.frame) vs \(keyboard.frame)")
80 capture("keyboard-" + mode + "-up")
81 app.scrollViews["conversation-scroll"].swipeDown()
82 XCTAssertTrue(keyboard.waitForNonExistence(timeout: 5), "a scroll of the conversation keeps the keyboard")
83 XCTAssertEqual(field.value as? String, "Please fix the sign-in button.")
84 capture("keyboard-" + mode + "-scrolled")
85 app.terminate()
86 }
87 }
88 @MainActor func testTapOnConversationDismissesKeyboardButSendKeepsIt() throws {
89 let app = XCUIApplication()
90 app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent"
91 app.launchEnvironment["EQUIPO_FIXTURE_TABS"] = "1"
92 app.launch()
93 let field = app.textFields.firstMatch
94 XCTAssertTrue(field.waitForExistence(timeout: 10))
95 field.tap()
96 let keyboard = app.keyboards.firstMatch
97 XCTAssertTrue(keyboard.waitForExistence(timeout: 5))
98 app.scrollViews["conversation-scroll"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.15)).tap()
99 XCTAssertTrue(keyboard.waitForNonExistence(timeout: 5), "a tap on the conversation keeps the keyboard")
100 field.tap()
101 XCTAssertTrue(keyboard.waitForExistence(timeout: 5))
102 field.typeText("Again")
103 app.buttons["Send"].tap()
104 Thread.sleep(forTimeInterval: 0.5)
105 XCTAssertTrue(keyboard.exists, "Send keeps the keyboard for a follow-up")
106 XCTAssertTrue(field.isHittable, "the composer is above the keyboard after Send")
107 }
108 /// Paul's path: type, open a task link in a Coordinator message, come
109 /// back. The keyboard is down; tapping the field brings it back with the
110 /// composer directly above it. Then the same from the task's own reply.
111 @MainActor func testTaskLinkAndBackLeavesKeyboardDown() throws {
112 for mode in ["light", "dark"] {
113 let app = XCUIApplication()
114 app.launchEnvironment["EQUIPO_ATTACHMENTS_FIXTURE"] = "sent"
115 app.launchEnvironment["EQUIPO_FIXTURE_TABS"] = "1"
116 app.launchEnvironment["EQUIPO_FIXTURE_DARK"] = mode == "dark" ? "1" : "0"
117 app.launch()
118 let field = app.textFields["Message"]
119 XCTAssertTrue(field.waitForExistence(timeout: 10))
120 field.tap(); field.typeText("Looking")
121 let keyboard = app.keyboards.firstMatch
122 XCTAssertTrue(keyboard.waitForExistence(timeout: 5))
123 // The link is inside the Coordinator's sentence: tap its words.
124 let message = app.staticTexts["I started Fix the sign-in button."]
125 XCTAssertTrue(message.waitForExistence(timeout: 5))
126 message.coordinate(withNormalizedOffset: CGVector(dx: 0.7, dy: 0.5)).tap()
127 XCTAssertTrue(keyboard.waitForNonExistence(timeout: 5), "opening a task keeps the keyboard")
128 let back = app.navigationBars.buttons["Conversation"]
129 XCTAssertTrue(back.waitForExistence(timeout: 5))
130 let reply = app.textFields["Reply"]
131 if reply.waitForExistence(timeout: 3) {
132 reply.tap()
133 XCTAssertTrue(keyboard.waitForExistence(timeout: 5))
134 }
135 capture("keyboard-" + mode + "-task")
136 back.tap()
137 XCTAssertTrue(field.waitForExistence(timeout: 5))
138 Thread.sleep(forTimeInterval: 1)
139 if keyboard.exists {
140 XCTAssertLessThanOrEqual(field.frame.maxY, keyboard.frame.minY + 1, "back with the keyboard up and the composer behind it")
141 }
142 XCTAssertFalse(keyboard.exists, "coming back to the conversation brings the keyboard back")
143 capture("keyboard-" + mode + "-back")
144 field.tap()
145 XCTAssertTrue(keyboard.waitForExistence(timeout: 5))
146 Thread.sleep(forTimeInterval: 0.6)
147 XCTAssertLessThanOrEqual(field.frame.maxY, keyboard.frame.minY + 1, "the composer is not above the keyboard after coming back")
148 XCTAssertTrue(field.isHittable)
149 app.terminate()
150 }
151 }
152 @MainActor private func capture(_ name: String) {
153 let attachment = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
154 attachment.name = name; attachment.lifetime = .keepAlways; add(attachment)
155 }
156}
157