2022-02-14 18:05:21 +02:00
|
|
|
//
|
2024-09-06 16:34:30 +03:00
|
|
|
// Copyright 2022-2024 New Vector Ltd.
|
2022-02-14 18:05:21 +02:00
|
|
|
//
|
2025-01-06 11:27:37 +01:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
// Please see LICENSE files in the repository root for full details.
|
2022-02-14 18:05:21 +02:00
|
|
|
//
|
|
|
|
|
2022-07-06 14:49:05 +01:00
|
|
|
import XCTest
|
2022-06-21 20:28:42 +03:00
|
|
|
|
|
|
|
@MainActor
|
|
|
|
class RoomScreenUITests: XCTestCase {
|
2023-05-15 15:42:40 +02:00
|
|
|
func testPlainNoAvatar() async throws {
|
2023-02-14 16:25:24 +00:00
|
|
|
let app = Application.launch(.roomPlainNoAvatar)
|
2022-06-21 20:28:42 +03:00
|
|
|
|
2023-02-15 05:53:04 +00:00
|
|
|
XCTAssert(app.staticTexts[A11yIdentifiers.roomScreen.name].exists)
|
|
|
|
XCTAssert(app.staticTexts[A11yIdentifiers.roomScreen.avatar].exists)
|
2022-08-11 15:02:47 +03:00
|
|
|
|
2025-01-08 10:55:26 +02:00
|
|
|
try await app.assertScreenshot(.roomPlainNoAvatar, delay: .seconds(0.5))
|
2022-06-21 20:28:42 +03:00
|
|
|
}
|
2022-12-12 12:27:49 +00:00
|
|
|
|
2023-05-15 15:42:40 +02:00
|
|
|
func testSmallTimelineLayout() async throws {
|
2023-02-14 16:25:24 +00:00
|
|
|
let app = Application.launch(.roomSmallTimeline)
|
2022-12-12 12:27:49 +00:00
|
|
|
|
|
|
|
// The messages should be bottom aligned.
|
2025-01-08 10:55:26 +02:00
|
|
|
try await app.assertScreenshot(.roomSmallTimeline, delay: .seconds(0.5))
|
2022-12-12 12:27:49 +00:00
|
|
|
}
|
|
|
|
|
2023-02-15 14:02:50 +00:00
|
|
|
func testSmallTimelineWithIncomingAndPagination() async throws {
|
|
|
|
let client = try UITestsSignalling.Client(mode: .tests)
|
2023-01-05 16:35:20 +00:00
|
|
|
|
2023-02-14 16:25:24 +00:00
|
|
|
let app = Application.launch(.roomSmallTimelineIncomingAndSmallPagination)
|
2022-12-12 12:27:49 +00:00
|
|
|
|
2023-02-15 14:02:50 +00:00
|
|
|
await client.waitForApp()
|
|
|
|
defer { try? client.stop() }
|
2023-01-05 16:35:20 +00:00
|
|
|
|
|
|
|
// When a back pagination occurs and an incoming message arrives.
|
2023-02-15 14:02:50 +00:00
|
|
|
try await performOperation(.incomingMessage, using: client)
|
|
|
|
try await performOperation(.paginate, using: client)
|
2022-12-12 12:27:49 +00:00
|
|
|
|
2023-01-05 16:35:20 +00:00
|
|
|
// Then the 4 visible messages should stay aligned to the bottom.
|
2025-01-08 10:55:26 +02:00
|
|
|
try await app.assertScreenshot(.roomSmallTimelineIncomingAndSmallPagination, delay: .seconds(0.5))
|
2022-12-12 12:27:49 +00:00
|
|
|
}
|
|
|
|
|
2023-02-15 14:02:50 +00:00
|
|
|
func testSmallTimelineWithLargePagination() async throws {
|
|
|
|
let client = try UITestsSignalling.Client(mode: .tests)
|
2023-01-05 16:35:20 +00:00
|
|
|
|
2023-02-14 16:25:24 +00:00
|
|
|
let app = Application.launch(.roomSmallTimelineLargePagination)
|
2023-01-05 16:35:20 +00:00
|
|
|
|
2023-02-15 14:02:50 +00:00
|
|
|
await client.waitForApp()
|
|
|
|
defer { try? client.stop() }
|
2023-01-05 16:35:20 +00:00
|
|
|
|
|
|
|
// When a large back pagination occurs.
|
2023-02-15 14:02:50 +00:00
|
|
|
try await performOperation(.paginate, using: client)
|
2023-01-05 16:35:20 +00:00
|
|
|
|
|
|
|
// The bottom of the timeline should remain visible with more items added above.
|
2025-01-08 10:55:26 +02:00
|
|
|
try await app.assertScreenshot(.roomSmallTimelineLargePagination, delay: .seconds(0.5))
|
2023-01-05 16:35:20 +00:00
|
|
|
}
|
|
|
|
|
2023-02-15 14:02:50 +00:00
|
|
|
func testTimelineLayoutAtTop() async throws {
|
|
|
|
let client = try UITestsSignalling.Client(mode: .tests)
|
2023-01-05 16:35:20 +00:00
|
|
|
|
2023-02-14 16:25:24 +00:00
|
|
|
let app = Application.launch(.roomLayoutTop)
|
2023-01-05 16:35:20 +00:00
|
|
|
|
2023-02-15 14:02:50 +00:00
|
|
|
await client.waitForApp()
|
|
|
|
defer { try? client.stop() }
|
2023-01-05 16:35:20 +00:00
|
|
|
|
|
|
|
// Given a timeline that is scrolled to the top.
|
2023-05-25 12:13:45 +02:00
|
|
|
for _ in 0...5 {
|
2023-05-26 17:43:38 +03:00
|
|
|
app.swipeDown()
|
2023-01-05 16:35:20 +00:00
|
|
|
}
|
2025-01-08 10:55:26 +02:00
|
|
|
try await app.assertScreenshot(.roomLayoutTop, delay: .seconds(0.5)) // Assert initial state for comparison.
|
2023-01-05 16:35:20 +00:00
|
|
|
|
|
|
|
// When a back pagination occurs.
|
2023-02-15 14:02:50 +00:00
|
|
|
try await performOperation(.paginate, using: client)
|
2023-01-05 16:35:20 +00:00
|
|
|
|
|
|
|
// Then the bottom of the timeline should remain unchanged (with new items having been added above).
|
2025-01-08 10:55:26 +02:00
|
|
|
try await app.assertScreenshot(.roomLayoutTop, delay: .seconds(0.5))
|
2023-01-05 16:35:20 +00:00
|
|
|
}
|
2023-05-15 15:42:40 +02:00
|
|
|
|
2023-05-26 17:43:38 +03:00
|
|
|
func testTimelineLayoutAtBottom() async throws {
|
|
|
|
let client = try UITestsSignalling.Client(mode: .tests)
|
|
|
|
|
|
|
|
let app = Application.launch(.roomLayoutBottom)
|
|
|
|
|
|
|
|
await client.waitForApp()
|
|
|
|
defer { try? client.stop() }
|
|
|
|
|
|
|
|
// Some time for the timeline to settle
|
|
|
|
try await Task.sleep(for: .seconds(1))
|
|
|
|
// When an incoming message arrives.
|
|
|
|
try await performOperation(.incomingMessage, using: client)
|
|
|
|
// Some time for the timeline to settle
|
|
|
|
try await Task.sleep(for: .seconds(1))
|
|
|
|
|
|
|
|
// Then the timeline should scroll down to reveal the message.
|
2025-01-08 10:55:26 +02:00
|
|
|
try await app.assertScreenshot(.roomLayoutBottom, step: 0, delay: .seconds(0.5))
|
2023-05-26 17:43:38 +03:00
|
|
|
|
|
|
|
// When the keyboard appears for the message composer.
|
|
|
|
try await tapMessageComposer(in: app)
|
|
|
|
|
2025-01-08 10:55:26 +02:00
|
|
|
try await app.assertScreenshot(.roomLayoutBottom, step: 1, delay: .seconds(0.5))
|
2023-05-26 17:43:38 +03:00
|
|
|
}
|
2024-04-29 10:00:41 +01:00
|
|
|
|
|
|
|
func testTimelineLayoutHighlightExisting() async throws {
|
|
|
|
let client = try UITestsSignalling.Client(mode: .tests)
|
|
|
|
|
|
|
|
let app = Application.launch(.roomLayoutHighlight)
|
|
|
|
|
|
|
|
await client.waitForApp()
|
|
|
|
defer { try? client.stop() }
|
|
|
|
|
|
|
|
// When tapping a permalink to an item in the timeline.
|
|
|
|
try await performOperation(.focusOnEvent("$5"), using: client)
|
|
|
|
|
|
|
|
// Then the item should become highlighted.
|
2025-01-08 10:55:26 +02:00
|
|
|
try await app.assertScreenshot(.roomLayoutHighlight, step: 0, delay: .seconds(0.5))
|
2024-04-29 17:32:16 +01:00
|
|
|
|
|
|
|
guard UIDevice.current.userInterfaceIdiom == .phone else { return }
|
|
|
|
|
|
|
|
// When scrolling to the bottom and tapping the same permalink again.
|
|
|
|
app.buttons[A11yIdentifiers.roomScreen.scrollToBottom].tap()
|
|
|
|
try await Task.sleep(for: .seconds(1)) // Some time for the timeline to settle
|
|
|
|
try await performOperation(.focusOnEvent("$5"), using: client)
|
|
|
|
|
|
|
|
// Then the item should also be highlighted and scrolled to in the same state as before.
|
2024-05-14 16:02:50 +03:00
|
|
|
try await app.assertScreenshot(.roomLayoutHighlight, step: 0)
|
2024-04-29 10:00:41 +01:00
|
|
|
}
|
2023-06-08 12:05:56 +02:00
|
|
|
|
|
|
|
func testTimelineReadReceipts() async throws {
|
|
|
|
let app = Application.launch(.roomSmallTimelineWithReadReceipts)
|
|
|
|
|
|
|
|
// The messages should be bottom aligned.
|
2025-01-08 10:55:26 +02:00
|
|
|
try await app.assertScreenshot(.roomSmallTimelineWithReadReceipts, delay: .seconds(0.5))
|
2023-06-08 12:05:56 +02:00
|
|
|
}
|
2023-08-11 12:25:16 +02:00
|
|
|
|
|
|
|
func testTimelineDisclosedPolls() async throws {
|
|
|
|
let app = Application.launch(.roomWithDisclosedPolls)
|
|
|
|
|
|
|
|
try await app.assertScreenshot(.roomWithDisclosedPolls)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testTimelineUndisclosedPolls() async throws {
|
|
|
|
let app = Application.launch(.roomWithUndisclosedPolls)
|
|
|
|
|
|
|
|
try await app.assertScreenshot(.roomWithUndisclosedPolls)
|
|
|
|
}
|
|
|
|
|
2023-09-21 16:59:17 +02:00
|
|
|
func testTimelineOutgoingPolls() async throws {
|
|
|
|
let app = Application.launch(.roomWithOutgoingPolls)
|
|
|
|
|
|
|
|
try await app.assertScreenshot(.roomWithOutgoingPolls)
|
|
|
|
}
|
|
|
|
|
2023-01-05 16:35:20 +00:00
|
|
|
// MARK: - Helper Methods
|
|
|
|
|
2023-11-10 15:38:54 +00:00
|
|
|
private func performOperation(_ operation: UITestsSignal.Timeline, using client: UITestsSignalling.Client) async throws {
|
|
|
|
try client.send(.timeline(operation))
|
2023-02-15 14:02:50 +00:00
|
|
|
await _ = client.signals.values.first { $0 == .success }
|
2023-05-15 15:42:40 +02:00
|
|
|
try await Task.sleep(for: .seconds(2)) // Allow the timeline to update
|
2023-01-05 16:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private func tapMessageComposer(in app: XCUIApplication) async throws {
|
|
|
|
app.textViews.element.tap()
|
2023-05-17 18:15:43 +02:00
|
|
|
try await Task.sleep(for: .seconds(10)) // Allow the animations to complete
|
2022-12-12 12:27:49 +00:00
|
|
|
}
|
2022-06-21 20:28:42 +03:00
|
|
|
}
|