Skip to content

Commit

Permalink
Added SuggestedAction Image Functionality (#1909)
Browse files Browse the repository at this point in the history
* Added SuggestedAction imagage functionality.

* Added SuggestedAction imagage functionality.

* Updated CHANGELOG.md

* Added conditional for image

* added image size test
  • Loading branch information
tdurnford authored and Corina committed Apr 17, 2019
1 parent 274988c commit 4172154
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `component`: Added `cardActionMiddleware` to customize the behavior of card action, by [@compulim](https://github.com/compulim), in PR [#1704](https://github.com/Microsoft/BotFramework-WebChat/pull/1704)
- `bundle`: Add `watermark` and `streamUrl` parameters to createDirectLine, by [@corinagum](https://github.com/corinagum), in PR [#1817](https://github.com/Microsoft/BotFramework-WebChat/pull/1817)
- `component`: Added `textarea` option to `SendBox` per issues [#17](https://github.com/Microsoft/BotFramework-WebChat/issues/17) and [#124](https://github.com/Microsoft/BotFramework-WebChat/issues/124), by [@tdurnford](https://github.com/tdurnford), in PR [#1889](https://github.com/Microsoft/BotFramework-WebChat/pull/1889)
- `component`: Added `suggestedAction` images per issue [#1739](https://github.com/Microsoft/BotFramework-WebChat/issues/1739), by [@tdurnford](https://github.com/tdurnford), in PR [#1909](https://github.com/Microsoft/BotFramework-WebChat/pull/1909)

### Changed

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions __tests__/suggestedActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { By } from 'selenium-webdriver';

import { imageSnapshotOptions, timeouts } from './constants.json';

import allImagesLoaded from './setup/conditions/allImagesLoaded';
import allOutgoingActivitiesSent from './setup/conditions/allOutgoingActivitiesSent';
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown';
import suggestedActionsShowed from './setup/conditions/suggestedActionsShowed';
Expand All @@ -20,6 +21,7 @@ describe('suggested-actions command', async () => {
await pageObjects.sendMessageViaSendBox('suggested-actions');

await driver.wait(suggestedActionsShowed(), timeouts.directLine);
await driver.wait( allImagesLoaded(), 2000 );

const base64PNG = await driver.takeScreenshot();

Expand Down Expand Up @@ -143,4 +145,34 @@ describe('suggested-actions command', async () => {

expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions);
});

test('should show suggested actions with images', async () => {
const { driver, pageObjects } = await setupWebDriver();

await driver.wait(uiConnected(), timeouts.directLine);
await pageObjects.sendMessageViaSendBox('emptycard');

await driver.wait(minNumActivitiesShown(1), timeouts.directLine);
await driver.wait( allImagesLoaded(), 2000 );

const base64PNG = await driver.takeScreenshot();

expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions);
});

test('should show suggested actions with larger images', async () => {

const styleOptions = { suggestedActionHeight: 80, suggestedActionImageHeight: 60 };
const { driver, pageObjects } = await setupWebDriver({ props: { styleOptions } });

await driver.wait(uiConnected(), timeouts.directLine);
await pageObjects.sendMessageViaSendBox('emptycard');

await driver.wait(minNumActivitiesShown(1), timeouts.directLine);
await driver.wait( allImagesLoaded(), 2000 );

const base64PNG = await driver.takeScreenshot();

expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions);
});
});
4 changes: 3 additions & 1 deletion packages/component/src/SendBox/SuggestedAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ export default connectSuggestedAction(
)(
({
buttonText,
disabled,
click,
disabled,
image,
styleSet
}) =>
<div className={ classNames(styleSet.suggestedAction + '', SUGGESTED_ACTION_CSS) }>
<button
disabled={ disabled }
onClick={ click }
>
{image && <img src={ image } />}
<nobr>{ buttonText }</nobr>
</button>
</div>
Expand Down
2 changes: 2 additions & 0 deletions packages/component/src/SendBox/SuggestedActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default connectSuggestedActions(
suggestedActions.map((
{
displayText,
image,
text,
title,
type,
Expand All @@ -61,6 +62,7 @@ export default connectSuggestedActions(
suggestedActionText({ displayText, title, type, value })
}
displayText={ displayText }
image={ image }
key={ index }
text={ text }
type={ type }
Expand Down
10 changes: 9 additions & 1 deletion packages/component/src/Styles/StyleSet/SuggestedAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default function createSuggestedActionStyle({
suggestedActionBackground,
suggestedActionBorder,
suggestedActionBorderRadius,
suggestedActionImageHeight,
suggestedActionTextColor,
suggestedActionDisabledBackground,
suggestedActionDisabledBorder,
Expand All @@ -18,12 +19,14 @@ export default function createSuggestedActionStyle({
paddingTop: paddingRegular,

'& > button': {
alignItems: 'center',
borderRadius: suggestedActionBorderRadius,
display: 'flex',
fontFamily: primaryFont,
fontSize: 'inherit',
height: suggestedActionHeight,
paddingLeft: paddingWide,
paddingRight: paddingWide,
borderRadius: suggestedActionBorderRadius,

'&:disabled': {
background: suggestedActionDisabledBackground,
Expand All @@ -35,6 +38,11 @@ export default function createSuggestedActionStyle({
background: suggestedActionBackground,
border: suggestedActionBorder,
color: suggestedActionTextColor
},

'& > img': {
height: suggestedActionImageHeight,
paddingRight: paddingRegular
}
}
};
Expand Down
1 change: 1 addition & 0 deletions packages/component/src/Styles/defaultStyleSetOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const DEFAULT_OPTIONS = {
suggestedActionBackground: 'White',
suggestedActionBorder: `solid 2px ${ DEFAULT_ACCENT }`,
suggestedActionBorderRadius: 0,
suggestedActionImageHeight: 20,
suggestedActionTextColor: DEFAULT_ACCENT,
suggestedActionDisabledBackground: 'White',
suggestedActionDisabledBorder: `solid 2px #E6E6E6`,
Expand Down

0 comments on commit 4172154

Please sign in to comment.