Переглянути джерело

Adds tests for info messages (and fixes hideInfo method)

Richard Willars 7 роки тому
батько
коміт
504a6977ac
2 змінених файлів з 84 додано та 3 видалено
  1. 1 1
      src/core/Core.js
  2. 83 2
      src/core/Core.test.js

+ 1 - 1
src/core/Core.js

@@ -743,7 +743,7 @@ class Uppy {
   }
 
   hideInfo () {
-    const newInfo = Object.assign({}, this.core.state.info, {
+    const newInfo = Object.assign({}, this.state.info, {
       isHidden: true
     })
     this.setState({

+ 83 - 2
src/core/Core.test.js

@@ -752,9 +752,90 @@ describe('src/Core', () => {
   })
 
   describe('info', () => {
-    xit('should set an info message to be displayed', () => {})
+    it('should set a string based message to be displayed infinitely', () => {
+      const infoVisibleEvent = jest.fn()
+      const core = new Core()
+      core.run()
+      core.on('core:info-visible', infoVisibleEvent)
+
+      core.info('This is the message', 'info', 0)
+      expect(core.state.info).toEqual({
+        isHidden: false,
+        type: 'info',
+        message: 'This is the message',
+        details: null
+      })
+      expect(infoVisibleEvent.mock.calls.length).toEqual(1)
+      expect(typeof core.infoTimeoutID).toEqual('undefined')
+    })
 
-    xit('should hide an info message', () => {})
+    it('should set a object based message to be displayed infinitely', () => {
+      const infoVisibleEvent = jest.fn()
+      const core = new Core()
+      core.run()
+      core.on('core:info-visible', infoVisibleEvent)
+
+      core.info({
+        message: 'This is the message',
+        details: {
+          foo: 'bar'
+        }
+      }, 'warning', 0)
+      expect(core.state.info).toEqual({
+        isHidden: false,
+        type: 'warning',
+        message: 'This is the message',
+        details: {
+          foo: 'bar'
+        }
+      })
+      expect(infoVisibleEvent.mock.calls.length).toEqual(1)
+      expect(typeof core.infoTimeoutID).toEqual('undefined')
+    })
+
+    it('should set an info message to be displayed for a period of time before hiding', (done) => {
+      const infoVisibleEvent = jest.fn()
+      const infoHiddenEvent = jest.fn()
+      const core = new Core()
+      core.run()
+      core.on('core:info-visible', infoVisibleEvent)
+      core.on('core:info-hidden', infoHiddenEvent)
+
+      core.info('This is the message', 'info', 100)
+      expect(typeof core.infoTimeoutID).toEqual('number')
+      expect(infoHiddenEvent.mock.calls.length).toEqual(0)
+      setTimeout(() => {
+        expect(infoHiddenEvent.mock.calls.length).toEqual(1)
+        expect(core.state.info).toEqual({
+          isHidden: true,
+          type: 'info',
+          message: 'This is the message',
+          details: null
+        })
+        done()
+      }, 110)
+    })
+
+    it('should hide an info message', () => {
+      const infoVisibleEvent = jest.fn()
+      const infoHiddenEvent = jest.fn()
+      const core = new Core()
+      core.run()
+      core.on('core:info-visible', infoVisibleEvent)
+      core.on('core:info-hidden', infoHiddenEvent)
+
+      core.info('This is the message', 'info', 0)
+      expect(typeof core.infoTimeoutID).toEqual('undefined')
+      expect(infoHiddenEvent.mock.calls.length).toEqual(0)
+      core.hideInfo()
+      expect(infoHiddenEvent.mock.calls.length).toEqual(1)
+      expect(core.state.info).toEqual({
+        isHidden: true,
+        type: 'info',
+        message: 'This is the message',
+        details: null
+      })
+    })
   })
 
   describe('createUpload', () => {