Forráskód Böngészése

rewrite 3 tests: tus, xhr and i18n

Artur Paikin 7 éve
szülő
commit
87f6b88aca

BIN
test/endtoend/fixtures/image.jpg


+ 66 - 0
test/endtoend/specs/uppy.test.js

@@ -0,0 +1,66 @@
+/* global browser, expect, capabilities  */
+var path = require('path')
+
+var testURL = 'http://localhost:4567'
+
+function uppySelectFakeFile (uppyID) {
+  var blob = new Blob(
+    ['data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTIwIDEyMCI+CiAgPGNpcmNsZSBjeD0iNjAiIGN5PSI2MCIgcj0iNTAiLz4KPC9zdmc+Cg=='],
+    { type: 'image/svg+xml' }
+  )
+  window[uppyID].addFile({
+    source: 'test',
+    name: 'test-file',
+    type: blob.type,
+    data: blob
+  })
+}
+
+function browserSupportsChooseFile (capabilities) {
+  // Webdriver for Safari and Edge doesn’t support .chooseFile
+  return capabilities.browserName !== 'safari' &&
+         capabilities.browserName !== 'MicrosoftEdge'
+}
+
+browser.url(testURL)
+
+describe('File upload with DragDrop + Tus, DragDrop + XHRUpload, i18n translated string', () => {
+  it('should upload a file with Tus and set progressbar to 100%', () => {
+    if (browserSupportsChooseFile(capabilities)) {
+      browser.chooseFile('#uppyDragDrop .uppy-DragDrop-input', path.join(__dirname, '../fixtures/image.jpg'))
+    } else {
+      browser.execute(uppySelectFakeFile, 'uppyDragDrop')
+    }
+    browser.pause(3000)
+    var html = browser.getHTML('#uppyDragDrop-progress .UppyProgressBar-percentage', false)
+    expect(parseInt(html)).to.be.equal(100)
+  })
+
+  it('should upload a file with XHRUpload and set progressbar to 100%', () => {
+    if (browserSupportsChooseFile(capabilities)) {
+      browser.chooseFile('#uppyi18n .uppy-DragDrop-input', path.join(__dirname, '../fixtures/image.jpg'))
+    } else {
+      browser.execute(uppySelectFakeFile, 'uppyi18n')
+    }
+    browser.pause(3000)
+    var html = browser.getHTML('#uppyi18n-progress .UppyProgressBar-percentage', false)
+    expect(parseInt(html)).to.be.equal(100)
+  })
+
+  it('should translate text strings into Russian', () => {
+    var text = browser.getText('#uppyi18n .uppy-DragDrop-label')
+    expect(text.trim()).to.be.equal('Перенесите файлы сюда или выберите')
+  })
+})
+
+  // it('another test', function () {
+  //   return browser
+  //     .url(uppyTestURL)
+  //     .chooseFile('#uppyDragDrop .uppy-DragDrop-input', path.join(__dirname, 'image.jpg'))
+  //     .pause(3000)
+  //     .getHTML('#uppyDragDrop-progress .UppyProgressBar-percentage', false).then(val => {
+  //       console.log(val)
+  //       expect(parseInt(val)).toBe(100)
+  //     })
+  // })
+// })

+ 43 - 0
test/endtoend/src/index.html

@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <title>Uppy test page</title>
+  </head>
+  <body>
+    <style>
+      main {
+        max-width: 700px;
+        margin: auto;
+      }
+
+      #uppyDragDrop-progress,
+      #uppyi18n-progress {
+        position: relative;
+      }
+
+    </style>
+    <main>
+      <h2>Uppy DragDrop + Tus</h2>
+      <div>
+        <div id="uppyDragDrop"></div>
+        <div id="uppyDragDrop-progress"></div>
+      </div>
+
+      <h2>Uppy DragDrop i18n + XHRUpload</h2>
+      <div>
+        <div id="uppyi18n"></div>
+        <div id="uppyi18n-progress"></div>
+      </div>
+
+      <h2>Uppy Dashboard + Tus</h2>
+      <div>
+        <div id="uppyDashboard"></div>
+      </div>
+    </main>
+
+    <link href="uppy.min.css" rel="stylesheet">
+    <script src="bundle.js"></script>
+  </body>
+</html>

+ 48 - 0
test/endtoend/src/main.js

@@ -0,0 +1,48 @@
+const Uppy = require('../../../src/core')
+const DragDrop = require('../../../src/plugins/DragDrop')
+const Dashboard = require('../../../src/plugins/Dashboard')
+const Tus = require('../../../src/plugins/Tus')
+const XHRUpload = require('../../../src/plugins/XHRUpload')
+const ProgressBar = require('../../../src/plugins/ProgressBar')
+
+// Initialise Uppy with Drag & Drop
+const uppyDragDrop = Uppy({
+  id: 'uppyDragDrop',
+  debug: true
+})
+  .use(DragDrop, {
+    target: '#uppyDragDrop'
+  })
+  .use(ProgressBar, { target: '#uppyDragDrop-progress' })
+  .use(Tus, { endpoint: 'http://master.tus.io/files/' })
+  .run()
+
+const uppyi18n = Uppy({
+  id: 'uppyi18n',
+  debug: true
+})
+  .use(DragDrop, {
+    target: '#uppyi18n',
+    locale: {
+      strings: {
+        dropHereOr: 'Перенесите файлы сюда или',
+        browse: 'выберите'
+      }
+    }
+  })
+  .use(ProgressBar, { target: '#uppyi18n-progress' })
+  .use(XHRUpload, { endpoint: 'http://api2.transloadit.com' })
+  .run()
+
+const uppyDashboard = Uppy({
+  id: 'uppyDashboard',
+  debug: true
+})
+  .use(Dashboard, {
+    target: '#uppyDashboard',
+    inline: true
+  })
+  .use(Tus, { endpoint: 'http://master.tus.io/files/' })
+  .run()
+
+console.log(uppyDragDrop, uppyi18n, uppyDashboard)