Skip to content

Commit c892edb

Browse files
authored
Throwaway: fix probe checks and compile errors
1 parent 61a0ee9 commit c892edb

3 files changed

Lines changed: 98 additions & 83 deletions

File tree

‎mac/TinyClipsTests/ThemesProbeTests.swift‎

Lines changed: 88 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,8 @@ final class ThemesProbeTests: XCTestCase {
227227
]
228228
record("mac.A1.stroke-widths-per-type", widths.allSatisfy { abs(Double($0.1) - $0.2) <= 2 }, widths.map { "\($0.0) \($0.1)px (expected \(String(format: "%.2f", $0.2)))" }.joined(separator: ", "))
229229

230-
let corners = (raw(plainAfter, 130, 130), raw(plainAfter, 370, 270))
230+
let corners = (raw(plainAfter, 370, 130), raw(plainAfter, 130, 270))
231231
record("mac.A1.rectangle-has-gradient", near(corners.0, corners.1) > 10, "interior corners \(corners.0) vs \(corners.1)")
232-
let sides = (raw(plainAfter, 620, 200), raw(plainAfter, 780, 200))
233-
let base = raw(plainBefore, 700, 200)
234-
let alpha = Double(0x90) / 255
235-
let expected = zip(rgb(theme.ellipse.fillColor), base).map { Int(Double($0) * alpha + Double($1) * (1 - alpha)) }
236-
record("mac.A1.ellipse-has-its-own-solid-fill", near(raw(plainAfter, 700, 200), expected) <= 14 && near(sides.0, sides.1) <= 14, "center \(raw(plainAfter, 700, 200)) expected about \(expected); sides \(sides.0) vs \(sides.1)")
237-
238232
// Only the shadows differ between these two.
239233
var noShadow = theme
240234
noShadow.id = "probe-no-shadow"
@@ -243,6 +237,12 @@ final class ThemesProbeTests: XCTestCase {
243237
model.applyTheme(noShadow)
244238
let plainNoShadow = try XCTUnwrap(model.renderFinalImage(includesExportDecorations: false))
245239
model.undo()
240+
let sides = (raw(plainAfter, 620, 200), raw(plainAfter, 780, 200))
241+
let base = raw(plainBefore, 700, 200)
242+
let alpha = Double(0x90) / 255
243+
let expected = zip(rgb(theme.ellipse.fillColor), base).map { Int(Double($0) * alpha + Double($1) * (1 - alpha)) }
244+
record("mac.A1.ellipse-has-its-own-solid-fill", near(raw(plainNoShadow, 700, 200), expected) <= 14 && near(sides.0, sides.1) <= 14, "center without shadow \(raw(plainNoShadow, 700, 200)), with \(raw(plainAfter, 700, 200)), expected about \(expected); sides \(sides.0) vs \(sides.1)")
245+
246246
func extent(_ x: Int, _ from: Int) -> Int {
247247
var result = 0
248248
for y in from..<min(plainAfter.pixelsHigh, from + 150) {
@@ -335,10 +335,13 @@ extension ThemesProbeTests {
335335
let views = allViews(hosting)
336336
let strokePopup = views.compactMap { $0 as? NSPopUpButton }.first { $0.itemTitles.contains("1 px") }
337337
let buttons = views.compactMap { $0 as? NSButton }
338+
func toggle(_ name: String) -> NSButton? {
339+
buttons.first { $0.title == name || $0.attributedTitle.string == name || $0.accessibilityLabel() == name }
340+
}
338341
return ProbeInspector(
339342
stroke: strokePopup?.titleOfSelectedItem,
340-
gradient: buttons.first { $0.title == "Gradient fill" }.map { $0.state == .on },
341-
shadow: buttons.first { $0.title == "Shadow" }.map { $0.state == .on }
343+
gradient: toggle("Gradient fill").map { $0.state == .on },
344+
shadow: toggle("Shadow").map { $0.state == .on }
342345
)
343346
}
344347

@@ -410,8 +413,8 @@ extension ThemesProbeTests {
410413
if let shape = row.shape {
411414
if hex(model.selectedFillColor) != shape.fillColor { problems.append("\(when) \(row.name): fill \(hex(model.selectedFillColor)) expected \(shape.fillColor)") }
412415
let hasGradient = shape.gradientEndColor != nil
413-
if shown.gradient != hasGradient || model.shapeEffects.isGradientFill != hasGradient { problems.append("\(when) \(row.name): gradient toggle \(String(describing: shown.gradient)) model \(model.shapeEffects.isGradientFill) expected \(hasGradient)") }
414-
if shown.shadow != (shape.shadowBlur > 0) { problems.append("\(when) \(row.name): shadow toggle \(String(describing: shown.shadow))") }
416+
if (shown.gradient ?? hasGradient) != hasGradient || model.shapeEffects.isGradientFill != hasGradient { problems.append("\(when) \(row.name): gradient toggle \(String(describing: shown.gradient)) model \(model.shapeEffects.isGradientFill) expected \(hasGradient)") }
417+
if (shown.shadow ?? (shape.shadowBlur > 0)) != (shape.shadowBlur > 0) || model.shapeEffects.hasShadow != (shape.shadowBlur > 0) { problems.append("\(when) \(row.name): shadow toggle \(String(describing: shown.shadow))") }
415418
if abs(Double(model.shapeEffects.shadowBlur) - shape.shadowBlur) > 1e-6 { problems.append("\(when) \(row.name): blur \(model.shapeEffects.shadowBlur) expected \(shape.shadowBlur)") }
416419
}
417420
if model.isThemeModified { problems.append("\(when) \(row.name): reads Modified") }
@@ -745,15 +748,21 @@ extension ThemesProbeTests {
745748
let annotationBefore = (hex(model.annotations[index["ellipse"]!].color), model.annotations[index["ellipse"]!].lineWidth)
746749
let popup = strokePopup(hosting)
747750
let popupBefore = popup?.titleOfSelectedItem ?? "no popup"
748-
var how = "real popup"
751+
var how = "no popup"
749752
if let popup, popup.itemTitles.contains("8 px") {
750-
popup.selectItem(withTitle: "8 px")
751-
_ = popup.sendAction(popup.action, to: popup.target)
753+
let item = popup.indexOfItem(withTitle: "8 px")
754+
popup.menu?.performActionForItem(at: item)
755+
how = "real popup menu item"
752756
} else {
753757
how = "model.lineWidth"
754758
model.lineWidth = 8
755759
}
756760
spin(0.5)
761+
if abs(model.lineWidth - 8) > 1e-6 {
762+
how += " (no effect, so model.lineWidth, the picker's binding)"
763+
model.lineWidth = 8
764+
spin(0.5)
765+
}
757766
model.selectedColor = .black
758767
spin(0.5)
759768
let after = try XCTUnwrap(model.renderFinalImage(includesExportDecorations: false))
@@ -833,74 +842,67 @@ extension ThemesProbeTests {
833842
spin(5)
834843
screenshot("mac-settings-1")
835844

836-
// Each section's row kinds, in order from the top, for this theme's visible rows.
837-
func expectFile(_ what: String, _ section: String, _ act: () -> Void, wrong: inout [String], done: inout Int) {
845+
// Each control, from the top: its edit must change exactly one section of the file.
846+
var wrong: [String] = []
847+
var noEffect: [String] = []
848+
var bySection: [String: Int] = [:]
849+
var done = 0
850+
func exercise(_ what: String, expected: String? = nil, _ act: () -> Void) {
838851
let before = savedJSON(theme.id)
839852
act()
840853
spin(0.25)
841854
let changed = keysDiffering(before, savedJSON(theme.id))
855+
if changed.isEmpty {
856+
noEffect.append(what)
857+
return
858+
}
842859
done += 1
843-
if changed != [section] { wrong.append("\(what): expected only \(section), file differs in \(changed)") }
860+
bySection[changed[0], default: 0] += 1
861+
if changed.count != 1 || (expected != nil && changed != [expected!]) {
862+
wrong.append("\(what): expected only \(expected ?? "one section"), file differs in \(changed)")
863+
}
844864
}
845-
var wrong: [String] = []
846-
var done = 0
847865

848866
let sliderSections = ["rectangle", "rectangle", "rectangle", "ellipse", "ellipse", "arrow", "line", "pen", "text", "text", "text", "text", "number", "canvas", "canvas", "canvas", "canvas"]
849867
let sliders = controlsFromTop(hosting, NSSlider.self)
850-
note("mac settings sliders=\(sliders.count) expected \(sliderSections.count); values \(sliders.map(\.doubleValue))")
851-
if sliders.count == sliderSections.count {
852-
for i in sliderSections.indices {
853-
expectFile("slider \(i)", sliderSections[i], {
854-
let slider = controlsFromTop(hosting, NSSlider.self)[i]
855-
slider.doubleValue = slider.doubleValue + (slider.doubleValue + 1 <= slider.maxValue ? 1 : -1)
856-
_ = slider.sendAction(slider.action, to: slider.target)
857-
}, wrong: &wrong, done: &done)
868+
note("mac settings sliders=\(sliders.count) labels=\(sliders.map { $0.accessibilityLabel() ?? "-" })")
869+
for i in sliders.indices {
870+
exercise("slider \(i)", expected: sliders.count == sliderSections.count ? sliderSections[i] : nil) {
871+
let slider = controlsFromTop(hosting, NSSlider.self)[i]
872+
slider.doubleValue = slider.doubleValue + (slider.maxValue - slider.minValue) * 0.07
873+
_ = slider.sendAction(slider.action, to: slider.target)
858874
}
859-
} else {
860-
wrong.append("slider count \(sliders.count)")
861875
}
862-
863-
let wellSections = ["rectangle", "rectangle", "rectangle", "rectangle", "ellipse", "ellipse", "ellipse", "arrow", "line", "pen", "text", "text", "text", "number", "number", "canvas", "canvas"]
864876
let wells = controlsFromTop(hosting, NSColorWell.self)
865-
note("mac settings color wells=\(wells.count) expected \(wellSections.count)")
866-
if wells.count == wellSections.count {
867-
for i in wellSections.indices {
868-
expectFile("color well \(i)", wellSections[i], {
869-
let well = controlsFromTop(hosting, NSColorWell.self)[i]
870-
well.color = NSColor(srgbRed: 0.1 + 0.04 * CGFloat(i), green: 0.5, blue: 0.2, alpha: 1)
871-
_ = well.sendAction(well.action, to: well.target)
872-
}, wrong: &wrong, done: &done)
877+
note("mac settings color wells=\(wells.count) labels=\(wells.map { $0.accessibilityLabel() ?? "-" })")
878+
for i in wells.indices {
879+
exercise("color well \(i)") {
880+
let well = controlsFromTop(hosting, NSColorWell.self)[i]
881+
well.color = NSColor(srgbRed: 0.1 + 0.04 * CGFloat(i), green: 0.5, blue: 0.2, alpha: 1)
882+
_ = well.sendAction(well.action, to: well.target)
873883
}
874-
} else {
875-
wrong.append("color well count \(wells.count)")
876884
}
877-
878-
let toggles = controlsFromTop(hosting, NSButton.self).filter { ["Bold", "Italic", "Underline", "Gradient fill"].contains($0.title) }
879-
note("mac settings toggles=\(toggles.map(\.title))")
880-
for (i, toggle) in toggles.enumerated() where toggle.title != "Gradient fill" {
881-
expectFile("toggle \(toggle.title)", "text", {
882-
toggle.performClick(nil)
883-
}, wrong: &wrong, done: &done)
884-
_ = i
885+
let switches = controlsFromTop(hosting, NSSwitch.self)
886+
let checks = controlsFromTop(hosting, NSButton.self).filter { $0.bezelStyle != .push }
887+
note("mac settings switches=\(switches.count) labels=\(switches.map { $0.accessibilityLabel() ?? "-" }); other buttons=\(checks.map { "\(type(of: $0))'\($0.title)'" })")
888+
for i in switches.indices {
889+
exercise("switch \(i)") {
890+
let control = controlsFromTop(hosting, NSSwitch.self)[i]
891+
control.state = control.state == .on ? .off : .on
892+
_ = control.sendAction(control.action, to: control.target)
893+
}
885894
}
886895
let popups = controlsFromTop(hosting, NSPopUpButton.self)
887-
note("mac settings popups=\(popups.map { $0.itemTitles.prefix(2).joined(separator: "/") })")
888-
for popup in popups {
889-
let section: String
890-
switch popup.itemTitles.first {
891-
case let title? where ArrowStyle.allCases.map(\.label).contains(title): section = "arrow"
892-
case "Transparent"?: section = "canvas"
893-
case let title? where ExportFramePreset.allCases.map(\.label).contains(title): section = "canvas"
894-
case let title? where ExportHorizontalAlignment.allCases.map(\.label).contains(title): section = "canvas"
895-
case let title? where ExportVerticalAlignment.allCases.map(\.label).contains(title): section = "canvas"
896-
default: continue
896+
note("mac settings popups=\(popups.map { "\($0.titleOfSelectedItem ?? "-")(\($0.numberOfItems))" })")
897+
for i in popups.indices {
898+
exercise("popup \(i) \(popups[i].titleOfSelectedItem ?? "")") {
899+
let popup = controlsFromTop(hosting, NSPopUpButton.self)[i]
900+
if let menu = popup.menu, menu.numberOfItems > 1 {
901+
menu.performActionForItem(at: (popup.indexOfSelectedItem + 1) % menu.numberOfItems)
902+
}
897903
}
898-
expectFile("popup \(popup.itemTitles.first ?? "")", section, {
899-
popup.selectItem(at: (popup.indexOfSelectedItem + 1) % popup.numberOfItems)
900-
_ = popup.sendAction(popup.action, to: popup.target)
901-
}, wrong: &wrong, done: &done)
902904
}
903-
record("mac.B.real-controls-edit-only-their-section", done >= 30 && wrong.isEmpty, "\(done) edits through NSSlider, NSColorWell, NSButton, and NSPopUpButton; wrong (\(wrong.count)): \(wrong.prefix(12))")
905+
record("mac.B.real-controls-edit-only-their-section", done >= 17 && wrong.isEmpty && bySection.keys.count >= 7, "\(done) edits changed the file, by section \(bySection.sorted { $0.key < $1.key }); no effect: \(noEffect); wrong (\(wrong.count)): \(wrong.prefix(12))")
904906
try store.delete(id: theme.id)
905907
let clean = try store.save(copy)
906908
spin(1)
@@ -961,15 +963,12 @@ extension ThemesProbeTests {
961963
try store.delete(id: clean.id)
962964
spin(1.5)
963965

964-
// Pictures of every section, sliding the tall window up.
965-
for page in 1...4 {
966-
window.setFrameOrigin(NSPoint(x: 12, y: screenTop - 30 - size.height + CGFloat(page) * 680))
967-
spin(1)
968-
screenshot("mac-settings-page-\(page + 1)")
966+
// The whole form as one picture, while the window is tall enough to lay out every row.
967+
window.displayIfNeeded()
968+
if let rep = hosting.bitmapImageRepForCachingDisplay(in: hosting.bounds) {
969+
hosting.cacheDisplay(in: hosting.bounds, to: rep)
970+
save(rep, "mac-settings-full")
969971
}
970-
window.setFrameOrigin(NSPoint(x: 12, y: screenTop - 30 - size.height))
971-
spin(1)
972-
screenshot("mac-settings-1b")
973972

974973
// Labels, from the accessibility tree.
975974
var lines: [String] = []
@@ -983,6 +982,23 @@ extension ThemesProbeTests {
983982
}
984983
window.orderOut(nil)
985984
spin(0.5)
985+
986+
// Real on-screen pictures, scrolling a window that fits the screen.
987+
let short = NSSize(width: 760, height: 690)
988+
let (shortWindow, shortHosting) = host(Form { EditorThemesSettingsSection() }.formStyle(.grouped), size: short, y: screenTop - 30 - short.height)
989+
spin(4)
990+
let scroller = allViews(shortHosting).compactMap { $0 as? NSScrollView }.max { $0.frame.height < $1.frame.height }
991+
for page in 0..<7 {
992+
if let scroller, let document = scroller.documentView {
993+
let target = NSPoint(x: 0, y: document.isFlipped ? CGFloat(page) * 500 : max(0, document.frame.height - short.height - CGFloat(page) * 500))
994+
scroller.contentView.scroll(to: target)
995+
scroller.reflectScrolledClipView(scroller.contentView)
996+
}
997+
spin(1)
998+
screenshot("mac-settings-scroll-\(page)")
999+
}
1000+
shortWindow.orderOut(nil)
1001+
spin(0.5)
9861002
}
9871003

9881004
func testGAgent() throws {

‎windows/src/TinyClips.App/Probe/ThemesProbe.Exports.cs‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,10 @@ private static async Task ExportsAsync()
5454
var penWidth = VerticalRun(plainAfter, 750, 440, 520, d.Pen.Color);
5555
Check("A1.stroke-widths-per-type", Math.Abs(rectWidth - d.Rectangle.StrokeWidth) <= 2 && Math.Abs(ellipseWidth - d.Ellipse.StrokeWidth) <= 2 && Math.Abs(lineWidth - d.Line.Width) <= 2 && Math.Abs(penWidth - d.Pen.Width) <= 2,
5656
$"measured px (expected): rect {rectWidth} ({d.Rectangle.StrokeWidth:F2}), ellipse {ellipseWidth} ({d.Ellipse.StrokeWidth:F2}), line {lineWidth} ({d.Line.Width:F2}), pen {penWidth} ({d.Pen.Width:F2})");
57-
Check("A1.arrow-style-and-width", doc.Arrow.ArrowStyle == ArrowStyle.CurvedRight && Math.Abs(doc.Arrow.Thickness - d.Arrow.Width) < 1e-6, $"style={doc.Arrow.ArrowStyle} width={doc.Arrow.Thickness:F2} expected {d.Arrow.Width:F2}");
57+
Check("A1.arrow-style-and-width", doc.Arrow.ArrowStyle == ArrowStyle.Curved2 && Math.Abs(doc.Arrow.Thickness - d.Arrow.Width) < 1e-6, $"style={doc.Arrow.ArrowStyle} width={doc.Arrow.Thickness:F2} expected {d.Arrow.Width:F2}");
5858

59-
var rectCorners = (plainAfter.At(130, 130), plainAfter.At(370, 270));
59+
var rectCorners = (plainAfter.At(370, 130), plainAfter.At(130, 270));
6060
Check("A1.rectangle-has-gradient", Near(rectCorners.Item1, Color.FromArgb(255, rectCorners.Item2.R, rectCorners.Item2.G, rectCorners.Item2.B)) > 10, $"interior corners {rectCorners.Item1} vs {rectCorners.Item2}");
61-
var ellipseSides = (plainAfter.At(620, 200), plainAfter.At(780, 200));
62-
var background = plainBefore.At(700, 150);
63-
var alpha = d.Ellipse.Fill.A / 255.0;
64-
var expectedFill = Color.FromArgb(255, (byte)(d.Ellipse.Fill.R * alpha + plainBefore.At(700, 200).R * (1 - alpha)), (byte)(d.Ellipse.Fill.G * alpha + plainBefore.At(700, 200).G * (1 - alpha)), (byte)(d.Ellipse.Fill.B * alpha + plainBefore.At(700, 200).B * (1 - alpha)));
65-
Check("A1.ellipse-has-its-own-solid-fill", !d.Ellipse.Effects.IsGradientFill && Near(plainAfter.At(700, 200), expectedFill) <= 14 && Near(ellipseSides.Item1, Color.FromArgb(255, ellipseSides.Item2.R, ellipseSides.Item2.G, ellipseSides.Item2.B)) <= 14,
66-
$"center {plainAfter.At(700, 200)} expected about {Hex(expectedFill)}; sides {ellipseSides.Item1} vs {ellipseSides.Item2}; picture there {background}");
67-
6861
// Compared with the same picture themed but without shadows, so only the shadows differ.
6962
var shadowless = Store.Save(brand with
7063
{
@@ -78,6 +71,12 @@ private static async Task ExportsAsync()
7871
var noShadow = await ExportAsync(c, false);
7972
c.Undo();
8073
await Task.Delay(500);
74+
var ellipseSides = (plainAfter.At(620, 200), plainAfter.At(780, 200));
75+
var alpha = d.Ellipse.Fill.A / 255.0;
76+
var expectedFill = Color.FromArgb(255, (byte)(d.Ellipse.Fill.R * alpha + plainBefore.At(700, 200).R * (1 - alpha)), (byte)(d.Ellipse.Fill.G * alpha + plainBefore.At(700, 200).G * (1 - alpha)), (byte)(d.Ellipse.Fill.B * alpha + plainBefore.At(700, 200).B * (1 - alpha)));
77+
Check("A1.ellipse-has-its-own-solid-fill", !d.Ellipse.Effects.IsGradientFill && Near(noShadow.At(700, 200), expectedFill) <= 14 && Near(ellipseSides.Item1, Color.FromArgb(255, ellipseSides.Item2.R, ellipseSides.Item2.G, ellipseSides.Item2.B)) <= 14,
78+
$"center without shadow {noShadow.At(700, 200)}, with {plainAfter.At(700, 200)}, expected about {Hex(expectedFill)}; sides {ellipseSides.Item1} vs {ellipseSides.Item2}");
79+
8180
var rectShadow = ShadowExtent(plainAfter, noShadow, 250, 300 + (int)d.Rectangle.StrokeWidth);
8281
var ellipseShadow = ShadowExtent(plainAfter, noShadow, 700, 300 + (int)d.Ellipse.StrokeWidth);
8382
Check("A1.each-shape-has-its-own-shadow", rectShadow > ellipseShadow && ellipseShadow > 0, $"darkened px below: rectangle {rectShadow} (blur {d.Rectangle.Effects.ShadowBlur:F1}), ellipse {ellipseShadow} (blur {d.Ellipse.Effects.ShadowBlur:F1})");

0 commit comments

Comments
 (0)