Browse Source

tests update, plugin mock added (work in progress)

Artur Paikin 9 years ago
parent
commit
14617f4860
4 changed files with 64 additions and 13 deletions
  1. 23 9
      test/core.spec.js
  2. 3 1
      test/index.js
  3. 35 0
      test/mocks/test-plugin.js
  4. 3 3
      test/translator.spec.js

+ 23 - 9
test/core.spec.js

@@ -1,22 +1,36 @@
 var test = require('tape')
-var Core = require('../src/core/index.js')
+var Uppy = require('../src/core/index.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) {
-  const core = new Core()
-  t.equal(typeof core, 'object', 'new Core() should return an object')
+  const uppy = new Uppy()
+  t.equal(typeof uppy, 'object', 'new Core() should return an object')
   t.end()
 })
 
 test('core type', function (t) {
-  const core = new Core()
-  t.equal(core.type, 'core', 'core.type should equal core')
+  const uppy = new Uppy()
+  t.equal(uppy.type, 'core', 'core.type should equal core')
   t.end()
 })
 
-test('translation', function (t) {
-  const russianDict = require('../src/locale/ru_RU.json')
-  const core = new Core({locale: russianDict})
+test('run one plugin success', function (t) {
+  const TestPlugin = require('./mocks/test-plugin.js')
+  const uppy = new Uppy({debug: true})
+  uppy
+    .use(TestPlugin)
+    .run()
+
+  t.equal(uppy.then(result => result), [1, 2, 3])
+
+  // setTimeout(function () {
+  //   t.equal(uppy, [1, 2, 3])
+  // }, 4000)
 
-  t.equal(core.translate('Choose a file'), 'Выберите файл', 'should return translated string')
   t.end()
 })

+ 3 - 1
test/index.js

@@ -1,4 +1,6 @@
 require('babel/register')({
   stage: 0
 })
-require('./translate.spec.js')
+
+require('./core.spec.js')
+require('./translator.spec.js')

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

@@ -0,0 +1,35 @@
+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()
+  }
+}

+ 3 - 3
test/translator.spec.js

@@ -6,7 +6,7 @@ test('russian translation', function (t) {
   const core = new Core({locale: russian})
 
   t.equal(
-    core.translator.t('chooseFile'),
+    core.translator.translate('chooseFile'),
     'Выберите файл',
     'should return translated string'
   )
@@ -19,7 +19,7 @@ test('interpolation', function (t) {
   const core = new Core({locale: english})
 
   t.equal(
-    core.translator.t('youHaveChosen', {'fileName': 'img.jpg'}),
+    core.translator.translate('youHaveChosen', {'fileName': 'img.jpg'}),
     'You have chosen: img.jpg',
     'should return interpolated string'
   )
@@ -32,7 +32,7 @@ test('pluralization', function (t) {
   const core = new Core({locale: russian})
 
   t.equal(
-    core.translator.t('filesChosen', {'smart_count': '18'}),
+    core.translator.translate('filesChosen', {'smart_count': '18'}),
     'Выбрано 18 файлов',
     'should return interpolated & pluralized string'
   )