-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Ponyfilling window.open * Update PR number * Update packages/component/src/Composer.js Co-Authored-By: compulim <[email protected]> * Apply suggestions from code review Co-Authored-By: compulim <[email protected]> * Use production CDN * Prefer cardActionMiddleware in favor of windowOpenPonyfill * Remove test code * Update README.md * Add tests * Update description for cardActionMiddleware * Add missing actions * Remove hideCursor * Blur focus * Wait for outgoing activities
- Loading branch information
Showing
12 changed files
with
455 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+33.4 KB
...shots__/chrome-docker/card-action-middleware-js-card-action-open-url-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+30 KB
...apshots__/chrome-docker/card-action-middleware-js-card-action-signin-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { By, Key } from 'selenium-webdriver'; | ||
|
||
import { imageSnapshotOptions, timeouts } from './constants.json'; | ||
|
||
import allOutgoingActivitiesSent from './setup/conditions/allOutgoingActivitiesSent'; | ||
import botConnected from './setup/conditions/botConnected'; | ||
import suggestedActionsShowed from './setup/conditions/suggestedActionsShowed'; | ||
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown.js'; | ||
|
||
// selenium-webdriver API doc: | ||
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html | ||
|
||
test('card action "openUrl"', async () => { | ||
const { driver, pageObjects } = await setupWebDriver({ | ||
props: { | ||
cardActionMiddleware: ({ dispatch }) => next => ({ cardAction }) => { | ||
if (cardAction.type === 'openUrl') { | ||
dispatch({ | ||
type: 'WEB_CHAT/SEND_MESSAGE', | ||
payload: { | ||
text: `Navigating to ${ cardAction.value }` | ||
} | ||
}); | ||
} else { | ||
return next(cardAction); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
await driver.wait(botConnected(), timeouts.directLine); | ||
|
||
const input = await driver.findElement(By.css('input[type="text"]')); | ||
|
||
await input.sendKeys('card-actions', Key.RETURN); | ||
await driver.wait(allOutgoingActivitiesSent(), timeouts.directLine); | ||
await driver.wait(suggestedActionsShowed(), timeouts.directLine); | ||
|
||
const openUrlButton = await driver.findElement(By.css('[role="form"] ul > li:first-child button')); | ||
|
||
await openUrlButton.click(); | ||
await driver.wait(allOutgoingActivitiesSent(), timeouts.directLine); | ||
await driver.wait(minNumActivitiesShown(5), timeouts.directLine); | ||
|
||
const base64PNG = await driver.takeScreenshot(); | ||
|
||
expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions); | ||
}, 60000); | ||
|
||
test('card action "signin"', async () => { | ||
const { driver } = await setupWebDriver({ | ||
props: { | ||
cardActionMiddleware: ({ dispatch }) => next => ({ cardAction, getSignInUrl }) => { | ||
if (cardAction.type === 'signin') { | ||
getSignInUrl().then(url => { | ||
dispatch({ | ||
type: 'WEB_CHAT/SEND_MESSAGE', | ||
payload: { | ||
text: `Signing into ${ new URL(url).host }` | ||
} | ||
}); | ||
}); | ||
} else { | ||
return next(cardAction); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
await driver.wait(botConnected(), timeouts.directLine); | ||
|
||
const input = await driver.findElement(By.css('input[type="text"]')); | ||
|
||
await input.sendKeys('oauth', Key.RETURN); | ||
await driver.wait(allOutgoingActivitiesSent(), timeouts.directLine); | ||
|
||
const openUrlButton = await driver.findElement(By.css('[role="log"] ul > li button')); | ||
|
||
await openUrlButton.click(); | ||
await driver.wait(minNumActivitiesShown(5), timeouts.directLine); | ||
await driver.wait(allOutgoingActivitiesSent(), timeouts.directLine); | ||
|
||
// When the "Sign in" button is clicked, the focus move to it, need to blur it. | ||
await driver.executeScript(() => { | ||
for (let element of document.querySelectorAll(':focus')) { | ||
element.blur(); | ||
} | ||
}); | ||
|
||
const base64PNG = await driver.takeScreenshot(); | ||
|
||
expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions); | ||
}, 60000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.