Skip to content
Merged
Show file tree
Hide file tree
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
29 changes: 15 additions & 14 deletions source/uwp/Renderer/lib/ActionHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,12 @@ namespace AdaptiveNamespace::ActionHelpers
{
// determine what type of action we're building
ComPtr<IAdaptiveActionElement> action(adaptiveActionElement);
ABI::AdaptiveNamespace::ActionType actionType;
RETURN_IF_FAILED(action->get_ActionType(&actionType));

// now construct an appropriate button for the action type
ComPtr<IButton> button;
try
{
CreateAppropriateButton(actionType, button);
CreateAppropriateButton(action.Get(), button);
}
CATCH_RETURN;

Expand Down Expand Up @@ -621,11 +619,8 @@ namespace AdaptiveNamespace::ActionHelpers
return;
}

ABI::AdaptiveNamespace::ActionType actionType;
action->get_ActionType(&actionType);

ComPtr<IButton> button;
CreateAppropriateButton(actionType, button);
CreateAppropriateButton(action, button);

ComPtr<IContentControl> buttonAsContentControl;
THROW_IF_FAILED(button.As(&buttonAsContentControl));
Expand Down Expand Up @@ -1028,19 +1023,25 @@ namespace AdaptiveNamespace::ActionHelpers
return actionSetAsPanel.CopyTo(actionSetControl);
}

void CreateAppropriateButton(ABI::AdaptiveNamespace::ActionType actionType, ComPtr<IButton>& button)
void CreateAppropriateButton(ABI::AdaptiveNamespace::IAdaptiveActionElement* action, ComPtr<IButton>& button)
{
// construct an appropriate button for the action type
if (actionType == ABI::AdaptiveNamespace::ActionType_OpenUrl)
if (action != nullptr)
{
// OpenUrl buttons should appear as links for accessibility purposes, so we use our custom LinkButton.
auto linkButton = winrt::make<LinkButton>();
button = linkButton.as<IButton>().detach();
ABI::AdaptiveNamespace::ActionType actionType;
THROW_IF_FAILED(action->get_ActionType(&actionType));

// construct an appropriate button for the action type
if (actionType == ABI::AdaptiveNamespace::ActionType_OpenUrl)
{
// OpenUrl buttons should appear as links for accessibility purposes, so we use our custom LinkButton.
auto linkButton = winrt::make<LinkButton>();
button = linkButton.as<IButton>().detach();
}
}

if (!button)
{
// Either non-OpenUrl action or instantiating LinkButton failed. Use standard button.
// Either no action, non-OpenUrl action, or instantiating LinkButton failed. Use standard button.
button = XamlHelpers::CreateXamlClass<IButton>(HStringReference(RuntimeClass_Windows_UI_Xaml_Controls_Button));
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/uwp/Renderer/lib/ActionHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ namespace AdaptiveNamespace::ActionHelpers
_In_ ABI::AdaptiveNamespace::IAdaptiveRenderArgs* renderArgs,
_Outptr_ ABI::Windows::UI::Xaml::IUIElement** actionSetControl);

void CreateAppropriateButton(ABI::AdaptiveNamespace::ActionType actionType,
void CreateAppropriateButton(_In_ ABI::AdaptiveNamespace::IAdaptiveActionElement* action,
Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Controls::IButton>& button);
}
55 changes: 55 additions & 0 deletions source/uwp/UWPUnitTests/RenderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;
using System.Threading.Tasks;
using UWPTestLibrary;
using AdaptiveCards.Rendering.Uwp;

namespace UWPUnitTests
{
[TestClass]
public class RenderTests
{
[TestMethod]
public async Task Media()
{
AdaptiveCard card = new AdaptiveCard
{
Version = "1.3"
};

AdaptiveMediaSource mediaSource = new AdaptiveMediaSource
{
MimeType = "audio/mp4",
Url = "https://www.stuff.com/media.mp4"
};

AdaptiveMedia media = new AdaptiveMedia();
media.Sources.Add(mediaSource);

card.Body.Add(media);

await RenderInDispatcher(card);
}

public async Task RenderInDispatcher(AdaptiveCard card)
{
RenderedAdaptiveCard renderedCard = null;

// Need to move the test to the UI Thread to render the card
var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
var renderer = new AdaptiveCardRenderer();

renderedCard = renderer.RenderAdaptiveCard(card);
});

Assert.AreEqual(0, renderedCard.Warnings.Count);
Assert.AreEqual(0, renderedCard.Errors.Count);
}
}
}
3 changes: 2 additions & 1 deletion source/uwp/UWPUnitTests/UWPUnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="RendererRegistration.cs" />
<Compile Include="RenderTests.cs" />
<Compile Include="UnitTest.cs" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -245,4 +246,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>