Skip to content

Conversation

@Rosuavio
Copy link
Contributor

@Rosuavio Rosuavio commented Sep 30, 2020

Add UI tests for TextBox with a TextBoxMask.Mask and x:Bind
Uses WinUI Test Infrasttcure from #3482 to test the fix from #3338 for #3335.

PR Type

What kind of change does this PR introduce?

  • Feature
  • Build or CI related changes

What is the current behavior?

No UI Tests for TextBoxMask

What is the new behavior?

Given a TextBox with a Mask set and its Text bound to a C# property using x:Bind. It tests if the text in the TextBox updates when that property is updated.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • [ ] Pull Request has been submitted to the documentation repository instructions. Link:
  • ~~[ ] Sample in sample app has been added / updated (for bug fixes / features) ~~
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

Does not test #3514

@ghost
Copy link

ghost commented Sep 30, 2020

Thanks RosarioPulella for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@ghost ghost requested review from Kyaa-dost, azchohfi and michael-hawker September 30, 2020 19:48
@net-foundation-cla
Copy link

net-foundation-cla bot commented Sep 30, 2020

CLA assistant check
All CLA requirements met.

@net-foundation-cla
Copy link

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

❌ RosarioPulella sign now
You have signed the CLA already but the status is still pending? Let us recheck it.

@Rosuavio Rosuavio changed the title Test TextBoxMask Test TextBox with a TextBoxMask.Mask and x:Bind Oct 1, 2020
@Rosuavio Rosuavio marked this pull request as ready for review October 1, 2020 19:34
@michael-hawker michael-hawker added this to the 7.0 milestone Oct 6, 2020
@michael-hawker michael-hawker mentioned this pull request Oct 15, 2020
7 tasks
@michael-hawker michael-hawker changed the base branch from master to muxtestinfra October 15, 2020 17:09
@michael-hawker
Copy link
Member

Changed the base of this PR to the other branch for now so it's easier to review/comment on until that one gets merged, then we can switch back.

Copy link
Member

@michael-hawker michael-hawker left a comment

Choose a reason for hiding this comment

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

Just want to make sure we use this PR to set ourselves up for adding more tests as we move forward from here! 🙂

<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="Pages\SimpleTest.xaml.cs">
Copy link
Member

Choose a reason for hiding this comment

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

@azchohfi can we use the SDK Extras to switch to the new-style project here? Don't want to get into merge problems in the future with multiple-tests being written.

Otherwise we can try using the glob syntax instead?

<TextBlock x:Name="textBlock"/>
<Frame x:Name="navigationFrame" />

<StackPanel Orientation="Horizontal" Grid.Row="1" >
Copy link
Member

Choose a reason for hiding this comment

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

However, I don't like the use of the buttons here to control the page navigation, we should build this into the infrastructure itself. So the MainPage has a function of understanding how to switch tasks and can evaluate a string and navigate to that page based on reflection or something, similar to how we navigate within the SampleApp currently:

https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/49760c325ecbddab254b61214e5a808e866e51d6/Microsoft.Toolkit.Uwp.SampleApp/Models/Sample.cs#L100

}

[TestMethod]
public void TestTextBoxMaskBinding_Property()
Copy link
Member

Choose a reason for hiding this comment

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

I definitely want to figure out how we split these into multiple files as well, so we can have multiple test cases per test page. i.e. we can have a test page using the component with a setup or two, and then have multiple smaller test methods to run against it.

Though ideally, we figure out how to manage this without tearing down and re-opening the app each time?

@azchohfi as commented on the other PR, do you know how we'd structure this here or have suggestions?

Verify.AreEqual(newValue, textBox.GetText());
}

private static void OpenTest(string name)
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, so this method should be integrated into the test-harness itself and know how to communicate with the MainPage in order to switch the page in the frame. We don't want to have to rely on adding more custom buttons and things to the main test page in order to do this.

As mentioned in the other PR I think the use of a custom Attribute could be handy if we could make that work. i.e.

    [TestMethod]
    [TestXamlFile("TextBoxMaskTestPage")]
    public void TestTextBoxMaskBinding_Property()
    {

The test harness before each test would read the attribute on it to grab the type name of the page to load, then we'd have to send the test app a message to load that page, and then execute the test.

Not sure if we would need an intermediary UI piece, use the clipboard, or go as heavy as an AppService to do this. Looks like in WinUI they just manipulate the UI similar to how you did it here, just more generally with a command: https://github.com/microsoft/microsoft-ui-xaml/blob/master/test/TestAppUtils/NavigateToTestCommand.cs#L12

And they use their TestSetupHelper to manually control the page at the start of each test: https://github.com/microsoft/microsoft-ui-xaml/blob/master/dev/TabView/InteractionTests/TabViewTests.cs#L49

@azchohfi thoughts? Should we just copy the setup WinUI has or should we try and improve upon this somehow with an attribute on the test method itself to control this?

I'm guessing it is easier if the idea is to better introp to WinUI that we more closely follow their patterns? @ranjeshj any preferences on if we experiment or try to more closely align? Has the current WinUI system been working well or have you been looking to changing it in the future?

Copy link
Member

Choose a reason for hiding this comment

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

I guess I left out that part of why I want to try and simplify these connections is to make it as straight-forward and easy for developers to add integration tests so that we can ensure adding them isn't a big burden to our community.

I think if we could introduce a new attribute based system here, it'd give developers the flexibility to re-use a page easily or setup multiple pages for different scenarios, eh?

It also makes each test easier to maintain and understand as all the test harness initialization is abstracted to the attribute.

Copy link
Member

Choose a reason for hiding this comment

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

Basically we'd set something up like this to grab the attribute for the base of our test system:

public TestContext TestContext { get; set; }

[TestInitialize]
public void TestInitialize()
{
    Debug.WriteLine("Running Test: " + TestContext.TestName);

    var currentlyRunningMethod = GetType().GetMethod(TestContext.TestName);
    var descriptionAttributes = currentlyRunningMethod.GetCustomAttributes(typeof(DescriptionAttribute), true) as System.Collections.Generic.IEnumerable<DescriptionAttribute>;
    var firstOne = descriptionAttributes.FirstOrDefault();
    if (firstOne != null)
    {
        Debug.WriteLine("Description: " + firstOne.Description);
    }
}

This is just grabbing a description attribute, but would work the same for our custom attribute and use that info to load the appropriate page in the Test App via test control commands as done currently or some other channel (AppService?).

In either case, I think we should have the test app load the requested page on demand vs. trying to determine all the pages ahead of time and load them at the start of the app. I think this would help with the test app starting time? Which would help if you're picking specific tests to run from VS, right?

Thoughts?

@ghost ghost closed this Oct 16, 2020
@ghost ghost deleted the branch CommunityToolkit:muxtestinfra October 16, 2020 22:28
@michael-hawker
Copy link
Member

Sorry @RosarioPulella looks like my change I did forced this to close unexpectedly.

Can you rebase your branch on top of master and then try force-pushing this branch to see if we can re-open the PR after that?

@Rosuavio
Copy link
Contributor Author

@michael-hawker Just rebasing did not fix the PR. I would need to change what branch the PR is targeting, and GitHub does not seem to let me do that. Should I open a new PR? I'll make sure to reference all the requested changes.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants