mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-25 03:08:34 +00:00
* build: update webdriverio to v5 * build: update wdio services config syntax * e2e test updates for wdio 5 * Sync pinned versions between repo root and companion * build: enable all e2e tests for this PR run * waitForExist * test: await browser.url() calls * test: awaitify url-plugin test * test: use sauceConnect * test: upload files to sauce before using them * fall back to fakechoosefile a lot? * fall back to fakechoosefile more * Disable file selection on saucelabs * test: need to await this thing * test: make more-sure that the input is visible * test: use currently low load transloadit region so i dont have to wait * test: update but disable xhr-limit * test: change the order * test: newer firefoxes * test: change the order back * kinda sucks that they only have super old browsers on linux * ci: disable url-plugin and transloadit e2e tests again * test: use local tus-node-server for integration tests * test: use envify to check env variables and select appropriate URL * test: use companion.test:1080 for tus uploads on Travis * test: fix env vars in typescript and CRA tests * test: use getBoundingClientRect, may work better in android * test: try getSize AND getBoundingClientRect * test: do not check image width in android * test: allow retrying tests that are prone to flakiness * test: be more verbose during e2e tests * test: force <input> visibility in more tests * test: warn if using test:endtoend not on CI
105 lines
3.1 KiB
JavaScript
105 lines
3.1 KiB
JavaScript
/* global browser, capabilities, expect, $, $$ */
|
|
const path = require('path')
|
|
const fs = require('fs')
|
|
const { selectFakeFile, supportsChooseFile } = require('../utils')
|
|
|
|
const testURL = 'http://localhost:4567/thumbnails'
|
|
|
|
const images = [
|
|
path.join(__dirname, '../../resources/image.jpg'),
|
|
path.join(__dirname, '../../resources/baboon.png'),
|
|
path.join(__dirname, '../../resources/kodim23.png'),
|
|
path.join(__dirname, '../../resources/invalid.png')
|
|
]
|
|
const notImages = [
|
|
{ type: 'text/javascript', file: __filename }
|
|
]
|
|
|
|
describe('ThumbnailGenerator', () => {
|
|
beforeEach(async () => {
|
|
await browser.url(testURL)
|
|
})
|
|
|
|
it('should generate thumbnails for images', async function () {
|
|
// Does not work on IE right now
|
|
if (capabilities.browserName === 'internet explorer') {
|
|
this.skip()
|
|
return
|
|
}
|
|
|
|
const input = await $('#uppyThumbnails .uppy-FileInput-input')
|
|
await input.waitForExist()
|
|
|
|
await browser.execute(/* must be valid ES5 for IE */ function () {
|
|
window.thumbnailsReady = new Promise(function (resolve) {
|
|
window.uppyThumbnails.on('thumbnail:all-generated', resolve)
|
|
})
|
|
})
|
|
|
|
if (supportsChooseFile()) {
|
|
for (const file of images) {
|
|
await input.setValue(file)
|
|
}
|
|
for (const { file } of notImages) {
|
|
await input.setValue(file)
|
|
}
|
|
} else {
|
|
for (const img of images) {
|
|
await browser.execute(
|
|
selectFakeFile,
|
|
'uppyThumbnails',
|
|
path.basename(img), // name
|
|
`image/${path.extname(img).slice(1)}`, // type
|
|
fs.readFileSync(img, 'base64') // b64
|
|
)
|
|
}
|
|
for (const { type, file } of notImages) {
|
|
await browser.execute(
|
|
selectFakeFile,
|
|
'uppyThumbnails',
|
|
path.basename(file), // name
|
|
type, // type
|
|
fs.readFileSync(file, 'base64') // b64
|
|
)
|
|
}
|
|
}
|
|
|
|
await browser.executeAsync(/* must be valid ES5 for IE */ function (done) {
|
|
window.thumbnailsReady.then(done)
|
|
})
|
|
|
|
// const names = $$('p.file-name')
|
|
const previews = await $$('img.file-preview')
|
|
|
|
// Names should all be listed before previews--indicates that previews were generated asynchronously.
|
|
/* Nevermind this, setValue() doesn't accept multiple files so they are added one by one and the thumbnails
|
|
* have finished generating by the time we add the next.
|
|
const nys = names.map((el) => el.getLocation('y'))
|
|
const pys = previews.map((el) => el.getLocation('y'))
|
|
for (const ny of nys) {
|
|
for (const py of pys) {
|
|
expect(ny).to.be.below(py, 'names should be listed before previews')
|
|
}
|
|
}
|
|
*/
|
|
|
|
expect(previews).to.have.lengthOf(3) // ex. the invalid image
|
|
for (const p of previews) {
|
|
expect(await p.getAttribute('src')).to.match(/^blob:/)
|
|
// Doesn't appear to work in Chrome 67 on Android 6.0
|
|
if (capabilities.platformName !== 'Android') {
|
|
expect(await getWidth(p)).to.equal(200)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
async function getWidth (ref) {
|
|
try {
|
|
return await ref.getSize('width')
|
|
} catch (err) {
|
|
return browser.execute(function (el) {
|
|
return el.getBoundingClientRect().width
|
|
}, ref)
|
|
}
|
|
}
|