浏览代码

Tests: core

Artur Paikin 9 年之前
父节点
当前提交
d89c0bf522
共有 3 个文件被更改,包括 42 次插入58 次删除
  1. 24 23
      test/core.spec.js
  2. 18 0
      test/mocks/plugin-selecter.js
  3. 0 35
      test/mocks/test-plugin.js

+ 24 - 23
test/core.spec.js

@@ -1,38 +1,39 @@
 var test = require('tape')
 var test = require('tape')
-var Uppy = require('../src/core/index.js')
+var Uppy = require('../src/core/Core.js')
 
 
-const TestPlugin = require('./mocks/test-plugin.js')
-const uppy = new Uppy({debug: true})
-uppy
-  .use(TestPlugin, {target: '.UppyDragDrop-One'})
-  .run()
-
-test('core object', function (t) {
+test('core', function (t) {
   const uppy = new Uppy()
   const uppy = new Uppy()
-  t.equal(typeof uppy, 'object', 'new Core() should return an object')
+
+  t.equal(typeof uppy, 'object', '`new Core()` should return an `object`')
+  t.equal(uppy instanceof Uppy, true, '`uppy` should be an instance of `Uppy` core')
   t.end()
   t.end()
 })
 })
 
 
-test('core type', function (t) {
+test('use plugins', function (t) {
+  const SelecterPlugin = require('./mocks/plugin-selecter.js')
   const uppy = new Uppy()
   const uppy = new Uppy()
-  t.equal(uppy.type, 'core', 'core.type should equal core')
+  uppy
+    .use(SelecterPlugin)
+
+  t.equal(Object.keys(uppy.plugins).length, 1, 'should add a plugin to the plugins stack')
   t.end()
   t.end()
 })
 })
 
 
-test('run one plugin success', function (t) {
-  const TestPlugin = require('./mocks/test-plugin.js')
-  const uppy = new Uppy({debug: true})
-  uppy
-    .use(TestPlugin)
-    .run()
+test('autoProceed', function (t) {
+  const SelecterPlugin = require('./mocks/plugin-selecter.js')
 
 
-  // @todo: TypeError: uppy.then is not a function:
-  // t.equal(uppy.then(result => result), [1, 2, 3])
+  const uppyOneSelecter = new Uppy()
+  uppyOneSelecter
+    .use(SelecterPlugin)
+    .run()
 
 
-  // @todo: But this is not acceptable either:
-  // setTimeout(function () {
-  //   t.equal(uppy, [1, 2, 3])
-  // }, 4000)
+  const uppyTwoSelecters = new Uppy()
+  uppyTwoSelecters
+    .use(SelecterPlugin)
+    .use(SelecterPlugin)
+    .run()
 
 
+  t.equal(uppyOneSelecter.opts.autoProceed, true, 'should autoProceed if only one selecter is used')
+  t.equal(uppyTwoSelecters.opts.autoProceed, false, 'should not autoProceed if more than one selecter is used')
   t.end()
   t.end()
 })
 })

+ 18 - 0
test/mocks/plugin-selecter.js

@@ -0,0 +1,18 @@
+var Plugin = require('../../src/plugins/Plugin.js')
+
+export default class TestSelector extends Plugin {
+  constructor (core, opts) {
+    super(core, opts)
+    this.type = 'selecter'
+  }
+
+  run (results) {
+    console.log({
+      class: this.constructor.name,
+      method: 'run',
+      results: results
+    })
+
+    return Promise.resolve('success')
+  }
+}

+ 0 - 35
test/mocks/test-plugin.js

@@ -1,35 +0,0 @@
-var Plugin = require('../../src/plugins/Plugin.js')
-
-export default class TestSelector extends Plugin {
-  constructor (core, opts) {
-    super(core, opts)
-    this.type = 'selecter'
-
-    // set default options
-    const defaultOptions = {}
-
-    // merge default options with the ones set by user
-    this.opts = Object.assign({}, defaultOptions, opts)
-  }
-
-  getFiles () {
-    return new Promise((resolve, reject) => {
-      const files = [1, 2, 3]
-      resolve(files)
-      // setTimeout(function () {
-      //   const files = [1, 2, 3]
-      //   resolve(files)
-      // }, 3000)
-    })
-  }
-
-  run (results) {
-    console.log({
-      class: this.constructor.name,
-      method: 'run',
-      results: results
-    })
-
-    return this.getFiles()
-  }
-}