Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-916: Change "shift time" terminology to "time shift" in Lombiq.UITestingToolbox #425

Merged
merged 8 commits into from
Nov 21, 2024
6 changes: 3 additions & 3 deletions Lombiq.Tests.UI.Samples/Tests/ShiftTimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
namespace Lombiq.Tests.UI.Samples.Tests;

// When you enable the "Shift Time - Shortcuts - Lombiq UI Testing Toolbox" feature, it replaces Orchard Core's stock
// ICLock implementation with the custom ShiftTimeClock class. You can use the
// ~/Lombiq.Tests.UI.Samples/ShiftTime/Set?days=... action to update the ShiftTimeClock.Shift property for the current
// ICLock implementation with the custom TimeShifterClock class. You can use the
// ~/Lombiq.Tests.UI.Samples/TimeShift/Set?days=... action to update the TimeShifterClock.Shift property for the current
// tenant, which will trick any service that uses IClock into thinking you are in the future. This can be used to test
// features that can expire, such as a limited-time product discount in a web store, without having to wait.
public class ShiftTimeTests : UITestBase
Expand Down Expand Up @@ -46,7 +46,7 @@ await context.FillInCodeMirrorEditorWithRetriesAsync(
// This extension method navigates to the action which sets the time offset. You can set it in terms of
// days or seconds. Both accept fractions and negative values. If both days and seconds are set, they
// are added together.
await context.SetShiftTimeAsync(days: 10);
await context.SetShiftTimeAsync(TimeSpan.FromDays(10));

// Let's verify the date!
var tenDaysFromNow = await GetNowAsync(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
namespace Lombiq.Tests.UI.Shortcuts.Controllers;

[DevelopmentAndLocalhostOnly]
public class ShiftTimeController : Controller
public class TimeShiftController : Controller
{
private readonly IClock _clock;

public ShiftTimeController(IClock clock) => _clock = clock;
public TimeShiftController(IClock clock) => _clock = clock;

public IActionResult Set(double days, double seconds) =>
SetInner(_ => TimeSpan.FromDays(days) + TimeSpan.FromSeconds(seconds));
Expand All @@ -20,7 +20,7 @@ public IActionResult Add(double days, double seconds) =>
SetInner(current => current + TimeSpan.FromDays(days) + TimeSpan.FromSeconds(seconds));

private IActionResult SetInner(Func<TimeSpan, TimeSpan> edit) =>
ShiftTimeClock.UpdateClock(_clock, edit) is { } totalSeconds
TimeShifterClock.UpdateClock(_clock, edit) is { } totalSeconds
? Ok(totalSeconds)
: BadRequest($"The clock is {_clock.GetType().FullName} instead of {nameof(ShiftTimeClock)}.");
: BadRequest($"The clock is {_clock.GetType().FullName} instead of {nameof(TimeShifterClock)}.");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Search for "shifttime", there are other remaining cases too.

Copy link
Member Author

@sarahelsaig sarahelsaig Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a leftover variable name in TimeShiftingClock.UpdateClock. I've updated that. The ShiftTimeTests class name should stay as-is, because it's {feature name}Tests. I did not see anything beyond those two cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about SetShiftTimeAsync and AddShiftTimeAsync? Both of these should use "time shift" IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wat? I've already explained that here and you said it's okay.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you were referring to the TimeSpan change there. But otherwise still, no, that's setting the time shifting value, i.e. time shift.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Lombiq.Tests.UI.Shortcuts.Services;
/// cref="IClock"/> into believing it's the future or past. This service is registered as singleton, so setting <see
/// cref="Shift"/> will persist in the tenant across requests.
/// </summary>
public class ShiftTimeClock : IClock
public class TimeShifterClock : IClock
Piedone marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly Clock _inner = new();

Expand All @@ -34,16 +34,16 @@ public DateTimeOffset ConvertToTimeZone(DateTimeOffset dateTimeOffset, ITimeZone
/// Use this to safely update the <see cref="Shift"/> value.
/// </summary>
/// <param name="clock">
/// The injected service, if it's <see cref="ShiftTimeClock"/> then its <see cref="Shift"/> property is updated.
/// The injected service, if it's <see cref="TimeShifterClock"/> then its <see cref="Shift"/> property is updated.
/// </param>
/// <param name="edit">Input is the current value of <see cref="Shift"/>, output is the new value.</param>
/// <returns>
/// The total seconds of the new value of <see cref="Shift"/>, or <see langword="null"/> if <paramref name="clock"/>
/// is not <see cref="ShiftTimeClock"/>.
/// is not <see cref="TimeShifterClock"/>.
/// </returns>
public static double? UpdateClock(IClock clock, Func<TimeSpan, TimeSpan> edit)
{
if (clock is not ShiftTimeClock shiftTimeClock) return null;
if (clock is not TimeShifterClock shiftTimeClock) return null;

shiftTimeClock.Shift = edit(shiftTimeClock.Shift);
return shiftTimeClock.Shift.TotalSeconds;
Expand Down
10 changes: 5 additions & 5 deletions Lombiq.Tests.UI.Shortcuts/ShortcutsFeatureIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public static class ShortcutsFeatureIds
public const string Area = "Lombiq.Tests.UI.Shortcuts";

public const string Default = Area;
public const string FeatureToggleTestBench = Default + ".FeatureToggleTestBench";
public const string MediaCachePurge = Default + ".MediaCachePurge";
public const string ShiftTime = Default + ".ShiftTime";
public const string Swagger = Default + ".Swagger";
public const string Workflows = Default + ".Workflows";
public const string FeatureToggleTestBench = $"{Default}.{nameof(FeatureToggleTestBench)}";
public const string MediaCachePurge = $"{Default}.{nameof(MediaCachePurge)}";
public const string ShiftTime = $"{Default}.{nameof(ShiftTime)}";
Piedone marked this conversation as resolved.
Show resolved Hide resolved
public const string Swagger = $"{Default}.{nameof(Swagger)}";
public const string Workflows = $"{Default}.{nameof(Workflows)}";
}
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI.Shortcuts/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public sealed class SetTimeStartup : StartupBase
public override void ConfigureServices(IServiceCollection services)
{
services.RemoveImplementationsOf<IClock>();
services.AddSingleton<IClock, ShiftTimeClock>();
services.AddSingleton<IClock, TimeShifterClock>();
}
}
18 changes: 10 additions & 8 deletions Lombiq.Tests.UI/Extensions/ShortcutsUITestContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -744,23 +744,25 @@ public static Task ExecuteJsonRecipeSiteSettingAsync<T>(this UITestContext conte
public static Task EnableTimeShiftingAsync(this UITestContext context) => context.EnableFeatureDirectlyAsync(ShiftTime);

/// <summary>
/// Sets the time shift to a specific value. If both <paramref name="days"/> and <paramref name="seconds"/> are
/// provided, then the <see cref="TimeSpan"/> values are added together.
/// Sets the time shift to a specific value.
/// </summary>
public static Task SetShiftTimeAsync(this UITestContext context, double days = 0, double seconds = 0)
public static Task SetShiftTimeAsync(this UITestContext context, TimeSpan time)
Piedone marked this conversation as resolved.
Show resolved Hide resolved
{
context.EnsureValidOrchardCoreTenantScope();
return context.GoToAsync<ShiftTimeController>(controller => controller.Set(days, seconds));
return time.TotalDays >= 1.0
? context.GoToAsync<TimeShiftController>(controller => controller.Set(time.TotalDays, 0))
: context.GoToAsync<TimeShiftController>(controller => controller.Set(0, time.TotalSeconds));
Piedone marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
/// Adds the specified value to the time shift. If both <paramref name="days"/> and <paramref name="seconds"/> are
/// provided, then the <see cref="TimeSpan"/> values for both are added. Negative values are supported as well.
/// Adds the specified value to the time shift.
/// </summary>
public static Task AddShiftTimeAsync(this UITestContext context, double days = 0, double seconds = 0)
public static Task AddShiftTimeAsync(this UITestContext context, TimeSpan time)
{
context.EnsureValidOrchardCoreTenantScope();
return context.GoToAsync<ShiftTimeController>(controller => controller.Add(days, seconds));
return time.TotalDays >= 1.0
? context.GoToAsync<TimeShiftController>(controller => controller.Add(time.TotalDays, 0))
: context.GoToAsync<TimeShiftController>(controller => controller.Add(0, time.TotalSeconds));
}

/// <summary>
Expand Down
Loading