-
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.
Support replace activity with same ID (#2825)
* Replace activity with same ID * Prettier * Update entry * Update CHANGELOG.md Co-Authored-By: TJ Durnford <tjdford@gmail.com> Co-authored-by: TJ Durnford <tjdford@gmail.com> Co-authored-by: Corina <14900841+corinagum@users.noreply.github.com>
- Loading branch information
1 parent
0b0708f
commit 482ae66
Showing
7 changed files
with
97 additions
and
5 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
Binary file added
BIN
+23 KB
...r/update-activity-js-should-not-replace-activity-without-activity-id-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
+64.4 KB
...r/update-activity-js-should-not-replace-activity-without-activity-id-2-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
+18.2 KB
...ker/update-activity-js-should-replace-activity-with-same-activity-id-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
+61.5 KB
...ker/update-activity-js-should-replace-activity-with-same-activity-id-2-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,91 @@ | ||
import { imageSnapshotOptions, timeouts } from './constants.json'; | ||
|
||
import allImagesLoaded from './setup/conditions/allImagesLoaded'; | ||
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown'; | ||
import scrollToBottomCompleted from './setup/conditions/scrollToBottomCompleted'; | ||
import uiConnected from './setup/conditions/uiConnected'; | ||
|
||
jest.setTimeout(timeouts.test); | ||
|
||
test('should replace activity with same activity ID', async () => { | ||
const { driver, pageObjects } = await setupWebDriver({ | ||
createDirectLine: options => { | ||
const workingDirectLine = window.WebChat.createDirectLine(options); | ||
let firstBotActivityId; | ||
let firstBotActivityTimestamp; | ||
|
||
return { | ||
activity$: workingDirectLine.activity$.map(activity => { | ||
if (!activity.channelData && activity.type === 'message') { | ||
// Duplicate the ID using the first message activity from bot. | ||
|
||
if (firstBotActivityId) { | ||
return Object.assign({}, activity, { | ||
id: firstBotActivityId, | ||
timestamp: firstBotActivityTimestamp | ||
}); | ||
} | ||
|
||
firstBotActivityId = activity.id; | ||
firstBotActivityTimestamp = activity.timestamp; | ||
} | ||
|
||
return activity; | ||
}), | ||
connectionStatus$: workingDirectLine.connectionStatus$, | ||
postActivity: workingDirectLine.postActivity.bind(workingDirectLine), | ||
token: workingDirectLine.token | ||
}; | ||
} | ||
}); | ||
|
||
await driver.wait(uiConnected(), timeouts.directLine); | ||
await pageObjects.sendMessageViaSendBox('echo This message will be replaced by a carousel.', { waitForSend: true }); | ||
await driver.wait(minNumActivitiesShown(2), timeouts.directLine); | ||
|
||
await expect(driver.takeScreenshot()).resolves.toMatchImageSnapshot(imageSnapshotOptions); | ||
|
||
await pageObjects.sendMessageViaSendBox('carousel', { waitForSend: true }); | ||
await driver.wait(minNumActivitiesShown(3), timeouts.directLine); | ||
await driver.wait(allImagesLoaded(), timeouts.fetchImage); | ||
|
||
await expect(driver.takeScreenshot()).resolves.toMatchImageSnapshot(imageSnapshotOptions); | ||
}); | ||
|
||
test('should not replace activity without activity ID', async () => { | ||
const { driver, pageObjects } = await setupWebDriver({ | ||
createDirectLine: options => { | ||
const workingDirectLine = window.WebChat.createDirectLine(options); | ||
|
||
return { | ||
activity$: workingDirectLine.activity$.map(activity => { | ||
if (!activity.channelData && activity.type === 'message') { | ||
// Remove all activity ID from bot | ||
|
||
return Object.assign({}, activity, { id: undefined }); | ||
} | ||
|
||
return activity; | ||
}), | ||
connectionStatus$: workingDirectLine.connectionStatus$, | ||
postActivity: workingDirectLine.postActivity.bind(workingDirectLine), | ||
token: workingDirectLine.token | ||
}; | ||
} | ||
}); | ||
|
||
await driver.wait(uiConnected(), timeouts.directLine); | ||
await pageObjects.sendMessageViaSendBox('echo This message will not be replaced by a carousel.', { | ||
waitForSend: true | ||
}); | ||
await driver.wait(minNumActivitiesShown(2), timeouts.directLine); | ||
|
||
await expect(driver.takeScreenshot()).resolves.toMatchImageSnapshot(imageSnapshotOptions); | ||
|
||
await pageObjects.sendMessageViaSendBox('carousel', { waitForSend: true }); | ||
await driver.wait(minNumActivitiesShown(3), timeouts.directLine); | ||
await driver.wait(allImagesLoaded(), timeouts.fetchImage); | ||
await driver.wait(scrollToBottomCompleted(), timeouts.scrollToBottom); | ||
|
||
await expect(driver.takeScreenshot()).resolves.toMatchImageSnapshot(imageSnapshotOptions); | ||
}); |
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