-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show download link and icon based on
contentUrl
(#2868)
* Replace DownloadAttachment and UploadAttachment with FileAttachment * Add entry * Add PR number * Add optionals * Fix tests * Test for FileAttachment * Also check for <a> * Test relliability * Update CHANGELOG.md Co-Authored-By: TJ Durnford <[email protected]> * Apply PR comments Co-authored-by: TJ Durnford <[email protected]>
- Loading branch information
Showing
32 changed files
with
393 additions
and
204 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
+15.5 KB
...s__/chrome-docker/file-attachment-js-show-zip-files-with-content-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
+14.9 KB
.../chrome-docker/file-attachment-js-show-zip-files-without-content-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.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { imageSnapshotOptions, timeouts } from './constants.json'; | ||
|
||
import allImagesLoaded from './setup/conditions/allImagesLoaded'; | ||
import minNumActivitiesShown from './setup/conditions/minNumActivitiesShown'; | ||
import uiConnected from './setup/conditions/uiConnected'; | ||
|
||
// selenium-webdriver API doc: | ||
// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html | ||
|
||
jest.setTimeout(timeouts.test); | ||
|
||
test('show ZIP files with contentUrl', async () => { | ||
const { driver, pageObjects } = await setupWebDriver({ | ||
createDirectLine: options => { | ||
const directLine = window.WebChat.createDirectLine(options); | ||
const patchedDirectLine = { | ||
activity$: new Observable(observer => { | ||
const subscription = directLine.activity$.subscribe({ | ||
next(activity) { | ||
observer.next( | ||
Object.assign({}, activity, { | ||
attachments: (activity.attachments || []).map(attachment => | ||
Object.assign({}, attachment, { | ||
contentUrl: 'https://example.org/' | ||
}) | ||
) | ||
}) | ||
); | ||
} | ||
}); | ||
|
||
return () => subscription.unsubscribe(); | ||
}), | ||
|
||
connectionStatus$: directLine.connectionStatus$, | ||
postActivity: directLine.postActivity.bind(directLine), | ||
token: directLine.token | ||
}; | ||
|
||
return patchedDirectLine; | ||
} | ||
}); | ||
|
||
await driver.wait(uiConnected(), timeouts.directLine); | ||
|
||
await pageObjects.sendFile('empty.zip'); | ||
await driver.wait(minNumActivitiesShown(2), timeouts.directLine); | ||
await driver.wait(allImagesLoaded(), timeouts.fetchImage); | ||
|
||
const base64PNG = await driver.takeScreenshot(); | ||
|
||
expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions); | ||
|
||
await expect( | ||
driver.executeScript(() => | ||
document.querySelector('[role="listitem"]:nth-child(1) a[target="_blank"]').getAttribute('href') | ||
) | ||
).resolves.toEqual('https://example.org/'); | ||
await expect( | ||
driver.executeScript(() => | ||
document.querySelector('[role="listitem"]:nth-child(2) a[target="_blank"]').getAttribute('href') | ||
) | ||
).resolves.toEqual('https://example.org/'); | ||
}); | ||
|
||
test('show ZIP files without contentUrl', async () => { | ||
const { driver, pageObjects } = await setupWebDriver({ | ||
createDirectLine: options => { | ||
const directLine = window.WebChat.createDirectLine(options); | ||
const patchedDirectLine = { | ||
activity$: new Observable(observer => { | ||
const subscription = directLine.activity$.subscribe({ | ||
next(activity) { | ||
observer.next( | ||
Object.assign({}, activity, { | ||
attachments: (activity.attachments || []).map(attachment => | ||
Object.assign({}, attachment, { | ||
contentUrl: undefined | ||
}) | ||
) | ||
}) | ||
); | ||
} | ||
}); | ||
|
||
return () => subscription.unsubscribe(); | ||
}), | ||
|
||
connectionStatus$: directLine.connectionStatus$, | ||
postActivity: directLine.postActivity.bind(directLine), | ||
token: directLine.token | ||
}; | ||
|
||
return patchedDirectLine; | ||
} | ||
}); | ||
|
||
await driver.wait(uiConnected(), timeouts.directLine); | ||
|
||
await pageObjects.sendFile('empty.zip'); | ||
await driver.wait(minNumActivitiesShown(2), timeouts.directLine); | ||
await driver.wait(allImagesLoaded(), timeouts.fetchImage); | ||
|
||
const base64PNG = await driver.takeScreenshot(); | ||
|
||
expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions); | ||
|
||
await expect( | ||
driver.executeScript(() => !!document.querySelector('[role="listitem"]:nth-child(1) a')) | ||
).resolves.toBeFalsy(); | ||
await expect( | ||
driver.executeScript(() => !!document.querySelector('[role="listitem"]:nth-child(2) a')) | ||
).resolves.toBeFalsy(); | ||
}); |
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
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
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 |
---|---|---|
@@ -1,5 +1,19 @@ | ||
import { By, until } from 'selenium-webdriver'; | ||
import { Condition } from 'selenium-webdriver'; | ||
|
||
export default function minNumActivitiesShown(numActivities) { | ||
return until.elementLocated(By.css(`[role="listitem"]:nth-child(${numActivities})`)); | ||
return new Condition(`${numActivities} activities is shown`, async driver => { | ||
// To run hooks (WebChatTest.runHook), the code internally create an activity. | ||
// Inside the activity renderer, it call hooks, but return empty visually. | ||
// This activity is invisible and should not count towards "minNumActivitiesShown". | ||
|
||
const numActivitiesShown = await driver.executeScript(() => | ||
[].reduce.call( | ||
document.querySelectorAll('[role="listitem"]'), | ||
(numActivitiesShown, child) => numActivitiesShown + (child.children.length ? 1 : 0), | ||
0 | ||
) | ||
); | ||
|
||
return numActivitiesShown >= numActivities; | ||
}); | ||
} |
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
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.