Skip to content

Commit

Permalink
Add fluent slider range test
Browse files Browse the repository at this point in the history
  • Loading branch information
juhangil committed Oct 5, 2024
1 parent 692ddfb commit bc0325b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,8 @@ public async Task Given_ParameterTab_When_Updated_Then_Parameter_Slider_Should_B
// Arrange
var configTab = Page.Locator("div.config-grid")
.Locator("fluent-tabs#config-tabs");

var parameterTab = configTab.Locator("fluent-tab#parameters-tab");
await parameterTab.ClickAsync();
await configTab.Locator("fluent-tab#parameters-tab")
.ClickAsync();

var component = configTab.Locator("fluent-tab-panel#parameters-tab-panel")
.Locator($"div#{id}");
Expand All @@ -406,9 +405,8 @@ public async Task Given_ParameterTab_When_Updated_Then_Parameter_MultiSelect_Sho
// Arrange
var configTab = Page.Locator("div.config-grid")
.Locator("fluent-tabs#config-tabs");

var parameterTab = configTab.Locator("fluent-tab#parameters-tab");
await parameterTab.ClickAsync();
await configTab.Locator("fluent-tab#parameters-tab")
.ClickAsync();

var component = configTab.Locator("fluent-tab-panel#parameters-tab-panel")
.Locator($"div#{id}");
Expand All @@ -422,4 +420,43 @@ public async Task Given_ParameterTab_When_Updated_Then_Parameter_MultiSelect_Sho
labelText.Should().StartWith(label);
await Expect(multiselect).ToBeVisibleAsync();
}
}

[Test]
[TestCase("range-past-messages", 1, 20, 10)]
[TestCase("range-max-response", 1, 16000, 800)]
[TestCase("range-temperature", 0, 1, 0.7)]
[TestCase("range-top-p", 0, 1, 0.95)]
[TestCase("range-frequency-penalty", 0, 2, 0)]
[TestCase("range-presence-penalty", 0, 2, 0)]
public async Task Given_ParameterTab_When_Updated_Then_Parameter_Range_Should_Have_Correct_Range(string id, decimal min, decimal max, decimal start)
{
// Arrange
var configTab = Page.Locator("div.config-grid")
.Locator("fluent-tabs#config-tabs");
await configTab.Locator("fluent-tab#parameters-tab")
.ClickAsync();

var content = configTab.Locator("fluent-tab-panel#parameters-tab-panel")
.Locator($"div#{id}")
.Locator($"div#{id}-content");

// Act
var slider = content.Locator("fluent-slider.parameter-component-slider");
var textfield = content.Locator("fluent-text-field.parameter-component-textfield");

var handle = slider.Locator("div.thumb-cursor");
var bound = await handle.BoundingBoxAsync();

// Assert
(await slider.GetAttributeAsync("current-value")).Should().Be(start.ToString());
(await textfield.GetAttributeAsync("current-value")).Should().Be(start.ToString());

await Page.Mouse.DragToPoint(handle, 0, bound!.Y);
(await slider.GetAttributeAsync("current-value")).Should().Be(min.ToString());
(await textfield.GetAttributeAsync("current-value")).Should().Be(min.ToString());

await Page.Mouse.DragToPoint(handle, float.MaxValue, bound!.Y);
(await slider.GetAttributeAsync("current-value")).Should().Be(max.ToString());
(await textfield.GetAttributeAsync("current-value")).Should().Be(max.ToString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.Playwright;

namespace AzureOpenAIProxy.PlaygroundApp.Tests.Pages;

internal static class PlaywrightPageExtensions
{
public static async Task DragToPoint(this IMouse mouse, ILocator source, float x, float y)
{
await source.HoverAsync();
await mouse.DownAsync();
await mouse.MoveAsync(x, y);
await mouse.UpAsync();
}
}

0 comments on commit bc0325b

Please sign in to comment.