Commit 44a08ad62a

44a08ad62a213299c91fce8143155e6ff27efed1

parent: f96de825e7

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-23 02:17 UTC

Drag the UI tests through a step's turns

The UI drag helper stops at a fold-and-unfold's peak and at a non-rigid
step's phase boundaries wherever the path turns back there, carries the
drag 6 points past, and starts a drag whose point lies outside the paper
view at the view's centre, since the app reads only the translation. The
audit now walks every step of all four models.

Closes #7

Layout: unified · split

App/UITests/FoldGestureTests.swift +31 −29
@@ -31,10 +31,13 @@ func completeCurrentFold(_ app: XCUIApplication) {
3131
3232/// Drags the current step's moving faces along their path, read from `fold.path` (the app must be
3333/// launched with `-UITesting`), to `fraction` of it, then lifts. Each drag is one straight
34/// press-and-drag through every 32nd sample, and a fold-and-unfold's peak, with short ones merged
35/// so each moves at least `minimumChord` points: a DragGesture does not begin under 10. A drag to
36/// the peak continues 8 points past it, and a drag to the end 30. Each holds before lifting, so its
37/// last position arrives before the lift.
34/// press-and-drag through every 32nd sample and every turn, with short ones merged so each moves
35/// at least `minimumChord` points: a DragGesture does not begin under 10. A turn is where the path
36/// goes back the way it came, at a fold-and-unfold's peak or at a non-rigid step's phase
37/// boundaries (t = ⅓ and ⅔); a drag to a turn continues 6 points past it, since the drag after it
38/// starts back along the way it came, and a drag to the end continues 30 points past it. The app
39/// reads only a drag's translation, so a drag from a point outside the paper view starts at its
40/// centre instead. Each holds before lifting, so its last position arrives before the lift.
3841func dragCurrentFold(_ app: XCUIApplication, to fraction: Double) {
3942 let paper = app.otherElements["fold.paper"]
4043 let marker = app.descendants(matching: .any)["fold.path"]
@@ -49,37 +52,36 @@ func dragCurrentFold(_ app: XCUIApplication, to fraction: Double) {
4952 CGVector(dx: (samples[b].dx - samples[a].dx) * size.width, dy: (samples[b].dy - samples[a].dy) * size.height)
5053 }
5154 func length(_ v: CGVector) -> Double { (v.dx * v.dx + v.dy * v.dy).squareRoot() }
55 func dot(_ u: CGVector, _ v: CGVector) -> Double { u.dx * v.dx + u.dy * v.dy }
5256 let last = Int((fraction * Double(samples.count - 1)).rounded())
53 // a fold-and-unfold turns back at its peak, the sample farthest from the start; the drag that
54 // reaches it carries on past it, since the drag after it starts back down the way it came
55 let peak = stepKind(app) == "foldAndUnfold" && last > 1
56 ? (1..<last).max { length(chord(0, $0)) < length(chord(0, $1)) } : nil
57
58 // a turn: the path arrives along one direction and leaves against it; its sample is the one
59 // furthest along the arrival within two of the boundary's
60 let boundaries = stepKind(app) == "foldAndUnfold" ? [64] : [43, 85]
61 var turns: [Int] = []
62 for c in boundaries where c + 2 < last {
63 let arriving = chord(c - 8, c), leaving = chord(c, min(c + 24, last))
64 guard length(arriving) > 2, length(leaving) > 2, dot(arriving, leaving) < 0 else { continue }
65 turns.append(((c - 2)...(c + 2)).max { dot(chord(0, $0), arriving) < dot(chord(0, $1), arriving) }!)
66 }
5767 var stops = [0]
58 for i in (Array(stride(from: 32, through: last, by: 32)) + (peak.map { [$0] } ?? [])).sorted()
59 where i == peak || (length(chord(stops.last!, i)) >= minimumChord && abs(i - (peak ?? -99)) >= 8) {
60 if i == peak {
61 while stops.count > 1 && length(chord(stops.last!, i)) < minimumChord { stops.removeLast() }
68 let regular = stride(from: 32, to: last, by: 32).filter { i in !turns.contains { abs($0 - i) < 8 } }
69 for i in (regular + turns + [last]).sorted() {
70 if !turns.contains(i) && i != last && length(chord(stops.last!, i)) < minimumChord { continue }
71 while stops.count > 1 && !turns.contains(stops.last!) && length(chord(stops.last!, i)) < minimumChord {
72 stops.removeLast()
6273 }
6374 stops.append(i)
6475 }
65 if stops.last != last {
66 if stops.count > 1 && length(chord(stops.last!, last)) < minimumChord {
67 stops[stops.count - 1] = last
68 } else {
69 stops.append(last)
70 }
71 }
76
7277 for (a, b) in zip(stops, stops.dropFirst()) {
73 var end = paper.coordinate(withNormalizedOffset: samples[b])
74 if b == samples.count - 1 {
75 let d = chord(a, b), l = max(length(d), 1)
76 end = end.withOffset(CGVector(dx: d.dx / l * 30, dy: d.dy / l * 30))
77 } else if b == peak {
78 let d = chord(a, b), l = max(length(d), 1)
79 end = end.withOffset(CGVector(dx: d.dx / l * 8, dy: d.dy / l * 8))
80 }
81 paper.coordinate(withNormalizedOffset: samples[a])
82 .press(forDuration: 0.1, thenDragTo: end, withVelocity: .default, thenHoldForDuration: 0.3)
78 var move = chord(a, b)
79 let l = max(length(move), 1), past = b == samples.count - 1 ? 30.0 : turns.contains(b) ? 6.0 : 0.0
80 move = CGVector(dx: move.dx + move.dx / l * past, dy: move.dy + move.dy / l * past)
81 let inside = (0.02...0.98).contains(samples[a].dx) && (0.02...0.98).contains(samples[a].dy)
82 let start = paper.coordinate(withNormalizedOffset: inside ? samples[a] : CGVector(dx: 0.5, dy: 0.5))
83 start.press(forDuration: 0.1, thenDragTo: start.withOffset(move), withVelocity: .default,
84 thenHoldForDuration: 0.3)
8385 }
8486}
8587
docs/authoring/crane.md +2 −2
@@ -141,8 +141,8 @@ For the drag, at each step's authored viewpoint:
141141
142142- the neck's and the tail's pops move a covering axis's centroid at least 8 points on screen,
143143 so the drag follows them;
144- the head's pop moves less, so its segment is the straight line down, at most half the paper
145 view's height for the pop (R81).
144- the head's pop moves less, so its segment is the straight line down, 160 points per unit of t
145 or half the paper view's height if that is less (R81).
146146
147147## Layer-order overrides
148148