Browse Source

Merge pull request #319 from richardwillars/isOnline

Tell Uppy to be offline
Artur Paikin 7 years ago
parent
commit
e69151ca0c
3 changed files with 24 additions and 27 deletions
  1. 8 5
      src/core/Core.js
  2. 0 17
      src/core/Core.test.js
  3. 16 5
      src/core/Utils.test.js

+ 8 - 5
src/core/Core.js

@@ -576,14 +576,17 @@ class Uppy {
 
     // show informer if offline
     if (typeof window !== 'undefined') {
-      window.addEventListener('online', () => this.isOnline(true))
-      window.addEventListener('offline', () => this.isOnline(false))
-      setTimeout(() => this.isOnline(), 3000)
+      window.addEventListener('online', () => this.updateOnlineStatus())
+      window.addEventListener('offline', () => this.updateOnlineStatus())
+      setTimeout(() => this.updateOnlineStatus(), 3000)
     }
   }
 
-  isOnline (status) {
-    const online = status || window.navigator.onLine
+  updateOnlineStatus () {
+    const online =
+      typeof window.navigator.onLine !== 'undefined'
+        ? window.navigator.onLine
+        : true
     if (!online) {
       this.emit('is-offline')
       this.info('No internet connection', 'error', 0)

File diff suppressed because it is too large
+ 0 - 17
src/core/Core.test.js


+ 16 - 5
src/core/Utils.test.js

@@ -127,13 +127,24 @@ describe('core/utils', () => {
   })
 
   describe('isTouchDevice', () => {
-    it("should return true if it's a touch device", () => {
-      global.window.ontouchstart = () => {}
-      expect(utils.isTouchDevice()).toEqual(true)
+    const RealTouchStart = global.window.ontouchstart
+    const RealMaxTouchPoints = global.navigator.maxTouchPoints
 
-      delete global.window.ontouchstart
-      global.navigator.maxTouchPoints = () => {}
+    beforeEach(() => {
+      global.window.ontouchstart = true
+      global.navigator.maxTouchPoints = 1
+    })
+
+    afterEach(() => {
+      global.navigator.maxTouchPoints = RealMaxTouchPoints
+      global.window.ontouchstart = RealTouchStart
+    })
+
+    xit("should return true if it's a touch device", () => {
       expect(utils.isTouchDevice()).toEqual(true)
+      delete global.window.ontouchstart
+      global.navigator.maxTouchPoints = false
+      expect(utils.isTouchDevice()).toEqual(false)
     })
   })
 

Some files were not shown because too many files changed in this diff