Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ No abbreviations in names.
- Every colour this tree's AXAML paints resolves to a key in `SemiPlot.UI/Styles/Palette.axaml`; a
literal in AXAML is a defect. Semi's own surfaces outside that key set keep Semi's variant-aware
stock brushes (`docs/architecture/ui-theme.md`).
- Every `Margin`, `Padding` and `*Spacing` value in AXAML is on the 4/8/12/16/24/32 scale; a text button
takes Semi's padding (`docs/architecture/ui-theme.md#an-off-scale-inset-in-axaml-is-a-defect`).
- A form never resizes on validation: fixed width, an `invalid` border class, one reserved message line
(`docs/architecture/ui-theme.md#a-form-never-resizes-on-validation`).
- The left-button gesture is one state, never overlapping branches: a `Chart/LeftButtonTool`
Expand Down
23 changes: 23 additions & 0 deletions SemiPlot/SemiPlot.Tests.Unit/UI/Chart/AxisScalePanelLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,29 @@ public void TheLogarithmicBox_StartsAtTheFieldEdge_UnderTheScaleTypeLabel(string
box.Content.Should().Be(Resources.PenFormLogarithmic);
}

[AvaloniaFact]
public void TheForm_TakesItsGapsFromTheSpacingScale()
{
using var viewModel = CreateLoadedViewModel();
using var shown = ShowChart(viewModel);
var (_, panel) = OpenPanel(viewModel, shown);
var bounds = panel.FindControl<Grid>("AxisScaleBounds")!;
var row = panel.FindControl<Grid>("AxisScaleType")!;
var header = (Control)panel.FindControl<TextBlock>("AxisScalePenName")!.Parent!;
var maximum = panel.FindControl<TextBox>("AxisScaleMaximum")!;
var maximumLabel = bounds.Children.OfType<TextBlock>().First();

(ViewProbe.LeftOf(maximum, bounds) - ViewProbe.RightOf(maximumLabel, bounds))
.Should().Be(12, "label to field");
(ViewProbe.LeftOf(panel.FindControl<CheckBox>("AxisScaleLogarithmic")!, row)
- ViewProbe.RightOf(panel.FindControl<TextBlock>("AxisScaleTypeLabel")!, row))
.Should().Be(12, "label to field");
(ViewProbe.TopOf(panel.FindControl<TextBox>("AxisScaleMinimum")!, panel) - ViewProbe.BottomOf(maximum, panel))
.Should().Be(8, "the row spacing");
(ViewProbe.TopOf(row, panel) - ViewProbe.BottomOf(bounds, panel)).Should().Be(8, "the row spacing");
(ViewProbe.TopOf(bounds, panel) - ViewProbe.BottomOf(header, panel)).Should().Be(8, "the row spacing");
}

[AvaloniaFact]
public void AClickOnTheScaleTypeLabelOrBesideTheBox_LeavesTheFlagAndGivesThePanelTheKeyboard()
{
Expand Down
25 changes: 25 additions & 0 deletions SemiPlot/SemiPlot.Tests.Unit/UI/Chart/ChartMarkerViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,31 @@ public void RenameOnAMarker_WithANewLabelAndOk_RelabelsIt()
LabelEditor.IsOpen.Should().BeFalse();
}

[AvaloniaFact]
public void TheLabelEditorButtons_TakeTheThemesPaddingAndHeight()
{
var marker = new StoredMarker(1, MomentAt(0.25), "Etch start");
_channel.Push(marker);
OpenLabelEditorToRename(marker);

foreach (var name in new[] { "MarkerLabelOk", "MarkerLabelCancel" })
{
ViewProbe.ShouldTakeTheThemesButtonInsets(LabelEditorButton(name), name);
}
}

[AvaloniaFact]
public void TheLabelEditor_StandsItsButtonsEightPixelsUnderTheBox()
{
var marker = new StoredMarker(1, MomentAt(0.25), "Etch start");
_channel.Push(marker);
OpenLabelEditorToRename(marker);
var editor = (Control)LabelEditor.Content!;

(ViewProbe.TopOf(LabelEditorButton("MarkerLabelOk"), editor) - ViewProbe.BottomOf(LabelBox, editor))
.Should().Be(8, "the row spacing");
}

