Skip to content

Commit

Permalink
Merge branch 'slicelayoutengine-fixes' into 1032-workspaces-yaml-config
Browse files Browse the repository at this point in the history
  • Loading branch information
dalyIsaac committed Sep 27, 2024
2 parents 759cbaa + 7c9320d commit badd745
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
27 changes: 24 additions & 3 deletions src/Whim.SliceLayout.Tests/SliceLayoutEngine/AreaTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using FluentAssertions;
using NSubstitute;
using Whim.TestUtils;
using Xunit;

namespace Whim.SliceLayout.Tests;
Expand All @@ -18,6 +15,30 @@ public void ParentArea_Equals()
Assert.Equal(area1, area2);
}

public static TheoryData<ParentArea, ParentArea> ParentArea_NotEqual =>
new()
{
{
new(isRow: true, (1, new OverflowArea(isRow: true))),
new(isRow: false, (1, new OverflowArea(isRow: true)))
},
{
new(isRow: true, (1, new OverflowArea(isRow: true))),
new(isRow: true, (1, new OverflowArea(isRow: false)))
},
{
new(isRow: true, (1, new OverflowArea(isRow: true))),
new(isRow: true, (1, new OverflowArea(isRow: true)), (1, new OverflowArea(isRow: true)))
},
};

[Theory, MemberData(nameof(ParentArea_NotEqual))]
public void ParentArea_Equals_NotEqual(ParentArea area1, ParentArea area2)
{
// Then
Assert.NotEqual(area1, area2);
}

[Fact]
public void ParentArea_GetHashCode()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,27 @@ public void Equals_Same(IContext ctx, SliceLayoutPlugin plugin)
Assert.True(equals);
}

[Theory, AutoSubstituteData]
public void Equals_DifferentType(IContext ctx, SliceLayoutPlugin plugin)
{
// Given
ILayoutEngine a = new SliceLayoutEngine(ctx, plugin, identity, SampleSliceLayouts.CreateNestedLayout());
ILayoutEngine b = SliceLayouts.CreateColumnLayout(ctx, plugin, identity);

// When
bool equals = a.Equals(b);

// Then
Assert.False(equals);
}

[Theory, AutoSubstituteData]
public void SliceLayoutEngine_GetHashCode(IContext ctx, SliceLayoutPlugin plugin)
{
// Given
ILayoutEngine sut = new SliceLayoutEngine(ctx, plugin, identity, SampleSliceLayouts.CreateNestedLayout());
sut = sut.AddWindow(Substitute.For<IWindow>());
sut = sut.MinimizeWindowStart(Substitute.For<IWindow>());

// When
int hashCode = sut.GetHashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal void WindowMessageMonitor_DpiChanged(IContext ctx, IInternalContext int
internal async Task WindowMessageMonitor_SessionChanged(IContext ctx, IInternalContext internalCtx)
{
// Given the listener is initialized
MonitorEventListener listener = new(ctx, internalCtx);
MonitorEventListener listener = new(ctx, internalCtx, 500);
listener.Initialize();

NativeManagerUtils.SetupTryEnqueue(ctx);
Expand All @@ -108,7 +108,7 @@ internal async Task WindowMessageMonitor_SessionChanged(IContext ctx, IInternalC
ctx.Store.MonitorEvents,
_windowMessageArgs
);
await Task.Delay(5200);
await Task.Delay(2000);

// Then a dispatch to the store was triggered
ctx.Store.Received(1).Dispatch(new MonitorsChangedTransform());
Expand Down
5 changes: 3 additions & 2 deletions src/Whim/Store/MonitorSector/MonitorEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Whim;

internal class MonitorEventListener(IContext ctx, IInternalContext internalCtx) : IDisposable
internal class MonitorEventListener(IContext ctx, IInternalContext internalCtx, int delayMs = 5000) : IDisposable
{
private readonly IContext _ctx = ctx;
private readonly IInternalContext _internalCtx = internalCtx;
private readonly int _delayMs = delayMs;
private bool _disposedValue;

public void Initialize()
Expand All @@ -29,7 +30,7 @@ private void WindowMessageMonitor_SessionChanged(object? sender, WindowMessageMo
// This gives Windows some to figure out the correct working area.
_ctx.NativeManager.TryEnqueue(async () =>
{
await Task.Delay(5000).ConfigureAwait(true);
await Task.Delay(_delayMs).ConfigureAwait(true);
WindowMessageMonitor_MonitorsChanged(sender, e);
});
}
Expand Down

0 comments on commit badd745

Please sign in to comment.