Browse Source

Rename isOnline with updateOnlineStatus and removed params

isOnline renamed to updateOnlineStatus and removes params

updateOnlineStatus default to true

Improved the window.navigator.onLine check

Adds tests for updateOnlineStatus

Removes debug

Fixes isTouchDevice test

File cleanup

Simplifies mock for window.navigator.onLine
Richard Willars 7 years ago
parent
commit
6ecaad1bc6
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

@@ -575,14 +575,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