[AvaloniaFact]
public void RenameOnAMarker_ThenCancel_KeepsTheOldLabel()
{
Expand Down
14 changes: 14 additions & 0 deletions SemiPlot/SemiPlot.Tests.Unit/UI/Chart/TimeWindowPanelViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,20 @@ public void TheMessageLine_KeepsThePanelsSize_EmptyAndWithTheLongestRule(string
skippedSizes.Should().Be(emptySizes);
}

[AvaloniaFact]
public void TheGrid_TakesItsGapsFromTheSpacingScale()
{
using var stand = PanelStand.Create();
stand.Open();
var startTime = stand.Panel.FindControl<TextBox>("TimeWindowStartTime")!;
var endTime = stand.Panel.FindControl<TextBox>("TimeWindowEndTime")!;

(ViewProbe.LeftOf(stand.Picker("TimeWindowStartDate"), stand.Panel) - ViewProbe.RightOf(startTime, stand.Panel))
.Should().Be(12, "field to field in one row");
(ViewProbe.TopOf(endTime, stand.Panel) - ViewProbe.BottomOf(startTime, stand.Panel))
.Should().Be(8, "the row spacing");
}

private static CalendarDayButton DayButton(CalendarDatePicker picker, DateTime day)
{
var popup = ViewProbe.Descendant<Popup>(picker, "PART_Popup");
Expand Down
63 changes: 53 additions & 10 deletions SemiPlot/SemiPlot.Tests.Unit/UI/Export/CsvExportWindowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ public void TheWindow_KeepsItsSizeAndItsButtonsWhenAFieldTurnsInvalid()
}
}

[AvaloniaFact]
public void TheButtons_TakeTheThemesPaddingAndHeight()
{
using var viewModel = Build();
var window = Realise(new CsvExportWindow { DataContext = viewModel });
try
{
foreach (var name in new[] { "ExportSaveAs", "ExportCancel", "ExportClose" })
{
ShouldTakeTheThemesButtonInsets(Named<Button>(window, name), name);
}
}
finally
{
Dismiss(window);
}
}

[AvaloniaFact]
public void TheInvalidControls_CarryTheInvalidClass_AndTheOthersDoNot()
{
Expand Down Expand Up @@ -642,7 +660,7 @@ public void ThePenList_MaxHeight_ShowsExactlyEightRowsOf28Pixels()
}

[AvaloniaFact]
public void ThePenCheckboxes_StandAtLeastSixPixelsOffTheListBorder()
public void ThePenCheckboxes_StandEightPixelsOffTheListBorder()
{
using var viewModel = BuildWithPens(12);
var window = Realise(new CsvExportWindow { DataContext = viewModel });
Expand All @@ -653,7 +671,33 @@ public void ThePenCheckboxes_StandAtLeastSixPixelsOffTheListBorder()
var innerLeft = list.BorderThickness.Left;
var boxLeft = box.TranslatePoint(new Point(0, 0), list)!.Value.X;

(boxLeft - innerLeft).Should().BeGreaterThanOrEqualTo(6);
(boxLeft - innerLeft).Should().Be(8);
}
finally
{
Dismiss(window);
}
}

