1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
@testable import Grain
import SwiftUI
import XCTest
/// The comment sheet, which is reused from three places — the gallery detail,
/// a feed card, and the story viewer — each handing it a different set of
/// callbacks and a different way to dismiss.
@MainActor
final class CommentSheetRenderTests: GrainTestCase {
private var account: TestAccount!
/// Async overrides: the synchronous `setUp`/`tearDown` are nonisolated, so
/// touching main-actor state from them warns.
override func setUp() async throws {
try await super.setUp()
account = TestAccount()
}
override func tearDown() async throws {
MockURLProtocol.handler = nil
account.restore()
try await super.tearDown()
}
private let settle: TimeInterval = 0.4
/// The sheet is used from the gallery detail, the card, and the story
/// viewer, each handing it a different set of callbacks and a different
/// dismiss affordance.
func testTheCommentSheetRendersInEachOfItsConfigurations() {
MockURLProtocol.respondByPath(Fixtures.routes)
let env = TestEnvironment()
let author = GrainProfile(
cid: "c1", did: "did:plc:someone", handle: "someone.test",
displayName: "Someone", avatar: "https://test.local/a.jpg"
)
let comments = [
GrainComment(
uri: "at://did:plc:someone/social.grain.comment/1", cid: "bafy1", author: author,
text: "A comment with a #hashtag and an @someone.test mention.",
createdAt: Fixtures.freshTimestamp, favCount: 3,
viewer: CommentViewerState(fav: "at://did:plc:test/social.grain.favorite/1")
),
GrainComment(
uri: "at://did:plc:test/social.grain.comment/2", cid: "bafy2",
author: GrainProfile(cid: "c2", did: "did:plc:test", handle: "tester.grain.social"),
text: "Your own comment, which you can delete.",
replyTo: "at://did:plc:someone/social.grain.comment/1",
createdAt: Fixtures.freshTimestamp
),
]
for style in [CommentDismissStyle.xmark, .done] {
ViewRender.render(
CommentSheetContent(
comments: comments,
isLoading: false,
isPostingComment: false,
client: env.client,
onPost: { _, _ in },
onDelete: { _ in },
onDismiss: {},
onProfileTap: { _ in },
onHashtagTap: { _ in },
onStoryTap: { _ in },
dismissStyle: style,
focusOnAppear: style == .done
)
.withTestEnvironment(env),
settle: settle
)
}
}
/// Signed out there is nothing to post with, so the input is absent.
func testTheCommentSheetRendersWhileSignedOut() {
MockURLProtocol.respondByPath(Fixtures.routes)
let env = TestEnvironment(authenticated: false)
ViewRender.render(
CommentSheetContent(
comments: [],
isLoading: false,
isPostingComment: false,
client: env.client,
onPost: { _, _ in },
onDelete: { _ in }
)
.withTestEnvironment(env),
settle: settle
)
}
}