microsoftly / BotTester

A simple bot testing framework for the bot builder framework. Easily send messages to a bot and check for expected responses and inspect session inside a dialog
MIT License
57 stars 11 forks source link

How to test Adaptive Cards #69

Open ihachani opened 6 years ago

ihachani commented 6 years ago

I am trying to test an AdaptiveCard. I am using the example from the documentation to create the card.

    var msg = new builder.Message(session);
    msg.attachmentLayout(builder.AttachmentLayout.carousel)
    msg.attachments([
        new builder.HeroCard(session)
            .title("Classic White T-Shirt")
            .subtitle("100% Soft and Luxurious Cotton")
            .text("Price is $25 and carried in sizes (S, M, L, and XL)")
            .images([builder.CardImage.create(session, 'http://petersapparel.parseapp.com/img/whiteshirt.png')])
            .buttons([
                builder.CardAction.imBack(session, "buy classic white t-shirt", "Buy")
            ]),
        new builder.HeroCard(session)
            .title("Classic Gray T-Shirt")
            .subtitle("100% Soft and Luxurious Cotton")
            .text("Price is $25 and carried in sizes (S, M, L, and XL)")
            .images([builder.CardImage.create(session, 'http://petersapparel.parseapp.com/img/grayshirt.png')])
            .buttons([
                builder.CardAction.imBack(session, "buy classic gray t-shirt", "Buy")
            ])
    ]);

The example in the BotTester documentation says to test against an adaptive card object refrenece. My problem is I can't create the Adaptive card because I don't have a session object.

ihachani commented 6 years ago

Another issue is the BotTester tests for undefined when a card is returned

The bot returns the message in the example above.

 return botTester
                .sendMessageToBot('someText', undefined)
                .runTest();

This passes when it should fail.

microsoftly commented 6 years ago

Good catch. The adaptive cards tests were a bit harder for me to work through because of how little I had interacted with them. Would you be interested in working with me on a solution?

microsoftly commented 6 years ago

&/also you should be able to mock the full adaptive card state without the session object. If I'm recalling correctly, the BotTester does a deep comparison and ignores anything that isn't expected