[AvaloniaFact]
public void TheForm_TakesItsGapsFromTheSpacingScale()
{
using var cultureScope = new CultureScope("en");
using var viewModel = BuildWithMarkers();
var window = Realise(new CsvExportWindow { DataContext = viewModel });
try
{
var startLabel = window.GetVisualDescendants().OfType<TextBlock>()
.Single(block => block.Text == Resources.ExportStartLabel);
var header = Named<TextBlock>(window, "ExportPensHeader");
var list = Named<Border>(window, "ExportPens");

(LeftOf(window, Named<CalendarDatePicker>(window, "ExportStartDate")) - RightOf(window, startLabel))
.Should().Be(12, "label to field");
(TopOf(window, header) - BottomOf(window, Named<ComboBox>(window, "ExportEndMarker")))
.Should().Be(16, "a section header stands 16 under the row above");
(TopOf(window, list) - BottomOf(window, header)).Should().Be(8, "and 8 over its first row");
LeftOf(window, list).Should().Be(16, "the window margin");
}
finally
{
Expand Down Expand Up @@ -789,7 +833,7 @@ public void EachEdge_PutsTheDateOverTheTimeAndTheMarkerBox_AndTheTabOrderFollows
timeBox.Bounds.Width.Should().Be(110, time);
(LeftOf(window, markerBox) - RightOf(window, timeBox)).Should().Be(8, marker);
RightOf(window, markerBox).Should().Be(RightOf(window, datePicker), marker);
(TopOf(window, timeBox) - BottomOf(window, datePicker)).Should().Be(10, "the second line is 10 px under");
(TopOf(window, timeBox) - BottomOf(window, datePicker)).Should().Be(8, "the second line is 8 px under");
TopOf(window, markerBox).Should().Be(TopOf(window, timeBox), "one line holds both");
CentreOf(window, labelBlock).Should().Be(CentreOf(window, datePicker), "the label is centred on the date");
new Control[] { datePicker, timeBox, markerBox }
Expand All @@ -798,7 +842,7 @@ public void EachEdge_PutsTheDateOverTheTimeAndTheMarkerBox_AndTheTabOrderFollows

(TopOf(window, Named<CalendarDatePicker>(window, "ExportEndDate"))
- BottomOf(window, Named<ComboBox>(window, "ExportStartMarker")))
.Should().Be(20, "the edges stand 20 px apart");
.Should().Be(16, "the edges stand 16 px apart");

string[] edgeControls =
[
Expand Down Expand Up @@ -833,8 +877,8 @@ public void TheDatesTheMarkerBoxesTheListAndTheMessage_EndAtOneRightEdge(string
RightOf(window, Named<ComboBox>(window, "ExportEndMarker")).Should().Be(edge);
RightOf(window, Named<Border>(window, "ExportPens")).Should().Be(edge);
RightOf(window, Named<TextBlock>(window, "ExportMessage")).Should().Be(edge);
edge.Should().Be(370);
window.Width.Should().Be(edge + 20, "the margin is the only space right of the form");
edge.Should().Be(374);
window.Width.Should().Be(edge + 16, "the margin is the only space right of the form");
}
finally
{
Expand Down Expand Up @@ -1382,23 +1426,22 @@ public void UnderRussian_TheWidestDateInInter_FitsTheStartPickersTextViewportOnT
{
// The headless shaper advances every glyph by the font size, so the texts are measured in Inter through
// Skia and the realised layout is corrected by the label column's real width.
const double FormWidth = 350;
const double FormColumnSpacing = 14;
const double CaretAndRoundingAllowance = 2;
using var cultureScope = new CultureScope("ru");
using var viewModel = BuildWithMarkers();
var window = Realise(new CsvExportWindow { DataContext = viewModel });
try
{
var picker = Named<CalendarDatePicker>(window, "ExportStartDate");
var form = (Grid)picker.Parent!;
var box = TextOf(picker);
var label = window.GetVisualDescendants().OfType<TextBlock>()
.Single(block => block.Text == Resources.ExportStartLabel);
using var typeface = InterTypeface();
using var labelFont = InterFont(typeface, label.FontSize);
using var dateFont = InterFont(typeface, box.FontSize);

var headlessLabelColumn = LeftOf(window, picker) - LeftOf(window, label) - FormColumnSpacing;
var headlessLabelColumn = LeftOf(window, picker) - LeftOf(window, label) - form.ColumnSpacing;
var standLabelColumn = Math.Ceiling(Math.Max(
labelFont.MeasureText(Resources.ExportStartLabel), labelFont.MeasureText(Resources.ExportEndLabel)));
var labelCorrection = headlessLabelColumn - standLabelColumn;
Expand All @@ -1407,7 +1450,7 @@ public void UnderRussian_TheWidestDateInInter_FitsTheStartPickersTextViewportOnT

box.Text.Should().Be("13.10.2026");
standDateCell.Should().BeApproximately(
FormWidth - FormColumnSpacing - standLabelColumn, 1, "the date takes the whole field column");
form.Bounds.Width - form.ColumnSpacing - standLabelColumn, 1, "the date takes the whole field column");
standViewport.Should().BeGreaterThanOrEqualTo(
WidestDateWidth(dateFont, Resources.ExportDateFormat) + CaretAndRoundingAllowance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public void TheTopRow_ShowsTextFromTheThresholdUpAndIconsBelowIt(double width, b
LabelOf(button).IsEffectivelyVisible.Should().Be(showsText, "'{0}' at {1} px", button.Name, width);
IconOf(button).IsEffectivelyVisible.Should().Be(!showsText, "'{0}' at {1} px", button.Name, width);
button.Bounds.Height.Should().Be(showsText ? 24 : 20, "'{0}' at {1} px", button.Name, width);
button.Padding.Should().Be(
showsText ? new Thickness(8, 0) : new Thickness(0), "'{0}' at {1} px", button.Name, width);
}

if (!showsText)
Expand Down
39 changes: 39 additions & 0 deletions SemiPlot/SemiPlot.Tests.Unit/UI/Legend/TrendLegendViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,45 @@ public void ARowUnderAHeader_StartsItsBoxWhereTheCaptionStarts()
LeftOf(rowBox, window).Should().Be(LeftOf(header, window));
}

[AvaloniaFact]
public void ARow_TakesItsInsetsFromTheSpacingScale()
{
var chart = CreateChart();
chart.AddPen(new Pen(1, "Chamber pressure", ["Pressures"], "#ff0000", "kPa", "0.000"));
using var legend = new TrendLegendViewModel(chart, [new StoredGroup(1, "Pressures", [1])]);
ChartTestBuilder.LoadInitialHistory(chart, _scheduler, ChartTestBuilder.From, ChartTestBuilder.To);
var window = Realize(legend);
var row = SingleRow(window);
var content = Descendant<Grid>(row, "RowContent");
var header = Descendant<Grid>(window, "GroupHeaderRow");
TestContext.Current.TestOutputHelper?.WriteLine($"legend row height {row.Bounds.Height} px (headless)");

TopOf(content, row).Should().Be(4, "an inset inside a control");
(row.Bounds.Height - BottomOf(content, row)).Should().Be(4, "an inset inside a control");
LeftOf(content, row).Should().Be(24, "a row under a drawn header keeps its 24 px indent");
(LeftOf(Descendant<TextBlock>(row, "RowName"), row) - RightOf(Descendant<Border>(row, "RowColor"), row))
.Should().Be(8, "the gap between controls in one row");
(LeftOf(Descendant<TextBlock>(row, "RowValue"), row) - RightOf(Descendant<TextBlock>(row, "RowName"), row))
.Should().Be(8, "the gap between controls in one row");
(TopOf(row, window) - BottomOf(header, window)).Should().Be(4, "the header row's bottom inset");
(row.Bounds.Height % 4).Should().Be(0, "the row height {0} px sits on the 4 px grid", row.Bounds.Height);
}

[AvaloniaFact]
public void AnUngroupedRow_TakesItsInsetsFromTheSpacingScale()
{
var chart = CreateChart();
chart.AddPen(new Pen(1, "Chamber pressure", [], "#ff0000", "kPa", "0.000"));
using var legend = new TrendLegendViewModel(chart, []);
var window = Realize(legend);
var row = SingleRow(window);
var content = Descendant<Grid>(row, "RowContent");

TopOf(content, row).Should().Be(4, "an inset inside a control");
(row.Bounds.Height - BottomOf(content, row)).Should().Be(4, "an inset inside a control");
LeftOf(content, row).Should().Be(4, "a row with no drawn header takes no indent");
}

[AvaloniaTheory]
[InlineData(AppThemeVariant.Light)]
[InlineData(AppThemeVariant.Dark)]
Expand Down
16 changes: 16 additions & 0 deletions SemiPlot/SemiPlot.Tests.Unit/UI/MainWindow/AboutInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ public void AboutDialog_ShowsTheNameTheVersionAndTheConfigurationDirectory()
}
}

[AvaloniaFact]
public void TheCloseButton_TakesTheThemesPaddingAndHeight()
{
var about = new AboutInfo("SemiPlot", "1.2.3", @"C:\semiplot\config");
var dialog = ViewProbe.Realise(new AboutDialog { DataContext = about });
try
{
ViewProbe.ShouldTakeTheThemesButtonInsets(
ViewProbe.Named<Button>(dialog, "AboutClose"), "the Close button is a text button");
}
finally
{
dialog.Close();
}
}

[Fact]
public void AboutInfo_NamesTheConfigurationDirectoryTheRunRead()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Xunit;

using static SemiPlot.Tests.Unit.UI.MainWindow.MainWindowTestBuilder;
using static SemiPlot.Tests.Unit.UI.ViewProbe;

namespace SemiPlot.Tests.Unit.UI.MainWindow;

Expand Down Expand Up @@ -121,6 +122,33 @@ public void ActiveLayerText_FollowsTheChartsLayerOnTheRealisedBar()
layerText.Text.Should().Be(Resources.FormatStatusLayerFormat(Resources.StatusLayerHour));
}

[AvaloniaFact]
public void TheSeparatorAndTheIndicator_TakeTheirInsetsFromTheSpacingScale()
{
using var panel = new MessagePanelViewModel();
using var states = new Subject<ArchiveConnectionState>();
using var statusBar = NewStatusBar(panel, states);
var view = new AppStatusBar { DataContext = statusBar };
var window = Realise(new Window { Content = view, SizeToContent = SizeToContent.Height });
try
{
var bar = (Grid)view.Content!;
var separator = bar.Children.OfType<Border>().Single();
var indicator = Named<Button>(view, "ConnectionIndicator");
var layerText = Named<TextBlock>(view, "ActiveLayerText");

TopOf(separator, bar).Should().Be(4, "an inset inside the bar");
(bar.Bounds.Height - BottomOf(separator, bar)).Should().Be(4, "an inset inside the bar");
(LeftOf(separator, bar) - RightOf(indicator, bar)).Should().Be(8, "the gap between controls in one row");
(LeftOf(layerText, bar) - RightOf(separator, bar)).Should().Be(8, "the gap between controls in one row");
ShouldTakeTheThemesButtonInsets(indicator, "the indicator is a text button");
}
finally
{
Dismiss(window);
}
}

private static Color ColourOf(IBrush? brush)
{
return brush.Should().BeAssignableTo<ISolidColorBrush>().Subject.Color;
Expand Down
Loading
Loading