Skip to content

Commit

Permalink
chore: Adjust tests for Uno
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Nov 29, 2024
1 parent d6f977d commit dc01fcc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public void Init()
}

[TestMethod]
#if !UNO_HAS_ENHANCED_LIFECYCLE && !WINAPPSDK
[Ignore("This works only for the ContentControl/ContentPresenter that are ported from WinUI, which is so far for lifecycle only")]
#endif
public async Task When_ContentTemplateSelector_Then_Content_Changes()
{
var selector = new LoggingContentTemplateSelector();
Expand All @@ -73,8 +76,16 @@ public async Task When_ContentTemplateSelector_Then_Content_Changes()
ContentTemplateSelector = selector,
};

#if HAS_UNO
// Because we support both overloads of SelectTemplate.
// We should better align with WinUI, but not very important for now.
Assert.AreEqual(2, selector.Logs.Count);
Assert.AreEqual("Dummy", selector.Logs[0]);
Assert.AreEqual("Dummy", selector.Logs[1]);
#else
Assert.AreEqual(1, selector.Logs.Count);
Assert.AreEqual("Dummy", selector.Logs[0]);
#endif

await UITestHelper.Load(SUT);

Expand All @@ -83,19 +94,41 @@ public async Task When_ContentTemplateSelector_Then_Content_Changes()
SUT.Content = "Content2";
await WindowHelper.WaitForIdle();

#if HAS_UNO
Assert.AreEqual(6, selector.Logs.Count);
Assert.AreEqual("Dummy", selector.Logs[0]);
Assert.AreEqual("Dummy", selector.Logs[1]);
Assert.AreEqual("Content1", selector.Logs[2]);
Assert.AreEqual("Content1", selector.Logs[3]);
Assert.AreEqual("Content2", selector.Logs[4]);
Assert.AreEqual("Content2", selector.Logs[5]);
#else
Assert.AreEqual(3, selector.Logs.Count);
Assert.AreEqual("Dummy", selector.Logs[0]);
Assert.AreEqual("Content1", selector.Logs[1]);
Assert.AreEqual("Content2", selector.Logs[2]);
#endif

SUT.ContentTemplateSelector = null;
SUT.ContentTemplateSelector = selector;

#if HAS_UNO
Assert.AreEqual(8, selector.Logs.Count);
Assert.AreEqual("Dummy", selector.Logs[0]);
Assert.AreEqual("Dummy", selector.Logs[1]);
Assert.AreEqual("Content1", selector.Logs[2]);
Assert.AreEqual("Content1", selector.Logs[3]);
Assert.AreEqual("Content2", selector.Logs[4]);
Assert.AreEqual("Content2", selector.Logs[5]);
Assert.AreEqual("Content2", selector.Logs[6]);
Assert.AreEqual("Content2", selector.Logs[7]);
#else
Assert.AreEqual(4, selector.Logs.Count);
Assert.AreEqual("Dummy", selector.Logs[0]);
Assert.AreEqual("Content1", selector.Logs[1]);
Assert.AreEqual("Content2", selector.Logs[2]);
Assert.AreEqual("Content2", selector.Logs[3]);
#endif
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ public async Task When_ContentTemplateSelector_Then_Content_Changes()
ContentTemplateSelector = selector,
};

#if HAS_UNO
// Because we support both overloads of SelectTemplate.
// We should better align with WinUI, but not very important for now.
Assert.AreEqual(2, selector.Logs.Count);
Assert.AreEqual("Dummy", selector.Logs[0]);
Assert.AreEqual("Dummy", selector.Logs[1]);
#else
Assert.AreEqual(1, selector.Logs.Count);
Assert.AreEqual("Dummy", selector.Logs[0]);

#endif
await UITestHelper.Load(SUT);

SUT.Content = "Content1";
Expand All @@ -60,15 +67,24 @@ public async Task When_ContentTemplateSelector_Then_Content_Changes()
// However, with the workaround, things will go wrong because changing ContentTemplateSelector will
// set SelectedContentTemplate to a local value, breaking the template-binding for SelectedContentTemplate.
// And then, ContentPresenter alone will not basically re-select the template when the Content changes.
Assert.AreEqual(1, selector.Logs.Count);
Assert.AreEqual(2, selector.Logs.Count);
Assert.AreEqual("Dummy", selector.Logs[0]);
Assert.AreEqual("Dummy", selector.Logs[1]);

SUT.ContentTemplateSelector = null;
SUT.ContentTemplateSelector = selector;

#if HAS_UNO
Assert.AreEqual(4, selector.Logs.Count);
Assert.AreEqual("Dummy", selector.Logs[0]);
Assert.AreEqual("Dummy", selector.Logs[1]);
Assert.AreEqual("Content2", selector.Logs[2]);
Assert.AreEqual("Content2", selector.Logs[3]);
#else
Assert.AreEqual(2, selector.Logs.Count);
Assert.AreEqual("Dummy", selector.Logs[0]);
Assert.AreEqual("Content2", selector.Logs[1]);
#endif
}

[TestMethod]
Expand Down

0 comments on commit dc01fcc

Please sign in to comment.