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

fix: subgrid binding asserting against JS values #51

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public static void ThenTheSubgridContainsARecordWithInTheLookup(string subGridNa
{
var reference = TestDriver.GetTestRecordReference(alias);

// Temporary until XrmApp.Entity.SubGrid.GetSubGridItems(subGridName) returns the correct ID for each item.
var index = (long)Driver.ExecuteScript(
$"return Xrm.Page.getControl(\"{subGridName}\").getGrid().getRows().get().findIndex(row => row.data.entity.attributes.get().findIndex(a => a.getName() === \"{lookup}\" && a.getValue() && a.getValue()[0].id === \"{reference.Id.ToString("B").ToUpper(CultureInfo.CurrentCulture)}\") > -1)");

Expand Down Expand Up @@ -200,33 +201,13 @@ public static void ThenTheSubgridContainsRecordsWithTheFollowingInTheLookup(stri
/// <param name="subGridName">The name of the subgrid.</param>
/// <param name="fieldValue">The expected value of the field.</param>
/// <param name="fieldName">The name of the field.</param>
[Then(@"the '(.*)' subgrid contains a record with '(.*)' in the '(.*)' (?:text|numeric|currency) field")]
[Then(@"the '(.*)' subgrid contains a record with '(.*)' in the '(.*)' (?:text|numeric|currency|lookup|datetime|optionset) field")]
public static void ThenTheSubgridContainsRecordsWithInTheField(string subGridName, string fieldValue, string fieldName)
{
// Bug in GetSubGridItems returns the same attribute values for every record. Using deprecated Xrm.Page for now
// List<GridItem> subGridItems = XrmApp.Entity.SubGrid.GetSubGridItems(subGridName);
// subGridItems.Any(item => item.GetAttribute<string>(fieldName) == fieldValue)
// .Should().BeTrue(because: "a matching record should be present in the subgrid);
var index = (long)Driver.ExecuteScript(
$"return Xrm.Page.getControl(\"{subGridName}\").getGrid().getRows().get().findIndex(row => row.data.entity.attributes.get().findIndex(a => a.getName() === \"{fieldName}\" && a.getValue() == \"{fieldValue}\") > -1)");

index.Should().BeGreaterOrEqualTo(0, because: "a matching record should be present in the subgrid");
}

/// <summary>
/// Asserts that the subgrid contains a record with a lookup matching the criteria.
/// </summary>
/// <param name="subGridName">The name of the subgrid.</param>
/// <param name="fieldValue">The expected value of the field.</param>
/// <param name="fieldName">The name of the field.</param>
[Then(@"the '(.*)' subgrid contains a record with '(.*)' in the '(.*)' lookup field")]
public static void ThenTheSubgridContainsARecordWithInTheLookupField(string subGridName, string fieldValue, string fieldName)
{
// Bug in GetSubGridItems returns the same attribute values for every record. Using deprecated Xrm.Page for now
var index = (long)Driver.ExecuteScript(
$"return Xrm.Page.getControl(\"{subGridName}\").getGrid().getRows().get().findIndex(row => row.data.entity.attributes.get().findIndex(a => a.getName() === \"{fieldName}\" && a.getValue() && a.getValue()[0].name === \"{fieldValue}\") > -1)");

index.Should().BeGreaterOrEqualTo(0, because: "a matching record should be present in the subgrid");
XrmApp.Entity.SubGrid
.GetSubGridItems(subGridName)
.Should()
.Contain(item => item.GetAttribute<string>(fieldName) == fieldValue, because: "a matching record should be present in the subgrid");
}

/// <summary>
Expand Down Expand Up @@ -310,18 +291,7 @@ public static void ThenICanNotSeeTheCommandOnTheFlyoutOfTheSubgrid(string comman
[When(@"I click the '([^']+)' command under the '([^']+)' flyout on the '([^']+)' subgrid")]
public static void WhenIClickTheCommandUnderTheFlyoutOnTheSubgrid(string commandName, string flyoutName, string subGridName)
{
/* Temporary until https://github.com/microsoft/EasyRepro/pull/918 is approved, then it can just be:
XrmApp.Entity.SubGrid.ClickCommand(subGridName, flyoutName, commandName);
*/

WhenIClickTheFlyoutOnTheSubgrid(flyoutName, subGridName);

Driver
.WaitUntilVisible(
By.CssSelector($"div[data-id*=\"flyoutRootNode\"] button[aria-label=\"{commandName}\"]"),
new TimeSpan(0, 0, 1),
$"Could not find the {commandName} command on the flyout of the subgrid.")
.Click(false);
XrmApp.Entity.SubGrid.ClickCommand(subGridName, flyoutName, commandName);
}

/// <summary>
Expand Down